List of JavaScript functions available

List of JavaScript functions available

Last update: गुरुवार, जून 30, 2022

After adding the code snippet to your website, you will be able to use JavaScript functions available in the _xeno object. That will bring you more control over your chatbox.

Ex: _xeno.identifyContact()


Properties

conversations

(Array) List of conversations and Messages

initialized

(Boolean) Whether the init function has been called or not

Message

(Class) Used to instantiate new Messages. new _xeno.Message(sample, text)

MessageSample

(Object) List of samples used to create a new message. MessageSample.support .agent .visitor .bot


Methods

getContactInfo (infoName)

Get an info from the contact.

  • infoName (String) Key of the info to get from the contact

getPublicKey ()

Get the public key used to initialize the chatbox.

  • Returns (String) The public key

goBackToPreviousView ()

Will show the previous view, as when the contact clicks on the "back" arrow.

  • Returns (Boolean) Whether the command was successful or not. If you can't go back any further, it will return false.

identifyContact ()

Triggers the initialization or re-initialization of the chatbox with the settings provided in _xenoSettings.

isLive ()

Used to know if the chatbox is in Live or in Delayed mode.

  • Returns (Boolean) True is the chatbox is in Live mode, false if the chatbox is in Delayed mode.

isOpen ()

Used to know if the chatbox is open or closed. It can be changed using _xeno.show() and _xeno.hide(). When the chatbox is going to be opened but it is not fully initialized yet (on page loading), it will return true.

  • Returns (Boolean) Whether the chatbox is open or closed.

on (event, callback)

Attach event listeners to Xeno.

  • event (String) Name of the event to listen to

  • callback (Function) Function called when the event is triggered

addMessage (message)

Adds a Message to the current conversation (the conversation your contact is watching, or the last open conversation, or an empty one). The Message object has to be initialized first with new _xeno.Message(_xeno.MessageSample.bot, "Hello World!"). This object will then be used as an argument to the sendMessage function. Note: This message is only displayed locally and is not sent to the server.

  • message (Message) A _xeno.Message object

sendMessageAsContact (text, callback)

Simulates a message sent by the Contact. This message is displayed in the chatbox and sent to the server.

  • text (String) Text that will be sent

  • callback (Function) Callback for apps not supporting promises

  • Returns (Promise) Promise resolving with a Boolean telling wether the message could be sent or not

show ()

Shows the chatbox

hide ()

Hides the chatbox

updateContact (info, options, callback)

Updates current contact info and sends it to the server. Can be used to update their current page by specifying an info.current_page. Note: The Contact ID can't be changed here: The contact is still the same, but we have more or different info about them.

  • info (Object) An object containing info about the contact. id will be ignored. Will use current_page to manually update their current page (useful for Single Page Apps).

  • options (Object) Various options to alter the function behavior.

    • triggersCheck (boolean) Automated communications are only checked upon page navigation. Since SPA do not trigger any standard page navigation after the initial page loading, automated communications will not be pushed anymore. This option will explicitly ask to perform a new check.

  • callback (Function) A function called with the response from the server.

setBotTree (botTreeUuid)

Changes the flow that will be ran when starting a new conversation. This won't affect ongoing conversations.

  • botTreeUuid (string|number) The UUID of the flow you would like to run. You can find it on your flows list, by opening the "Advanced info" modal. This parameter also accepts a flow ID (which changes everytime you edit a flow), or a flow name (which will change when renaming your flows).

startConversation (options = {})

Opens the chatbox and displays an empty conversation.

  • options.botTree (string|number) The UUID of the flow you would like to run. You can find it on your flows list, by opening the "Advanced info" modal. This parameter also accepts a flow ID (which changes everytime you edit a flow), or a flow name (which will change when renaming your flows).

  • options.contactCommitted (boolean) Whether the contact performed an action stating explicitely that they want to start a new conversation. If you are using this function when the page loads, or on any non-user event, you should leave this parameter to a falsy value. When set to true, the "Get started" button will be skipped, and the conversation will start right away.

removeAllBubbles ()

When the chatbox is closed, incoming messages (automated communications, or manual messages) will display preview bubbles above the Xeno button used to open the chatbox. All these messages previews can be cleared by using the removeAllBubbles function. Note that clearing previews won't remove the corresponding messages inside the conversation once the chatbox is open.

clearTriggers ()

Any automated communication, that is either being displayed or which is planned to be displayed a few seconds later will be removed or canceled.

Deprecated methods

identify (info)

Deprecated. Use _xenoSettings instead. This function allows to specify the identity of the visitor. The id is a unique ID that identifies the visitor. id and name are mandatory. For SPA: If the visitor has already been identified, calling this function will destroy the chatbox and load a new one. This is useful when the user signed in another account. This function is called automatically when using _xenoSettings.

  • info (Object) Information about the contact to identify. id and name are mandatory.

init (publicKey, options)

Deprecated. Use _xenoSettings instead. Starts the initialization of the chatbox. This function is called automatically when using _xenoSettings.

  • publicKey (String) You can find this key in the "deploy" page

  • options (Object) Contains various options used upon initialization


Javascript API

12 article in this category.