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:
1
<script src="https://static.xenioo.com/webchat/xenioowebchat.js"></script>
2
<script>
3
xenioowebchat.Start("<chatbotid>",{
4
onChatShow : function(){
5
console.log( "Chat area is now visible." );
6
}
7
});
8
</script>
Copied!
Below you can find the full list of the supported events:
Event
Description
Parameters
onInit
Fired as soon as chatbot initializations is started
None
onReady
Fired when initialization ends and the chatbot is ready
None
onChatClose
Happens every time the user closes the chat window
None
onChatShow
Happens every time the user or a script opens the chat window
None
onChatHide
Happens every time the user or a script closes the chat window
None
onWidgetClick
Fired as the user clicks on the chat widget on the bottom right
calloutclicked = true if the user opened the chat by clicking on the callout bubble, false otherwise.
onDataConnection
Fired whenever the chatbot is retrieving data from the Xenioo servers
None
onItemRender
Fired every time a single item is rendered in the chat window
obj = the instance of the chat part to be rendered
onElementRender
Fired after the chat element to be rendered is ready to be added to the DOM
element = DOM node instance
obj = the instance of the chat part to be rendered
onButtonClick
Fired as a button is clicked in the chat window
say = The text of the button, command = the id of the button
onUserSays
Happens as soon as the user types something in the chat
say = the text sent by the user.
onChatInteractionStarted
Fired as soon as Xenioo starts rendering the first interaction chat element
None
onChatInteractionCompleted
Fired as soon as interaction rendering is done and control is given back to the user
None
onVoiceConfigured
Fired as soon as Xenioo completes the initialization of languages and voices for text-to-speech
speechutterance = a SpeechSynthesisUtterance object that will be used to for speech-to-text
onDestroy
Fired as soon as the whole Xenioo widget is destroyed and removed from the page contents
None
onCalloutDisplay
Fired when the callout bubble of the widget is displayed
text = the text to be displayed in the callout bubble.
The following script implements all of the above events:
1
<script src="https://static.xenioo.com/webchat/xenioowebchat.js"></script>
2
<script>
3
xenioowebchat.Start("d07be17d-9be1-4f57-b220-af5559f61f8e", {
4
onInit : function( options ){
5
console.log( "Starting initialization." );
6
console.log( options );
7
},
8
onReady : function(){
9
console.log( "Xenioo chat instance is now ready." );
10
},
11
onChatClose : function(){
12
console.log( "User has closed the chat area." );
13
},
14
onChatShow : function(){
15
console.log( "Chat area is now visible." );
16
},
17
onChatHide : function(){
18
console.log( "Chat area is now hidden." );
19
},
20
onWidgetClick : function( calloutclicked ){
21
console.log( "User clicked Xenioo chat widget." );
22
},
23
onDataConnection : function(){
24
console.log( "Connecting to Xenioo servers." );
25
},
26
onItemRender : function( obj ){
27
console.log( "Rendering item in chat area (check console log for object details)" );
28
console.log( obj );
29
},
30
onElementRender: function( element, obj ){
31
console.log( "Rendering item in chat area (check console log for object details)" );
32
console.log( obj );
33
},
34
onButtonClick : function( say, command ){
35
console.log( "User clicked '" + say + "' button." );
36
},
37
onUserSays : function( say ){
38
console.log( "User input:" + say );
39
},
40
onChatInteractionStarted : function(){
41
console.log( "Interaction started." );
42
},
43
onChatInteractionCompleted : function(){
44
console.log( "Interaction finished. Control is back to the user." );
45
},
46
onVoiceConfigured: function( utterance ){
47
console.log( "Voice is initialized!" );
48
},
49
onDestroy : function(){
50
console.log( "Chat widget erased removed from page" );
51
},
52
onCalloutDisplay: function( text ){
53
console.log( "Callout bubble displayed:" + text );
54
}
55
});
56
</script>
Copied!

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.

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:
1
xenioowebchat.goTo( "My Bot Behaviour", "Bot Interaction Name",
2
{
3
mycustomvariable : "sometest",
4
myothervariable : "moretest"
5
}
6
);
Copied!

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.
1
xenioowebchat..showFloatingUrl(
2
{
3
Text:"Xenioo Home!!!", //title
4
Command: "https://www.xenioo.com" //target url
5
} );
Copied!

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:
1
xenioowebchat.setVoiceLanguage( "it-IT" );
Copied!
In the following example instead, we're switching to the first available voice on the current browser:
1
xenioowebchat.setVoiceLanguage( null, window.speechSynthesis.getVoices()[0] );
Copied!
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.
Copy link