Chat.addListener()
The ZohoSalesIQ.Chat.addListener provides an interface for various chat event callbacks to help developers track different chat-related actions, such as opening and closing, performed by the app user. The ZohoSalesIQ.Chat.addListener invokes callback methods for various chat actions performed by visitors.
VisitorChat object returned in the callback will hold these properties. The method returns an instance of the Visitor Chat class, which contains information related to the chat.
Events | Invoked when |
CHAT_VIEW_OPENED | a chat window is opened |
CHAT_VIEW_CLOSED | a chat window is closed |
CHAT_OPENED | a chat is initiated |
CHAT_CLOSED | a chat is ended |
CHAT_MISSED | a chat is missed |
CHAT_ATTENDED | a chat is picked up |
CHAT_REOPENED | a chat is reopened |
CHAT_QUEUE_POSITION_CHANGED | the position in the queue of a queued chat changes |
PERFORM_CHATACTION | a chat action is to be executed. Learn More |
CUSTOM_TRIGGER | a custom trigger is executed. Learn More |
CHAT_UNREAD_COUNT_CHANGED | the unread count is changed |
HANDLE_URL | a URL in the chat is clicked |
FEEDBACK_RECEIVED | invoked when feedback is given by the visitor |
RATING_RECEIVED | invoked when a chat is rated by the visitor |
BOT_TRIGGER | invoked when the user opens the SDK |
Example
Copied const { Event } = ZohoSalesIQ.Chat
ZohoSalesIQ.Chat.addListener(({event, body}) => {
switch (event) {
case Event.CHAT_ATTENDED:
// body: SalesIQChat
console.log(body, 'EVENT_CHAT_ATTENDED');
break;
case Event.CHAT_UNREAD_COUNT_CHANGED:
// body: number
console.log(body, 'EVENT_CHAT_UNREAD_COUNT_CHANGED');
break;
case Event.CHAT_CLOSED:
// body: SalesIQChat
console.log(body, 'EVENT_CHAT_CLOSED');
break;
case Event.CHAT_MISSED:
// body: SalesIQChat
console.log(body, 'EVENT_CHAT_MISSED');
break;
case Event.CHAT_OPENED:
// body: SalesIQChat
console.log(body, 'EVENT_CHAT_OPENED');
break;
case Event.CHAT_QUEUE_POSITION_CHANGED:
// body: SalesIQChat
console.log(body.queuePosition, 'EVENT_CHAT_QUEUE_POSITION_CHANGED');
break;
case Event.CHAT_REOPENED:
// body: SalesIQChat
console.log(body, 'EVENT_CHAT_REOPENED');
break;
case Event.FEEDBACK_RECEIVED:
// body: SalesIQChat
console.log(body.feedback, 'EVENT_FEEDBACK_RECEIVED');
break;
case Event.HANDLE_URL:
// body: SalesIQChat
console.log(body.url, body.chat, 'EVENT_HANDLE_URL');
break;
case Event.RATING_RECEIVED:
// body: SalesIQChat
console.log(body.rating, 'EVENT_RATING_RECEIVED');
break;
case Event.BOT_TRIGGER:
// body: null
console.log('EVENT_BOT_TRIGGER');
break;
case Event.CHAT_VIEW_CLOSED:
console.log(body.id, 'EVENT_CHATVIEW_CLOSED');
break;
case Event.CHAT_VIEW_OPENED:
console.log(body.id, 'EVENT_CHATVIEW_OPENED');
break;
case Event.CUSTOM_TRIGGER:
// body: SalesIQChat
console.log(body.triggerName, 'EVENT_CUSTOMTRIGGER');
console.log(body.visitorInformation, 'EVENT_CUSTOMTRIGGER');
break;
case Event.PERFORM_CHATACTION:
console.log(
JSON.stringify(body, null, 4),
'EVENT_PERFORM_CHATACTION',
);
break;
default:
break;
}
});