Open a Conversation

Updated 

Live Chat can be configured to either start a new conversation or resume an existing one. Refer to the appropriate section below for implementation details:

sprChat('openNewConversation')

This SDK can be used to start a new conversation on behalf of the user. The conversation will start with the welcome messages that were configured in the application builder. 

Parameters

Name

Required/Optional

Typescript type

Description

Default Value

initialMessages

Optional

Array<{ isSentByUser?: boolean; message: string | Partial<Message> } | string>

Override the default welcome messages by the supplied array.

None.
If an array is sent, unless specified, isSentByUser is false.

autoInitiateConversation

Optional

boolean

Need to create a case without any user message

No

conversationContext

Optional

StringTMap<string[]>

Pass some kind of context along with new conversation

No

Examples

1. Starts a conversation with welcome messages that were configured in the Live Chat application builder.

window.sprChat('openNewConversation');

2. Starts a conversation with 1 brand message and 1 user message.

window.sprChat('openNewConversation', { initialMessages: [{ message: "Hello, How can i help you?" }, { message: 'Audio issue', isSentByUser: true }]});

3. Starts a conversation with “_c_abcdef123” custom field and its value “123”. 

window.sprChat('openNewConversation', { conversationContext: {'_c_abcdef123': ['123'] }});

4. Starts a conversation with a video call.

Note: This applies only when initiating a new conversation with a video call.

sprChat('openNewConversation', {  additional: { actionType: 'VIDEO_CALL' },  silent: true,});

sprChat('openExistingConversation')

This SDK can be used when we want to open the latest active and open conversation (ie, unclosed + undeleted + having the most recent published message) of the user. 

It can also be used to open a particular conversation, if you have the ID captured (by listening to some events that declare the ongoing conversation). Use this only and only  if you want to open an old, open conversation.


Parameters

Name

Required/Optional

Typescript type

Description

Default Value

conversationId

Optional

string

Sprinklr defined conversation ID

Latest active and open conversation

Examples 

1. Automatically opens the latest active and open conversation.

window.sprChat('openExistingConversation');​

2. Open 'conv_123' conversation.

window.sprChat('openExistingConversation', 'conv_123');