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))
ParameterTypeDescription
optionsObjectOptional

These are your message payload options. All possible options are listed below.
function(callbackResponse, error)FunctionOptional

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

PropertyTypeDescription
conversationIdStringRequired

This is the conversation that you are sending a message to.
bodyStringOptional

This is the text in the message body.
payloadStringOptional

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.
attachmentsArrayOptional

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.
lastDeflectionObjectOptional

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.
isInAssistantModeBooleanOptional

If you are using a conversational assistant on this conversation, this property should be true until you receive an onAssistantEnded event.
initAssistantPayloadObjectOptional

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.
langStringOptional

The lang property can be used to say what language the message is in.

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

{
  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

{
  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

PropertyTypeDescription
messageIdStringRequired

This is the unique identifier for the sent message.
bodyStringOptional

This is the text of the sent message body.
createdAtStringRequired

The creation timestamp of the message.
directionStringRequired

Says whether the message was sent in to your Kustomer Agent instance, or sent out.
conversationIdStringRequired

The conversation that the message was sent to.
attachmentsArrayOptional

A list of attachments that were sent with the message