Skip to main content

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.

EventsInvoked when​
CHAT_VIEW_OPENEDa chat window is opened
CHAT_VIEW_CLOSEDa chat window is closed
CHAT_OPENEDa chat is initiated
CHAT_CLOSEDa chat is ended
CHAT_MISSEDa chat is missed
CHAT_ATTENDEDa chat is picked up
CHAT_REOPENEDa chat is reopened
CHAT_QUEUE_POSITION_CHANGEDthe position in the queue of a queued chat changes
PERFORM_CHATACTIONa chat action is to be executed. Learn More
CUSTOM_TRIGGERa custom trigger is executed. Learn More
CHAT_UNREAD_COUNT_CHANGEDthe unread count is changed
HANDLE_URLa URL in the chat is clicked
FEEDBACK_RECEIVED invoked when feedback is given by the visitor
RATING_RECEIVEDinvoked when a chat is rated by the visitor
BOT_TRIGGERinvoked 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;
      }
    });