SDK API Reference

Ada’s Web Chat consists of a global adaEmbed object that you must add to your site to use any Web SDK functionality, along with corresponding settings and actions.

Settings

Set the Web Chat’s configurable options by defining an adaSettings object on your window scope.

HTML
1<script>
2 window.adaSettings = {
3 ...
4 }
5</script>
6...
7<!-- Define the web chat script afterwards -->

Alternatively, you can pass settings to the adaEmbed.start method. (See Delay bot loading.)

The Web SDK requires that window.adaSettings be defined before the script loads. You must therefore either define window.adaSettings before the script, or make use of async on your web chat script.

The following are all of the available settings for Web chat.

adaReadyCallback

adaReadyCallback?(params: { isRolledOut: boolean }): void;

Specifies a callback function to be called when Web Chat has finished setting up. This is especially useful when Web Chat is loaded asynchronously.

HTML
1<script type="text/javascript">
2 window.adaSettings = {
3 adaReadyCallback: ({ isRolledOut }) => {
4 console.log("Ada Embed is done setting up. Chat support is now available.");
5 }
6 }
7</script>

chatterTokenCallback

chatterTokenCallback?(chatter: string): void;

Specifies a callback for when the chatter token has been set in Chat. This is called when chat is first opened by a chatter.

cluster

cluster?: string;

Specifies the Kubernetes cluster to be used. Unless directed by an Ada team member, you should not change this value.

conversationEndCallback

conversationEndCallback?(callback: (event?: { [key]: string | object }) => void): void;

Use conversationEndCallback to specify a callback function to be called when a chatter ends the conversation. The callback will receive an event object containing conversation metadata.

HTML
1<script type="text/javascript">
2window.adaSettings = {
3 conversationEndCallback: (event) => {
4 // perform action after conversation has been ended by the chatter
5 }
6};
7</script>

crossWindowPersistence

crossWindowPersistence?: boolean;

When set to true, allows the chat drawer open/close state to persist across windows and page refreshes using the Window.sessionStorage API. When the browser is closed the state is forgotten. Note that the crossWindowPersistence setting only works if an Ada Glass live chat is active (that is, while a chatter is connected to an agent).

We recommend enabling this feature if your bot uses Ada Glass.

domain

domain?: string;

Use this setting to change the subdomain. Unless directed by an Ada team member, you will not need to change this value.

greeting

greeting?: string;

Use to customize the greeting messages that new chatters see. This is useful for setting page-specific greetings across your app. The greeting should correspond to the ID of the Answer you would like to use, which you can find in the URL of the corresponding Answer in the dashboard.

Example

handle

handle:? string;

Can be used to specify the bot handle if one is not specified in the script data-handle attribute.

hideMask

hideMask?: boolean;

When set to true, prevents the default mask from appearing on top of your site’s content when opened on desktop.

We recommend setting the value of hideMask to false. This allows users to navigate the page while the Ada chat window is open.

language

language?: string;

Set the language for your bot. This setting takes in a language code to programatically set the default bot language. For example, you could change the language to French as in the following example:

HTML
1<script>
2 window.adaSettings = {
3 language: "fr",
4 }
5 </script>

You must first turn languages on in your dashboard:

Language codes must use the ISO 639-1 language format.

Alternatively, you can use the setLanguage action, which allows you to change the language without clearing the chat history.

lazy

lazy?: boolean;

When set to true true, this will prevent the bot from loading until the adaEmbed.start(...) method is called. (Alternatively, see Delay bot loading.)

metaFields

metaFields?: FlatObject;

Use metaFields to pass information about a chatter to Ada. This can be useful for tracking information about your customers, as well as personalizing their experience. For example, you may wish to track the phone_number and name for conversation attribution. (See Variables for more information)

Once set, you can access this information:

  • in the email attachment from Handoff Form submissions
  • via the Meta variables modal in the Conversations page of your Ada dashboard

To change these values after bot setup, use the setMetaFields action.

HTML
1<script type="text/javascript">
2 window.adaSettings = {
3 metaFields: {
4 phone_number: "(123) 456-7890",
5 name: "Ada Lovelace"
6 }
7 }
8</script>

Meta field keys should not include whitespace, emojis, special characters, or periods.

onAdaEmbedLoaded

Called when the embed script has been loaded, and before it is initialized. This is useful for subscribing to events. Subscribing here ensures that subscriptions are in place before events are triggered.

HTML
1<script type="text/javascript">
2window.adaSettings = {
3 onAdaEmbedLoaded: () => {
4 window.adaEmbed.subscribeEvent("ada:campaigns:shown", (data) => {
5 console.log("Message received from campaign with key:", data.campaignKey);
6 });
7 }
8};
9</script>

parentElement

parentElement?: string | HTMLElement;

