Scripting
The Xenioo widget script supports multiple functions you can use to interact with the chat from an external script or to alter chat rendering during execution. You can find here an interactive example of the most widely used functions.
Events
Events are fired as the user or the bot execute specific operations. Your script can implement these events by simply supplying your own function inside the initialization script. In the following example, the initialization script is attaching to the onChatShow event:
Below you can find the full list of the supported events:
The following script implements all of the above events:
Functions
To use Xenioo web widget functions all you need to do is refer to the global xenioowebchat JavaScript variable that is created automatically by the Web Widget script.
isChatOpened()
Returns true if the chat area is visible, otherwise false.
openChat()
Open the chat area if closed. If the chat area is already visible, nothing happens.
closeChat()
Close the chat area if open. If the chat area is already hidden, nothing happens.
toggleChat()
This function will open the chat area if closed or close it if opened.
resetChat()
This function will reset the chat area, removing all message bubbles and clearing the current user id. Using this function will create a new conversation on Xenioo but will not reset the chat layout and personalization.
scrollCarousel( speed, id, indexmove )
This function will make the carousel specified by id move by speed. If speed is negative, the carousel will scroll to the left otherwise to the right. The active index of the carousel will be the result of the current index value plus indexmove.
say( text, command )
The say function will send a text or command to the chatbot. This is exactly as the user writes something or click on a specific button.
showBubble( text )
Display the chat widget callout bubble with the message specified in text. The bubble is displayed only if the chat area is closed.
hideBubble()
Hides the currently displayed callout bubble. If no bubble is displayed the command is ignored.
getVariable( name )
Returns the value of a conversation variable sent to the client by Web Publishing configuration. Only variables selected for forwarding are available here. If the variable is not found, null is returned.
setVariable( name, value )
Will add a variable with a given value to the next message sent to Xenioo. Differently from the Cloud Scripting SetVariable this command does not set the variable value right away: a user interaction is required in order to send the data back to the bot.
goTo( behavior, interaction, params )
This function will redirect the conversation the the specified behaviour and interaction. Additionally, one or more parameters can be specified. These parameters will be translated to variables sent to the chatbot runtime. The script below shows an example of a goTo call:
closeFloatContent()
Close the floating content area if open. If the floating content area is already hidden, nothing happens.
openFloatContent();
Open the floating content area if closed. If the floating content area is already visible, nothing happens.
toggleFloatContent();
This function will open the floating content area if closed or close it if opened.
showFloatingUrl( { Text, Command } );
This function will open the floating content area and display the Url set in Command. The floating area will have the title set in Text. The floating area can be seen only if the chat area is opened.
setVoiceLanguage( language, voice );
This function will change the current voice configuration setting by applying a new language or a new voice to the current utterance instance. The following example will change the current language to Italian:
In the following example instead, we're switching to the first available voice on the current browser:
Voice changes will take effect starting from the next sentence to be said by the text-to-speech engine.
destroy();
This function will stop the Xenioo chat widget and remove any content generated from the page.
Last updated