Newer Version Available

This content describes an older version of this product. View Latest

Get Chat Event Notifications

Get notified when certain chat events are triggered. Subscribe to events by calling embedded_svc.addEventHandler() in your Snap-ins Chat code snippet.

Calls to embedded_svc.addEventHandler() must take place before calls to embedded_svc.init(). If your code snippet contains calls to embedded_svc.init(), make sure that you enter your calls in the correct order.

Important

The following events broadcast an object back to the client. They use the following format.
1{
2        liveAgentSessionKey: chasitorData.chatKey
3    }
eventName Scenario
onAgentJoinedConference Fired when an agent joins the chat conference.
onAgentLeftConference Fired when an agent leaves the chat conference.
onAgentMessage Fired when the agent sends a message.
onAgentRichMessage Fired when the chatbot sends a rich message. The chatbot sends a mixture of rich messages and plain messages.
onChasitorMessage Fired when the chat visitor sends a message.
onChatConferenceEnded Fired when the chat conference has ended.
onChatConferenceInitiated Fired when the chat conference is initiated.
onChatEndedByAgent Fired when the agent ends the chat.
onChatEndedByChasitor Fired when the chat visitor ends the chat.
onChatReconnectSuccessful Fired when the chat reconnects successfully.
onChatRequestSuccess Fired when the chat request is successful.
onChatTransferSuccessful Fired when a chat transfer is successful.
onConnectionError Fired when the connection to the agent is lost.
onIdleTimeoutOccurred Fired when a chat times out due to the visitor being idle. The chat ends and the visitor sees a message that the chat has ended.
onQueueUpdate Fired in the following scenarios:
  • The visitor has requested a chat and is waiting for an agent.
  • After requesting a chat, the visitor navigates to another page, but is still waiting for an agent.
  • The visitor had previously lost connection (see reconnectingState) and has regained it.
  • The visitor has advanced in the queue, but is still waiting for an agent to accept the chat request.
  • A bot or agent has requested a chat transfer and is waiting for another agent to accept.
  • During a chat transfer, the visitor navigates to another page, but is still waiting to be transferred.
  • The visitor has advanced in the queue, but is still waiting for an agent to accept the chat transfer.

This event fires only if queue position is enabled for your Snap-ins deployment and your Snap-ins code snippet is version 5.0 or later.

Note

The following events broadcast back to the client but don’t broadcast any data.

eventName Scenario
onClickSubmitButton Click handler for the "Submit" button in the offline support UI component.
onHelpButtonClick Callback to fire when the help button is clicked.
onInviteAccepted Accepts the automated chat invitation.
onInviteRejected Rejects the automated chat invitation.

Code Example

The following code is an example of how these events can be used in your Snap-ins Chat code snippet.
1embedded_svc.addEventHandler("onHelpButtonClick", function(data) {
2    console.log("onHelpButtonClick event was fired.");
3});
4
5embedded_svc.addEventHandler("onChatRequestSuccess", function(data) {
6    console.log("onChatRequestSuccess event was fired.  liveAgentSessionKey was " + data.liveAgentSessionKey);
7});
8
9embedded_svc.addEventHandler("onChatEstablished", function(data) {
10    console.log("onChatEstablished event was fired.  liveAgentSessionKey was " + data.liveAgentSessionKey);
11});
12
13embedded_svc.addEventHandler("onChasitorMessage", function(data) {
14    console.log("onChasitorMessage event was fired.  liveAgentSessionKey was " + data.liveAgentSessionKey);
15});
16
17embedded_svc.addEventHandler("onAgentMessage", function(data) {
18    console.log("onAgentMessage event was fired.  liveAgentSessionKey was " + data.liveAgentSessionKey);
19});
20
21embedded_svc.addEventHandler("onChatConferenceInitiated", function(data) {
22    console.log("onChatConferenceInitiated event was fired.  liveAgentSessionKey was " + data.liveAgentSessionKey);
23});
24
25embedded_svc.addEventHandler("onAgentJoinedConference", function(data) {
26    console.log("onAgentJoinedConference event was fired.  liveAgentSessionKey was " + data.liveAgentSessionKey);
27});
28
29embedded_svc.addEventHandler("onAgentLeftConference", function(data) {
30    console.log("onAgentLeftConference event was fired.  liveAgentSessionKey was " + data.liveAgentSessionKey);
31});
32
33embedded_svc.addEventHandler("onChatConferenceEnded", function(data) {
34    console.log("onChatConferenceEnded event was fired.  liveAgentSessionKey was " + data.liveAgentSessionKey);
35});
36
37embedded_svc.addEventHandler("onChatTransferSuccessful", function(data) {
38    console.log("onChatTransferSuccessful event was fired.  liveAgentSessionKey was " + data.liveAgentSessionKey);
39});
40
41embedded_svc.addEventHandler("onChatEndedByChasitor", function(data) {
42    console.log("onChatEndedByChasitor event was fired.  liveAgentSessionKey was " + data.liveAgentSessionKey);
43});
44
45embedded_svc.addEventHandler("onChatEndedByAgent", function(data) {
46    console.log("onChatEndedByAgent event was fired.  liveAgentSessionKey was " + data.liveAgentSessionKey);
47});
48
49embedded_svc.addEventHandler("onQueueUpdate", function(data) {
50    console.log("onQueueUpdate event was fired. liveAgentSessionKey was " + data.liveAgentSessionKey + "and queuePosition was " + data.queuePosition);
51});
52
53embedded_svc.addEventHandler("onIdleTimeoutOccurred", function(data) {
54    console.log("onIdleTimeoutOccurred event was fired.  liveAgentSessionKey was " + data.liveAgentSessionKey);
55});
56
57embedded_svc.addEventHandler("onConnectionError", function(data) {
58    console.log("onConnectionError event was fired.  liveAgentSessionKey was " + data.liveAgentSessionKey);
59});
60
61embedded_svc.addEventHandler("onClickSubmitButton", function(data) {
62    console.log("onClickSubmitButton event was fired.  liveAgentSessionKey was " + data.liveAgentSessionKey);
63});
64embedded_svc.addEventHandler("onInviteAccepted", function(data) {
65    console.log("onInviteAccepted event was fired.");
66});
67
68embedded_svc.addEventHandler("onInviteRejected", function(data) {
69    console.log("onInviteRejected event was fired.");
70});