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 (dashboard page code)

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

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { messages } from 'wix-inbox.v2';
3import { elevate } from 'wix-auth';
4
5/* Sample conversationId value: '9ac410b1-17f8-3b10-a3f4-0dd5c295d510'
6 *
7 * Sample visibility value: 'BUSINESS_AND_PARTICIPANT'
8 */
9
10export const myListMessagesFunction = webMethod(Permissions.Anyone, async (conversationId, visibility) => {
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 */
81