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 KustomerCore.sendMessage() completes.callbackResponse is an object returned to the callback function. See the callbackResponse section below to see the properties of the object.error is either undefined or a native JavaScript Error object. |
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 payload to store the value of the quick reply button. |
attachments | Array | Optional This is a list of objects with a property called file , pointing to an image, pdf or video attachment file that you are sending with your message.See attachments below to see what this looks like. |
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 lastDeflection below to see what this looks like. |
isInAssistantMode | Boolean | Optional If you are using a conversational assistant on this conversation, this property should be true until you receive an onAssistantEnded event. |
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 KustomerCore.initAssistant .See initAssistantPayload below to see what this object looks like. |
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 in to your Kustomer Agent instance, or sent out . |
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 almost 4 years ago