Chat widget API

With the Chat widget API it is possible to control the chat widget's behavior and call the JavaScript methods listed below. For example, you can trigger scenarios, hide the chat window or set attributes into an existing conversation.

The chat widget API is active whenever an Ebbot chat widget is loaded on a page. It can be tested through the developer console.

Hooks

Use hooks to make the widget call a function.

onBeforeLoad

Callback function invoked when widget code is loaded but chat window is not rendered yet

window.Ebbot.onBeforeLoad = function(data) {
  // ...
};

onLoad

Callback function invoked when widget code is loaded and chat window is rendered

window.Ebbot.onLoad = function(data) {
  // ...
};

onReset

Callback function invoked when conversation is reset

window.Ebbot.onReset = function() {
  // ...
};

onCreate

Callback function invoked after create() API method call.

window.Ebbot.onCreate = function() {
  // ...
};

onDestroy

Callback function invoked after destroy() API method call.

window.Ebbot.onDestroy = function() {
  // ...
};

onChatWindowOpen

Callback function invoked when the chat window is opened

window.Ebbot.onChatWindowOpen = function() {
  // ...
};

onChatWindowClose

Callback function invoked when the chat window is closed

window.Ebbot.onChatWindowClose = function() {
  // ...
};

onMessage

Callback function invoked after query result

window.Ebbot.onMessage = function(data) {
  // ...
};

onBotMessage

Callback function invoked after a bot message is received

window.Ebbot.onBotMessage = function(data) {
  // ...
};

onUserMessage

Callback function invoked after user types a message

window.Ebbot.onUserMessage = function(data) {
  // ...
};

onStartConversation

Callback function invoked after query result

window.Ebbot.onStartConversation = function(data) {
  // ...
};

Methods

Use methods to call a function in the widget.

create

Create chat widget if does not exist

window.Ebbot.create();

destroy

Destroy chat widget if exist

window.Ebbot.destroy();

initChatWindow

Displays chat conversation box and initialises the chat

window.ebbot.initChatWindow();

isInitialized

Returns true if the chat is initialized

window.Ebbot.isInitialized();

resetSession

Reset current session

window.Ebbot.resetSession();

openChatWindow

Open chat window

window.Ebbot.openChatWindow();

closeChatWindow

Close chat window

window.Ebbot.closeChatWindow();

isChatWindowOpened

Check if chat window is opened

window.Ebbot.isChatWindowOpened();

isChatWindowClosed

Check if chat window is closed

window.Ebbot.isChatWindowClosed();

sendMessage

Send Message

window.Ebbot.sendMessage("Hello !");

setUserAttribute

Set User Attribute

window.Ebbot.setUserAttribute({ test: "123" });

triggerScenario

Trigger Scenario

window.Ebbot.triggerScenario({
  scenario: "scenarioId", // Found in the URL of a scenario
  state: "stateId"
});

endChat

End Chat

window.Ebbot.endChat();

transcriptChat

Transcript chat

window.Ebbot.transcriptChat();

snoozeChat

Turn on/off chat notifications

window.Ebbot.snoozeChat();

isSnoozed

Check if notifications are on/off

window.Ebbot.isSnoozed();

hide

Hide the chat

window.Ebbot.hide();

show

Show the chat

window.Ebbot.show();

isHidden

Is the chat window hidden

window.Ebbot.isHidden();

clearChat

Clears all the messages from the chat window

window.Ebbot.clearChat();

isUserActive

Returns true if the user is/was active

window.Ebbot.isUserActive();

isConversationActive

Returns true if the conversation is started

window.Ebbot.isConversationActive();

getWidgetSize

Returns an object containing the width and height of the widget (including blob, if its not on mobile). As calculations depend on the open animation, it might take 500ms for the size to update.

window.Ebbot.getWidgetSize();

Last updated