Search.../

listMessages( )

Developer Preview

Retrieves messages between the business and participant.

Description

Up to 30 messages are returned per request. If the number of messages is larger than the returned page, pagingMetadata.cursors is returned in the response, indicating that another page of results is available. To retrieve the next page, pass the next cursor value in the next request's paging.cursor parameter.

To ensure you'll always retrieve the next record, use the same visibility and sorting in the first request and all subsequent requests.

By default, 30 messages are retrieved, sorted by sequence in descending order (the most recent messages are first in the list).

Admin Method

This function requires elevated permissions to run. This function is not universal and runs only on the backend.

Syntax

function listMessages(conversationId: string, visibility: string, options: ListMessagesOptions): Promise<ListMessagesResponse>

listMessages Parameters

NAME
TYPE
DESCRIPTION
conversationId
string

ID of the conversation that contains the intended messages.

visibility
string

Required. Filters for messages with the specified visibility setting.

  • BUSINESS_AND_PARTICIPANT: Return messages visible to the business and the participant.
  • BUSINESS: Return all messages.
options
Optional
ListMessagesOptions

Additional options for listing messages.

Returns

Return Type:

Promise<
ListMessagesResponse
>
NAME
TYPE
DESCRIPTION
messages
Array<
Message
>

List of messages between the specified visitor and the site.

pagingMetadata
PagingMetadataV2

Details on the paged set of results returned.

Was this helpful?

View a list of sent messages

Copy Code
1import { messages } from 'wix-inbox.v2';
2import { elevate } from 'wix-auth';
3
4/* Sample conversationId value: '9ac410b1-17f8-3b10-a3f4-0dd5c295d510'
5 *
6 * Sample visibility value: 'BUSINESS_AND_PARTICIPANT'
7 */
8
9export async function myListMessagesFunction(conversationId, visibility) {
10
11 try {
12 const elevatedListMessages = elevate(messages.listMessages);
13 const messageList = await elevatedListMessages(conversationId, visibility);
14 const firstSender = messageList.messages[0].sender;
15
16 return messageList;
17 } catch(error) {
18 console.error(error);
19 // Handle the error
20 }
21}
22
23/* Promise resolves to:
24 * {
25 * "messages": [
26 * {
27 * "_createdDate": "2023-12-28T09:41:06.660Z",
28 * "_id": "1703756466660667",
29 * "appId": "14517e1a-3ff0-af98-408e-2bd6953c36a2",
30 * "badges": [],
31 * "content": {
32 * "previewText": "thanks for the content",
33 * "basic": {
34 * "items": [
35 * {
36 * "text": "thanks for the content"
37 * }
38 * ]
39 * },
40 * },
41 * "direction": "PARTICIPANT_TO_BUSINESS",
42 * "sender": {
43 * "anonymousVisitorId": "3c06d38d-1433-4889-b303-1ff1779176e6"
44 * },
45 * "sequence": "1703756466660667",
46 * "sourceChannel": "UNKNOWN_CHANNEL_TYPE",
47 * "targetChannels": [],
48 * "visibility": "BUSINESS_AND_PARTICIPANT",
49 * },
50 * {
51 * "_createdDate": "2023-12-27T16:16:07.816Z",
52 * "_id": "1703693767816923",
53 * "badges": [],
54 * "content": {
55 * "previewText": "Thanks for the like :)",
56 * "basic": {
57 * "items": [
58 * {
59 * "text": "Thanks for the like :)"
60 * }
61 * ]
62 * },
63 * },
64 * "direction": "BUSINESS_TO_PARTICIPANT",
65 * "sender": {
66 * "wixUserId": "b17c523c-6ec9-4b56-9d9d-123cc6978bdf"
67 * },
68 * "sequence": "1703693767816923",
69 * "sourceChannel": "UNKNOWN_CHANNEL_TYPE",
70 * "targetChannels": [
71 * "CHAT"
72 * ],
73 * "visibility": "BUSINESS_AND_PARTICIPANT",
74 * }
75 * ],
76 * "pagingMetadata": {
77 * "tooManyToCount": true
78 * }
79 * }
80 */