KustomerCore.addListener()
Adds a callback function that is run after a specific event
First, initialize chat
You must run
KustomerCore.init()
before you can execute any additional KustomerCore methods.
Examples
We're provided some examples of how you can call KustomerCore.addListener()
:
const onMessageReceivedHandler = (response, error) => {
console.log(response);
}
KustomerCore.addListener('onMessageReceived', onMessageReceivedHandler);
Remove extra listeners ๐งน
Remove any extra listeners you no longer need with
KustomerCore.removeListener()
to clear up your memory, just as you would for a nativewindow.addEventListener
listener.
Syntax
Kustomer.addListener(event, function(callbackResponse, error))
Parameter | Type | Description |
---|---|---|
event | String | Required The name of the event you want to add a listener to, for example, onConversationCreate , onMessageReceived , etc... |
function(callbackResponse, error) | Function | Required The function you want to run after the event is triggered. callbackResponse is either null or a value, depending on what event you are hooking onto. See the list of events below for the different structures.error is either undefined or a native JavaScript Error object. |
event
types
event
typesonConversationCreate
onConversationCreate
Hook for after a conversation is created.
// callbackResponse
{
conversationId: String,
createdAt: String,
ended: Boolean,
isInAssistantMode: Boolean
}
onConversationEnded
onConversationEnded
Hook for when a conversation is ended.
// callbackResponse
{
conversationId: String,
createdAt: String,
ended: Boolean
}
onConversationUnended
onConversationUnended
Hook for when a conversation is changed from ended to not ended anymore. The callbackResponse
structure is the same as for onConversationEnded
.
onAssistantEnded
onAssistantEnded
Hook for when a conversation has ended assistant mode.
// callbackResponse
{
conversationId: String,
isInAssistantMode: Boolean,
}
onSatisfactionReceived
onSatisfactionReceived
Hook for when a conversation receives a satisfaction form.
// callbackResponse
{
conversationId: String,
satisfactionId: String,
timetoken: String,
form: {
description: String,
introduction: String,
name: String,
followupQuestion: String,
ratingPrompt: String,
scale: {
options: String,
labelLow: String,
labelHigh: String,
type: String,
},
},
response: {
rating: Number,
followupAnswer: String,
},
}
onLogin
onLogin
Hook for after the user is authenticated with Kustomer.login()
.
// callbackResponse
{
identified: Boolean,
email: String | undefined,
externalId: String | undefined,
customerId: String,
}
onLogout
onLogout
Hook for after the user is logged out with Kustomer.logout()
.
onMessageReceived
onMessageReceived
Hook for when a message was successfully received
// callbackResponse
{
messageId: String,
body: String,
createdAt: String,
direction: String,
conversationId: String,
attachments: Array,
meta: {
template: Object,
articles: Array
},
sentBy: {
type: String
id: String,
displayName: String,
avatarUrl: String
},
}
onUnreadCountChange
onUnreadCountChange
Hook for when the unread count changes.
// callbackResponse
{
total: Number,
change: {
conversationId: String,
count: Number,
},
}
onAgentTypingActivity
onAgentTypingActivity
Hook for when Agent starts typing
// callbackResponse
{
conversationId: String,
user: {
avatarUrl: String,
displayName: String,
},
typing: Boolean
}
Updated over 3 years ago