KustomerCore.sendMessage()
Sends a customer message to your Kustomer instance.
First, initialize chat
You must initialize with
KustomerCore.init()
before you can execute any additional Core SDK methods
Examples
const messageObj = {
conversationId: 'SOME_ID',
body: 'Hi! Could you help me?',
};
// Send a message
KustomerCore.sendMessage(messageObj);
// Send message with a callback
KustomerCore.sendMessage(messageObj, function (res, error) {
console.log('Message sent!');
});
Syntax
KustomerCore.sendMessage(options, function(callbackResponse, error))
Parameter | Type | Description |
---|---|---|
options | Object | Optional These are your message payload options. All possible options are listed below. |
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 |
options
options
Property | Type | Description |
---|---|---|
conversationId | String | Required This is the conversation that you are sending a message to. |
body | String | Optional This is the text in the message body. |
payload | String | Optional If you are sending back a quick reply to an assistant question, you can use |
attachments | Array | Optional This is a list of objects with a property called See |
lastDeflection | Object | Optional For messages replying to a knowledge base deflection from the assistant, this is an object containing details about the deflection articles so they will be displayed in the Kustomer instance. See |
isInAssistantMode | Boolean | Optional If you are using a conversational assistant on this conversation, this property should be true until you receive an |
initAssistantPayload | Object | Optional If this message is the first one being sent replying to a conversational assistant, you will need to pass along part of the assistant initial messages payload that were received when you called See |
lang | String | Optional The lang property can be used to say what language the message is in. |
attachments
attachments
You can read more about JavaScript File Objects and how to create them here: https://developer.mozilla.org/en-US/docs/Web/API/File
// attachments
[
{ file: JavaScript File Object },
{ file: JavaScript File Object },
]
lastDeflection
lastDeflection
// lastDeflection
{
articles: [
{
id: String,
version: String,
visited: Number,
lang: String,
title: String,
url: String,
},
{
id: String,
version: String,
visited: Number,
lang: String,
title: String,
url: String,
},
]
}
initAssistantPayload
initAssistantPayload
// initAssistantPayload
{
assistant: 'SOME_ASSISTANT_ID`,
dialog: 'SOME_DIALOG_ID',
node: 'SOME_NODE_ID',
initialMessages: [
{
meta: {
template: Object
},
direction: String,
directionType: String,
importedAt: String,
trackingId: String,
lang: String,
}
],
}
// the initialMessages above are mapped from the response of KustomerCore.initAssistant()
callbackResponse
callbackResponse
Property | Type | Description |
---|---|---|
messageId | String | Required This is the unique identifier for the sent message. |
body | String | Optional This is the text of the sent message body. |
createdAt | String | Required The creation timestamp of the message. |
direction | String | Required Says whether the message was sent |
conversationId | String | Required The conversation that the message was sent to. |
attachments | Array | Optional A list of attachments that were sent with the message |
Updated over 1 year ago