Specifies where to mount the <iframe> if the default side drawer is not desired. Accepts the HTMLElement or element id of the desired parent element.

HTML
1<head>
2 <!-- ... -->
3 <script type="text/javascript">
4 window.adaSettings = {
5 parentElement: document.getElementById("custom-iframe")
6 }
7 </script>
8</head>
9<body>
10 <!-- ... -->
11 <div id="custom-iframe"></div>
12</body>

Chat will render immediately inside the parentElement provided. This means that the conversation will also get initialized. We do not recommend initializing Embed2 with the parentElement setting automatically on every page, since it could lead to low engagement rates.

privateMode

privateMode?: boolean;

Puts web chat into private mode when set to true. In private mode, web chat forgets conversation history on refresh. This is effectively the same as setting customer persistence or chatter persistence to Forget After Reload.

rolloutOverride

rolloutOverride?: number;

Use this setting to override the rollout value set in the dashboard. This can be useful if you need page-specific rollout values. Accepts any number between 0 and 1.

sensitiveMetaFields

sensitiveMetaFields?: FlatObject;

Like metaFields, you can use sensitiveMetaFields to pass information about a chatter to Ada. With sensitiveMetaFields, however, values are:

  • encrypted immediately upon entering the Ada system
  • temporarily stored in a cache on the Ada side, that is cleared after 24 hours
  • not stored in the database
  • redacted on the dashboard

If the sensitive data is sent as part of a bot response, it is not redacted the first time it appears (to allow the chatter to verify it, for example), but the data is redacted when fetching the logs of a recent conversation.

HTML
1<script type="text/javascript">
2 window.adaSettings = {
3 sensitiveMetaFields: {
4 jwt_token: "xxxxx.yyyyy.zzzzz",
5 }
6 }
7</script>

To change these values after bot setup, use the setSensitiveMetaFields action.

Meta field keys should not include whitespace, emojis, special characters, or periods.

testMode

testMode?: boolean;

Marks the chatter as a test user.

toggleCallback

toggleCallback?(isDrawerOpen: boolean): void;

Use this setting to trigger side effects when the web chat drawer is opened or closed.

zdChatterAuthCallback

zdChatterAuthCallback?(callback: (token: string) => void): void;

Use zdChatterAuthCallback for Zendesk chatter authentication. This setting allows you to request a JWT token from your API, then pass it to Ada. This creates shared trust between Ada and Zendesk, and in turn allows for verifiable chatter identity within the context of a chat session.

1window.adaSettings = {
2 zdChatterAuthCallback: (callback) => {
3 // Here you should make a request to get the fresh JWT token
4 const token = "token goes here";
5 callback(token)
6 }
7};

Ada waits up to 30 seconds for the callback to be triggered before loading chat. If the callback isn’t triggered within that time, Ada abandons the request. If you need to bypass authentication, ensure you call the callback with no arguments.

zdChatterAuthCallback is available only for Zendesk Chat. It is not available for Zendesk Messaging.

JavaScript
1window.adaSettings = {
2 handle: "<YOUR-BOT-HANDLE>",
3 cluster: "<YOUR-CLUSTER>",
4 zdChatterAuthCallback: (callback) => {
5 if (userLoggedIn) {
6 const token = "token goes here";
7 callback(token)
8 }
9
10 callback()
11 }
12};

Actions

You can call all of the following Embed2 Actions from the global adaEmbed object.

closeCampaign

closeCampaign(): Promise<void>;

Closes the currently displayed campaign (does nothing if no campaign is currently displayed).

This action requires the Ada Pro package.

deleteHistory

deleteHistory(): Promise<void>;

Deletes the chatter object used to fetch conversation logs for a user from storage. When a user opens a new chat window, a new chatter object is generated.

evaluateCampaignConditions

evaluateCampaignConditions(options: CampaignParams): Promise<void>;

This is similar to triggerCampaign, however, instead of triggering a specific Campaign, evaluateCampaignConditions evaluates the trigger conditions of the Campaigns in priority order, and triggers the first Campaign whose conditions are matched. This can be useful, for example, if Embed2 cannot determine that the route has changed, and the campaign trigger rules need to be evaluated again.

An optional argument options can be passed that matches the CampaignParams interface. These options settings may be helpful when testing your Campaign:

  • ignoreFrequency?: boolean: if ignoreFrequency is true, trigger conditions for Campaigns that have already been triggered within the configured frequency are also evaluated and may be triggered.
  • ignoreStatus?: boolean: if ignoreStatus is true, trigger conditions for inactive and draft Campaigns are also evaluated and may be triggered.

This action requires the Ada Pro package.

getInfo

getInfo(): Promise<WindowInfo>;

Returns a WindowInfo object containing information about the bot. See WindowInfo for more details.

