Newer Version Available
Get Chat Event Notifications
Set up notifications when certain chat events are triggered. Subscribe to these
particular events by calling to embedded_svc.addEventHandler in your Embedded Chat code snippet.
The following events pass a JSON object parameter to the provided callback which contains one
attribute:
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. |
| onIdleTimeoutClear | Fired when the visitor responds after an idle timeout warning is visible, which will clear the warning. |
| 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. |
| onIdleTimeoutWarningStart | Fired when the visitor has not responded to the agent during the time set in the Customer Time-out Warning (seconds) field in Chat Buttons & Invitations Setup. |
| onInvitationResourceLoaded | Fired after the automated chat invitation static resource is loaded. |
| onQueueUpdate | Fired in the following scenarios:
|
The following general application-level events to the client are not specific to a Chat session, but can be used during Chat. These events do not broadcast any data.
| eventName | Scenario |
|---|---|
| afterMaximize | Fired when the Embedded Service Chat application is maximized by the end user clicking the minimized state. |
| afterDestroy | Fired when Embedded Service Chat has ended and the application is closed. |
| afterMinimize | Fired when the Embedded Service Chat application is minimized by the end user clicking the minimize button in the chat window header. |
| 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. |
The following general application-level events to the client are not specific to a Chat session, but can be used during Chat. These events do broadcast data.
| eventName | Scenario |
|---|---|
| onAvailability | Fires in a loop every 60 seconds and indicates if the agent
is online. The data parameter includes:
|
| onSettingsCallCompleted | Fired after the getSettings call is
completed. The call happens on page load and retrieves settings
for the chat button requested. Includes the initial agent
availability status of the button on the snippet. The data
parameter includes:
|
Code Example
The following code is an example of how these events can be used in your Embedded Service 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});
64
65embedded_svc.addEventHandler("onInviteAccepted", function() {
66 console.log("onInviteAccepted event was fired.");
67});
68
69embedded_svc.addEventHandler("onInviteRejected", function() {
70 console.log("onInviteRejected event was fired.");
71});
72
73embedded_svc.addEventHandler("onInvitationResourceLoaded", function() {
74 console.log("onInvitationResourceLoaded event was fired.");
75});
76
77embedded_svc.addEventHandler("onSettingsCallCompleted", function(data) {
78 console.log("onSettingsCallCompleted event was fired. Agent availability status is " + data.isAgentAvailable ? "online": "offline");
79});
80
81embedded_svc.addEventHandler("onAvailability", function(data) {
82 console.log("onAvailability event was fired. Agent availability status is " + data.isAgentAvailable ? "online": "offline");
83});