Web SDK API
Key Notes:
- Using the SDK API is done by a global object that is attached to the Window object.
Any use will start withwindow.AE_SDK.<api-function>
- The functions are asynchronous, and order matters. For example,
signIn
must come afterinitialize
:
await window.AE_SDK.initialize('your-own-app-key');
await window.AE_SDK.signIn('your-website-auth-jwt-token');
// Or
window.AE_SDK.initialize('your-own-app-key').then(
()=> window.AE_SDK.signIn('your-website-auth-jwt-token'));
SDK functions
- initialize:
(appKey: string, extraSettings?: ExtraSettings) => Promise<void>;
- signIn:
(token: string) => Promise<{ token: string; homeUserId: string }>;
- signOut:
() => Promise<void>;
- hide:
() => Promise<void>;
- show:
() => Promise<void>;
- triggerMessagingOverlay:
(prePopulatedMessage?: string) => Promise<void>;
- getAreExpertsAvailable:
(options?: Record<string, any>) => Promise<boolean>;
- version:
() => string;
- messagingApi:
- overrideExpertise:
(expertise: string[]) => Promise<void>;
- overrideLanguageExpertise:
(languageExpertise: string[]) => Promise<void>;
- overrideMessagingPool:
(messagingPool: string) => Promise<void>;
- sendHiddenCustomerMessage:
(message: string) => Promise<void>;
- sendCustomerMessage:
(message: string, hidden?: boolean) => Promise<void>;
- sendTeamMessage:
(message: string, options?: TimelineApiOptions)
- sendCustomTeamMessage:
(messageType: string, content: any, options?: TimelineApiOptions);
- sendDynamicComponent:
(item: string, url: string, content: any);
- overrideExpertise:
initialize
window.AE_SDK.initialize('your-own-app-key');
You must call this function before anything else.
Initialize the SDK with the desired settings.
Parameters
Name | Type | Description | Default |
---|---|---|---|
appKey (required) | string | Your unique SDK App Key | --- |
extraSettings | ExtraSettings | Extra settings that allows to extend the SDK functionality | --- |
Returns: Promise<void>
signIn
window.AE_SDK.signIn('your-website-auth-jwt-token');
Please reach the SDK team and ask to add support to your JWT token before trying to use this method.
Allows to log-in the user with a dynamic token (and skips the built-in login mechanism)
Parameters
Name | Type | Description | Default |
---|---|---|---|
token (required) | string | The token of the user | none |
Return: Promise<{ token: string; homeUserId: string }>;
token
: the converted SDK Token. (For more details about custom authentication token please talk to use).homeUserId
: the logged-in user ID.
signOut
window.AE_SDK.signOut();
Signs the user out.
Parameters: None
Return: Promise<void>
hide
window.AE_SDK.hide();
Hide anything related to the SDK on screen.
Parameters: None
Return: Promise<void>
show
window.AE_SDK.show();
Show the SDK back on screen.
Parameters: None
Return: Promise<void>
triggerMessagingOverlay
window.AE_SDK.triggerMessagingOverlay(prePopulatedMessage?: string);
allows to open the messaging overlay from any CTA in the host website. This function supports passing a text string that will pre-populate the message box, without sending it.
Pre-populated message will only work if the user is logged in.
Parameters
Name | Type | Description | Default |
---|---|---|---|
prePopulatedMessage | string | The text to populate the message box with | none |
Return: Promise<void>
getAreExpertsAvailable
window.AE_SDK.getAreExpertsAvailable(options?: Options);
Check if there are available experts to answer sessions based on the appkey messaging pool and expertise.
In the case of an overriding pool and expertise, the overridden values will be taken.
Experts are considered available if they were doing any kind of action such as typing, moving the cursor, etc.
Parameters
Name | Type | Description | Default |
---|---|---|---|
options? | * Options | Options for the query | * See default options below |
* Options
Property | type | Default |
---|---|---|
expertiseToExclude? | string[] | [] |
Return: Promise<boolean>
version
window.AE_SDK.version();
Returns the version of the SDK being used.
messagingApi
overrideExpertise
window.AE_SDK.messagingApi.overrideExpertise(expertise: string[]);
Allow overriding the expertise used to create a session.
Parameters
Name | Type | Description | Default |
---|---|---|---|
expertise | string[] | array of required expert expertise | received by initializing per app key |
Return: Promise<void>
overrideLanguageExpertise
window.AE_SDK.messagingApi.overrideLanguageExpertise(languageExpertise: string[]);
Allow overriding the language expertise used to create a session.
Parameters
Name | Type | Description | Default |
---|---|---|---|
expertise | string[] | array of required expert language expertise | received by initializing per app key |
Return: Promise<void>
overrideMessagingPool
window.AE_SDK.messagingApi.overrideMessagingPool(messagingPool: string);
Allow overriding the messaging pool of where the session will be sent to.
Parameters
Name | Type | Description | Default |
---|---|---|---|
messagingPool | string | the required messaging pool | received by initializing per app key |
Return: Promise<void>
sendHiddenCustomerMessage
window.AE_SDK.messagingApi.sendHiddenCustomerMessage(message: string);
This function is going to be deprecated in the future.
Use instead sendCustomerMessage(message: string, hidden: boolean) with hidden = true.
Send message as a customer that only experts can see to initiate a session. If the user already has an ongoing session, then this method won't send the message.
This API function will be enabled/disabled by the SDK team per app key.
Parameters
Name | Type | Description | Default |
---|---|---|---|
message | string | Content of the message | none |
Return: Promise<void>
sendCustomerMessage
window.AE_SDK.messagingApi.sendCustomerMessage(message: string, hidden?: boolean);
Send message as a customer to initiate a session. If the user already has an ongoing session, then this method won't send the message.
This API function will be enabled/disabled by
the SDK team per app key.
Parameters
Name | Type | Description | Default |
---|---|---|---|
message | string | Content of the message | none |
hidden? | boolean | can the customer see the message on his timeline | false |
Return: Promise<void>
sendTeamMessage
window.AE_SDK.messagingApi.sendTeamMessage(message: string, options?: TimelineApiOptions);
Send a message as the team.
Parameters
Name | Type | Description | Default |
---|---|---|---|
message | string | Content of the message | none |
options? | TimelineApiOptions | Options for sending | * See default options below |
Return: Promise<void>
sendCustomTeamMessage
window.AE_SDK.messagingApi.sendCustomTeamMessage(messageType: string, content: any, options?: TimelineApiOptions);
Send a custom message as the team.
Parameters
Name | Type | Description | Default |
---|---|---|---|
messageType | string | The type message | none |
content | any | Content of the message | none |
options? | TimelineApiOptions | Options for sending | * See default options below |
Return: Promise<void>
sendDynamicComponent
window.AE_SDK.messagingApi.sendDynamicComponent(item: string, url: string, content: any);
Send a component message as the team.
Parameters
Name | Type | Description | Default |
---|---|---|---|
item | string | The type message | none |
url | string | The url of the dynamic component | none |
content | any | Content of the message | none |
Return: Promise<void>
Associated Types
ExtraSettings
An optional object that can override some of the SDK's default behaviors.
- registerToEvents
- plugins
containerElementId: string;
- allow rendering the timeline experience to a different dom element container.hiddenInitialization: boolean;
- initializing the SDK as hidden (default false);
TimelineApiOptions
An optional parameter for sending components
Name | Type | Description | Default |
---|---|---|---|
senderName? | string | the name of the sender | none |
fakeTyping? | bool | should the SDK fake a typing indicator to look like the expert is typing before sending the message | false |
registerToEvents
registerToEvents
is a function that receives event emitter for registering to SDK events, available events are:
- MESSAGE_RECEIVED
- MESSAGE_SENT
- SEND_MESSAGE_FAILED
- SESSION_CHANGED
- LOGGED_IN
- LOGGED_OUT
- LOGIN_FAILED
- TOKEN_IS_ABOUT_TO_EXPIRE
- PROACTIVE_EXPERIENCE_VIEWED
- TIMELINE_ITEM_SKIPPED
For further information of events and their arguments, click here.
Example:
const registerToEvents = (eventEmitter: any) => {
eventEmitter.on('NEW_MESSAGE', (args: any) => {
console.log('registerEventEmitter NewMessage', args);
});
eventEmitter.on('ACTION', (args: any) => {
console.log('registerEventEmitter Action', args);
});
};
// Initialize the SDK
AE_SDK.initialize('APPKEY', { registerToEvents });
plugins
Plugins are the way to enhance and add new behavior to the SDK or alter existing one, with 3 properties:
- timelineItems (optional) - Allows you to override & enhance rendering of timeline items.
- login (optional) - overrides the default login page.
Example:
const plugins = {
timelineItems: [customTimelinePlugin1,customTimelinePlugin2,...],
login: CustomLoginPage
}
// Initialize the SDK
AE_SDK.initialize('APP_KEY', {plugins});
For further information of plugins, click here.