JavaScript
1window.adaEmbed.getInfo().then(function(windowInfo){
2 console.log("is the drawer open?");
3 console.log(windowInfo.isDrawerOpen ? "Yes": "No");
4});

reset

reset(resetParams?: ResetParams): Promise<void>;

Creates a new chatter and refreshes the Chat window. reset can take an optional object allowing you to change the language, metaFields, sensitiveMetaFields, and greeting for the new chatter.

JavaScript
1window.adaEmbed.reset({
2 greeting: "5e9481e296ac6c4467092be5"
3});

setLanguage

setLanguage(language: string): void;

Changes the language in chat programatically. Use this action, rather than the language setting, to change the chat language without clearing the chat history. Language codes must use a lowercase, two-letter code, in ISO 639-1 language format. For example, en, fr, ca, ar, and so on.

1window.adaEmbed.setLanguage("en");

Before using setLanguage:

setMetaFields

setMetaFields(fields: FlatObject): Promise<void>;

Used to update metaFields after chat has been opened. In most situations, the metaFields settings object should be enough for user attribution. However, in cases where Ada chat remains open while page changes occur (like in Single Page Applications), this method may be useful.

JavaScript
1window.adaEmbed.setMetaFields({
2 phone_number: "(123) 456-7890",
3 name: "Ada Lovelace"
4});

Meta field keys should not include whitespace, emojis, special characters, or periods.

setSensitiveMetaFields

setSensitiveMetaFields(fields: FlatObject): Promise<void>;

Use this action to update sensitiveMetaFields after chat has been opened. Here, the values are not stored in the database and are deleted after 24 hours.

JavaScript
1window.adaEmbed.setSensitiveMetaFields({
2 jwt_token: "xxxxx.yyyyy.zzzzz",
3});

Meta field keys should not include whitespace, emojis, special characters, or periods.

start

start(adaSettings: StartOptions): Promise<void>;

Used to initialize Embed2 on your page. This action is triggered by default internally, so you will typically not need to call it directly unless you are using Embed2 in lazy mode, or have called stop and want to restart Embed2.

StartOptions matches anything listed in the Settings section (for example, adaReadyCallback).

JavaScript
1window.adaEmbed.start({
2 handle: "my-bot",
3 language: "fr",
4 mobileOverlay: true
5});

stop

stop(): Promise<void>;

Removes Embed2 from your page.

subscribeEvent

subscribeEvent(eventKey: string, callback: (data: object, context: object) => void): Promise<number>

Certain things in Ada trigger events. Each event consists of an event key and a data payload. Using subscribeEvent, you can define callbacks that are called when a specific event is triggered.

JavaScript
1window.adaEmbed.subscribeEvent("ada:campaigns:shown", (data) => {
2 console.log("Message received from campaign with key:", data.campaignKey);
3});

Callbacks are triggered whenever an event starts with the eventKey provided to subscribeEvent. This means you can subscribe to all events of a certain category. For example, the callback in a subscription to ada:campaigns will be called on ada:campaigns:shown, ada:campaigns:opened, and any other events beginning with ada:campaigns.

Two arguments are provided to each callback when it is called: data and context:

  • data is specific to each event.
  • context is an object with a single property, the eventKey of the event that triggered the callback.
JavaScript
1window.adaEmbed.subscribeEvent("ada:campaigns", (data, context) => {
2 const { eventKey } = context;
3
4 if (eventKey === "ada:campaigns:shown") {
5 console.log("Message received from campaign with key:", data.campaignKey);
6 }
7
8 if (eventKey === "ada:campaigns:opened") {
9 console.log("Chat opened after being shown campaign with key:", data.campaignKey);
10 }
11
12 if (eventKey === "ada:campaigns:engaged") {
13 console.log("Chatter engaged with campaign with key:", data.campaignKey);
14 }
15});

subscribeEvent returns a number subscriptionId that you can use to unsubscribe later (see unsubscribeEvent).

JavaScript
1window.adaEmbed.subscribeEvent("ada:end_conversation", (data, context) => {
2 console.log("The conversation has been ended by the user.");
3 console.log("Chatter ID: ", data.chatter_id);
4 console.log("Chat Data: ", data.event_data);
5 console.log("Chat Transcript: ", data.event_data.chatter_transcript);
6 });

It is strongly recommended that you place initial subscriptions to events in the onAdaEmbedLoaded function. This ensures that:

  • the embed script has been loaded, so it is available to accept subscriptions.
  • subscriptions happen before any events are triggered, so that no events are missed.
JavaScript
1window.adaEmbed.subscribeEvent("ada:chat_frame_timeout", (data, context) => {
2 // Perform logic needed here when chat fails to load.
3});

The following are the events that you can currently subscribe to:

