Search.../

getConversation( )

Developer Preview

Retrieves a conversation by conversation ID.

Description

If you don't have the conversation ID, use getOrCreateConversation() to retrieve the conversation with the visitor, contact, or member ID.

Admin Method

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

Syntax

function getConversation(conversationId: string): Promise<GetConversationResponse>

getConversation Parameters

NAME
TYPE
DESCRIPTION
conversationId
string

Conversation ID.

Returns

Return Type:

Promise<
GetConversationResponse
>
NAME
TYPE
DESCRIPTION
conversation
Conversation

Retrieved conversation.

Was this helpful?

Get a conversation (dashboard page code)

Copy Code
1import { conversations } from 'wix-inbox.v2';
2
3/* Sample conversationID value: '092d1135-99cf-3ca9-a0bf-378e1df4539b' */
4
5export async function myGetConversationFunction(conversationId) {
6
7 try {
8 const conversationObject = await conversations.getConversation(conversationId);
9 const channels = conversationObject.conversation.channels;
10 const firstChannel = conversationObject.conversation.channels[0];
11 const businessName = conversationObject.conversation.businessDisplayData.name;
12
13 return conversationObject;
14 } catch (error) {
15 console.error(error);
16 //Handle the error
17 }
18}
19
20/* Promise resolves to:
21 * {
22 * "conversation": {
23 * "_id": "6fd2b962-dd8f-382f-8d27-ae63f188c939",
24 * "businessDisplayData": {
25 * "name": "Tim's Cookies"
26 * },
27 * "channels": [
28 * "CHAT",
29 * "EMAIL"
30 * ],
31 * "participant": {
32 * "contactId": "9e668c08-8bdb-4240-babb-8176935f6f78"
33 * },
34 * "participantDisplayData": {
35 * "name": "jsmith@example.com"
36 * }
37 * }
38 * }
39 */
Get a conversation (export from backend code)

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { conversations } from 'wix-inbox.v2';
3import { elevate } from 'wix-auth';
4
5/* Sample conversationID value: '092d1135-99cf-3ca9-a0bf-378e1df4539b' */
6
7export const myGetConversationFunction = webMethod(Permissions.Anyone, async (conversationId) => {
8
9 try {
10 const elevatedGetConversation = elevate(conversations.getConversation);
11 const conversationObject = await elevatedGetConversation(conversationId);
12 const channels = conversationObject.conversation.channels;
13 const firstChannel = conversationObject.conversation.channels[0];
14 const businessName = conversationObject.conversation.businessDisplayData.name;
15
16 return conversationObject;
17 } catch (error) {
18 console.error(error);
19 //Handle the error
20 }
21});
22
23/* Promise resolves to:
24 * {
25 * "conversation": {
26 * "_id": "6fd2b962-dd8f-382f-8d27-ae63f188c939",
27 * "businessDisplayData": {
28 * "name": "Tim's Cookies"
29 * },
30 * "channels": [
31 * "CHAT",
32 * "EMAIL"
33 * ],
34 * "participant": {
35 * "contactId": "9e668c08-8bdb-4240-babb-8176935f6f78"
36 * },
37 * "participantDisplayData": {
38 * "name": "jsmith@example.com"
39 * }
40 * }
41 * }
42 */
43