Kustomer.createConversation()
Start a new conversation for a customer.
Use Kustomer.createConversation()
to open the chat widget and take the customer to a new conversation. You can optionally start the conversation with an initial message.
This method is useful when you need to hand off a response from a web form to the chat widget.
First, initialize chat fully
Kustomer Chat must finish initializing fully with
Kustomer.start()
before you can execute any additional Web SDK methods.Tip: Call other methods inside the callback of
Kustomer.start()
to ensure Kustomer Chat always completes initialization before the code tries to run other methods.To learn more, see Troubleshooting: Kustomer method calls won't execute.
When using a Conversational Assistant
The
message
value will be used in response to the first question in your Conversational Assistant. If you have set the first question as a Button Question or Data Attribute Question for an attribute that is a Tree type, users will be required to select an option before the Conversational Assistant continues.
Examples
We're provided some examples of how you can call Kustomer.createConversation()
:
Pass a
message
parameter to create a conversationYou must pass in a value for the
message
parameter inoptions
withKustomer.createConversation()
to create a conversation in Kustomer.
// Create a conversation. This takes the user to the conversation thread but does not create the conversation in Kustomer.
Kustomer.createConversation()
// Create a conversation with a callback to run after a conversation has successfully been created in Kustomer.
Kustomer.createConversation({
assistantId: "SOME_ASSISTANT_ID",
message: "I need some help"
},
function (response, error) => {
if (error) {
console.log("handle the error")
} else {
console.log("handle the response")
}
}
Syntax
Kustomer.createConversation(options, function(response, error))
Parameter | Type | Description |
---|---|---|
options | Object | Required An object containing an initial message or assistantId. |
function(callbackResponse, error) | Function | Optional A callback that is run after callbackResponse is an object returned to the callback function. See the error is either undefined or a native JavaScript Error object. |
options
options
Property | Type | Description |
---|---|---|
message | String | Optional This message will be passed into the conversation when it starts. It will either be the initial message or in response to a conversational assistant. |
assistantId | String | Optional By passing in an |
callbackResponse
callbackResponse
Property | Type | Description |
---|---|---|
conversationId | string | Unique id of the newly created conversation |
createdAt | string | timestamp representing the date and time the conversation was created |
ended | boolean | Determines whether or not the conversation has been ended |
isInAssistantMode | boolean | Indicates if the conversation is currently in assistant mode and the customer is interacting with a conversational assistant. |
Updated about 1 year ago