Event keyDataDescription
ada:agent:joined{"conversation_id": "66a150a67abaa4b0d515909b"}
The conversation ID
Triggered whenever an agent joins the conversation.
ada:agent:left{"conversation_id": "66a150a67abaa4b0d515909b"}
The conversation ID
Triggered whenever an agent leaves the conversation.
ada:campaigns:showncampaignKey
The key of the campaign that triggered the received message.
Triggered when the chat application receives a message originating from a campaign.
ada:campaigns:openedcampaignKey
The key of the last campaign shown before chat was opened.
Triggered when chat is opened after a proactive campaign has been shown.
ada:campaigns:engagedcampaignKey
The key of the last campaign shown before the conversation was engaged.
Triggered when the chatter engages a conversation (that is, sends a message) after being shown a campaign in the same session.
ada:conversation:message{ <br /> "author": "bot" | "agent", <br /> "conversation_id": "66a150a67abaa4b0d515909b" // the Ada conversation ID <br /> "message_id": "66a150a67ab7a4b0d5259077" // the Ada message ID <br />}Triggered whenever the chatter receives a new message.
ada:end_conversationchatter_id
Contains the chat id for the chatter.
event_data
Contains neccessary chat information (chat start time, chat end time, chat messages).
chatter_transcript
Contains the transcript between the user and the bot.
Triggered when the chatter ends the chat by closing the chat window or selecting End Chat.
ada:chat_frame_timeoutnullTriggers when the chat iframe has loaded, but the chat application does not confirm it is ready within 5 seconds. Used to create a fallback when chat fails to load.

The events that begin with ada:agent are compatible with the following handoffs:

  • Zendesk Messaging
  • Zendesk Live Chat
  • Salesforce
  • Nuance
  • Aysnchronous handoffs (via Ada’s Solutions team)

toggle

toggle(): Promise<void>;

Used toggle to programatically open or close the chat window. You cannot use this method with the parentElement option.

triggerAnswer

triggerAnswer(answerId: string): void;

Triggers an answer in chat. Include the Answer ID, which you can find in the URL of the corresponding Answer in the dashboard.

Example

window.adaEmbed.triggerAnswer("627d28a9bd9ca9e5337b9763");

The chat window must be opened at least once before this method can be used.

triggerCampaign

triggerCampaign(campaignKey: string, options: CampaignParams): Promise<void>;

Use in conjunction with campaignKey to trigger proactive campaigns. It supports two optional arguments:

  • ignoreFrequency?: boolean: when set to true, allows campaign triggering even if it’s already been triggered within the frequency configured in the dashboard campaign settings.
  • ignoreStatus?: boolean: when set to true, allows campaign triggering even if it’s inactive or in a draft state.

In most cases, you should set these to false, so that the original settings configured for the campaign take precedence. There may be specific cases in which you might enable ignoreFrequency. For example, a campaign that is shared across multiple pages, that you want to show once on a single page (such as the main page of a help center), but show once per session on all subpages.

See Embed Campaign Use Cases for some examples of how to use this action.

This action requires the Ada Pro package.

trackEvent

trackEvent(eventKey: string, value?: number, meta?: FlatObject)

Use this to track an Event. The arguments of this function are:

  • eventKey: string: the key of the Event to track (required).
  • value?: number: an optional value to assign to the Event.
  • meta?: FlatObject: an optional object containing metadata corresponding to the Event. For example, it may be useful to track information such as currency, product group, customer segment, and so on.
1window.adaEmbed.trackEvent("Example_Event", 2, {
2 productId: "a1b2c3",
3 customerSegment: "premium"
4});

This action requires the Ada Pro package.

unsubscribeEvent

unsubscribeEvent(subscriptionId: number): void;

Use this function to remove subscriptions created with the subscribeEvent function. It takes a single parameter, subscriptionId, which is the id of the subscription to be removed.

1const subscriptionId = await window.adaEmbed.subscribeEvent("ada:campaigns:shown", (data) => {
2 console.log("Message received from campaign with key:", data.campaignKey);
3});
4
5window.adaEmbed.unsubscribeEvent(subscriptionId);

Type signatures

Embed2 actions commonly use the following type signatures.

CampaignParams

JavaScript
1{
2 ignoreFrequency?: boolean
3 ignoreStatus?: boolean
4}

FlatObject

JavaScript
1{
2 [key: string]\: string | number | boolean | null
3}

ResetParams

JavaScript
1{
2 greeting?: string;
3 language?: string;
4 metaFields?: FlatObject;
5 sensitiveMetaFields?: FlatObject;
6}

WindowInfo

JavaScript
1{
2 hasActiveChatter: boolean;
3 hasClosedChat: boolean;
4 isChatOpen: boolean;
5 isDrawerOpen: boolean;
6}