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

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