Events
The SDK provides an event mechanism to keep the host app updated on events related to the chat session, like customer actions, expert actions, or technical events like login events.
Registration
There are two ways for register to an event:
- Through initialize (in case the app isn't using auto-initialization):
const registerToEvents = (eventEmitter: any) => {
eventEmitter.on('SESSION_CHANGED', (args: any) => {
console.log('session state was changed', args);
});
};
AE_SDK.initialize({ registerToEvents });
- Using the events API:
window.AE_SDK((thrownError, AE_SDK) => {
AE_SDK.events.addListener('LOGGED_IN', args => {
// your code here
});
});
Both eventEmitter
and AE_SDK.events
are instances of Node EventEmitter class.
Registering to events with the second example (using AE_SDK.events) is available even before the SDK was initialized.
Available events
The available events are:
- MESSAGE_RECEIVED
- MESSAGE_SENT
- SEND_MESSAGE_FAILED
- SESSION_CHANGED
- LOGGED_IN
- LOGIN_FAILED
- LOGGED_OUT
TOKEN_IS_ABOUT_TO_EXPIRE- TIMELINE_ITEM_SKIPPED
- IMAGE_PREVIEW
- PROACTIVE_EXPERIENCE_VIEWED
- FABIO_CLICKED
- CHAT_TOGGLE_ANIMATION_ENDED
- DRAWER_EVENT
- EXPERTS_AVAILABILITY_CHANGED
Events Args:
MESSAGE_RECEIVED
Called when the customer receives a message.
Property | type | Description |
---|---|---|
type | string (text, image, video, other) | The type of the message that was received: text/image/video/other |
message | string | The message |
from | string | The name of the expert/bot/team who sent the message |
MESSAGE_SENT
Called when the customer sends a message.
Property | type | Description |
---|---|---|
type | string (text, image, video, other) | The type of the message that was sent: text/image/video/other |
message | string | The message |
metadata? | MetaData | More optional information about the message as described below |
sessionId? | string | The unique Id of the chat session |
SEND_MESSAGE_FAILED
Called when the message sent by the customer failed to be delivered.
Property | type | Description |
---|---|---|
type | string (text, image, video, other) | The type of the message that was sent: text/image/video/other |
message | string | The message |
metadata? | MetaData | More optional information about the message as described below |
sessionId? | string | The unique Id of the chat session |
error? | any | The error that caused the failure |
MetaData
Details about the session, such as expertise and pool.
Property | type | Description |
---|---|---|
senderType | 'Device' or 'Team' | Device is the customer, Team is the expert |
messagingPool | string | The pool/queue of the session (e.g. Asurion) |
expertise | string | The expertise/skill this session is assigned to (e.g. general_conversation) |
SESSION_CHANGED
Called when the session status is changed:
- Session created by the customer
- Session was assigned to an expert
- Session was resolved/canceled/escalated by the expert
Property | type | Description |
---|---|---|
action | string (created, assigned, resolved, canceled, escalated) | created, assigned, resolved, canceled, escalated |
sessionId? | string | The unique Id of the chat session |
expertId? | string | The expert who acted (if exists) |
LOGGED_IN
Called when the customer logs in.
Property | type | Description |
---|---|---|
token | string | The authentication token |
homeUserId | string | The AE user ID of the customer |
LOGGED_OUT
Called when the customer logs out. No payload.
LOGIN_FAILED
Called when the customer failed to log in.
Property | type | Description |
---|---|---|
error | any | The error description |
TOKEN_IS_ABOUT_TO_EXPIRE
Called 2 min before the session token is expired. No payload.
This event will soon be deprecated and will not trigger anymore.
Authentication tokens should be automatically renewed before they are expired
FABIO_CLICKED
Called when the customer clicks on the FAB to expand or collapse it.
Property | type | Description |
---|---|---|
isExpanded | boolean | True on expended / false on collapsed |