Base Conversation object methods
The following methods are exposed by the conversation object, injected in every Cloud Script Action execution. You can use the conversation object in any point of the Cloud Script Action Execution.

Chatbot Variables and Tags

GetVariable

This method will return the current value of a specified variable. If the variable does not exist, an empty string is returned.
1
conversation.GetVariable( variablename );
Copied!

SetVariable

This method will update the value of a variable with a given name. Multiple overloads are available for additional call details.
1
conversation.SetVariable( variablename, variablevalue );
2
conversation.SetVariable( variablename, variablevalue, setmode );
3
conversation.SetVariable( variablename, variablevalue, replacewith, setmode );
Copied!
The setmode parameter defines the mode used to update the target variable. You can use the following table as a reference for the parameter.
value
mode
0
Default. The value will be overwritten
1
Append. The value will be added to the end of the current value
2
Concatenate. The value will be added to the end of the current value, separated by a comma
3
Add. Xenioo will attempt to sum the given value to the current value of the variable
4
Subtract. Xenioo will attempt to subtract the given value from the current value of the variable
5
Divide. Xenioo will attempt to divide current value of the variable by the given value
6
Multiply. Xenioo will attempt to multiply current value of the variable by the given value
7
ReplaceString. All occurences of the given value inside the current value will be replaced by replacewith value
8
RemoveString. The given value will be removed from the current variable value
9
ClearValue. The current value of the variable will be set to an empty string value

SetTag

This method will create a new tag and attach it to the current conversation.
1
conversation.SetTag( tagname );
Copied!

DropTag

This method will drop a specific tag from the current conversation. No error is returned if the tag does not exist.
1
conversation.DropTag( tagname );
Copied!

HasTag

This method will check the existence of specific tag and return true if found otherwise false.
1
conversation.HasTag( tagname );
Copied!

Global Variables

Global variables differ from standard chatbot variables as they are global to all conversations. Updates to any global variable is immediately reflected to every conversation. Additionally, global variables have an expiration time: if you try to access an expired variable value after the expiration period an empty string will be returned.

GetGlobalVariable

This method will return the current value of the specified global variable. If the variable does not exist, an empty string is returned.
1
conversation.GetGlobalVariable( variablename );
Copied!

SetGlobalVariable

This method will create or update the value of a global variable with a given name. An additional overload of the function can be used to set the automatic expiration of the value in minutes: accessing the variable value after the expiration date will return an empty string.
1
conversation.SetGlobalVariable( variablename, variablevalue );
2
conversation.SetGlobalVariable( variablename, variablevalue, expireminutes );
Copied!

Conversation Flow and Data

GoTo

This method will redirect the conversation to the behaviour specified in targetbehaviour and the interaction specified in targetinteraction. If targetinteraction is empty or null, the conversation will be redirected to the start interaction of targetbehaviour. Conversation will be redirected as soon as the script action completes. No additional operations or actions will be executed, even if child of the current scripting action.
1
conversation.GoTo( targetbehaviour, targetinteraction );
Copied!

GetShareURL

This method will generate a new share URL for the current conversation. The expiretime parameter indicates after how many hours the generated URL will expire. Setting takeover as true will generate a take over URL while setting it as false will generate a view only URL. Setting autohandover to true, will automatically hand over the conversation to Xenioo as soon as the take over URL expires.
1
conversation.GetShareURL( expiretime, takover, autohandover );
Copied!

DropAllShares

This method will delete and invalidate any shared URL currently active for the current conversation.
1
conversation.DropAllShares( );
Copied!

Log

This method will log a user text to the current chat execution diagram. The log will be displayed as system, following the standard script action logging.
1
conversation.Log( text );
Copied!

LogIssue

This method will log an issue text to the current chat execution diagram. The log will be displayed as system, following the standard script action logging. An issue text is displayed with an alert and a red color accent.
1
conversation.Log( text );
Copied!

AddReplyPart

This method will add a new reply part to the current conversation block. You can use this method to add new text or advanced controls to the current conversation. The added parts are volatile and will not become part of the runtime chatbot build design. This method has multiple overloads that can be used to further define you action.
1
conversation.AddReplyPart( text );
2
conversation.AddReplyPart( type, text, command );
3
conversation.AddReplyPart( type, text, command, commandvariable );
4
conversation.AddReplyPart( type, text, command, commandvariable, targetbehaviour, targetinteraction );
Copied!
The type parameter defines the type of chat content that the method should add to the current conversation. Refer to the table below for a list of all types supported by this method.
Type value
Content Type
0
Text
1
Quick Button
3
Image
6
Question (Blocking)
9
Video
10
Audio
11
File
17
Url
The following cloud script snippet shows how to add dynamic buttons inside a chat flow:
1
/*
2
The Xenioo variable colors_list holds a simple JSON built like this:
3
4
[
5
{
6
"colorid": "A",
7
"color": "Red"
8
},
9
{
10
"colorid": "B",
11
"color": "Blue"
12
},
13
{
14
"colorid": "C",
15
"color": "Yellow"
16
}
17
]
18
19
JSON.parse transform it into a full object that can be iterated to
20
create multiple chat buttons
21
22
*/
23
24
var colors = JSON.parse( conversation.GetVariableValue( "colors_list" ) );
25
for( var i=0; i < colors.length; i++ ){
26
conversation.AddReplyPart(
27
"1" /* part type. 1 is button */,
28
colors[i].color, /* part text. We're using color name */
29
colors[i].colorid, /* command payload. Its the value we want in our postback. We are using ID */
30
"picked_color", /* postback target variable name. we can use this later in our chatbot */
31
"", /* button target behaviour. We leave it empty: its the current one */
32
"Color Selected" /* button target interaction. We go to "Selected Color" you see in the diagram */
33
);
34
35
}
Copied!

GetConversationEntriesCount

This method will return the amount of entries found in the current conversation. Each entry represent a reply block from Xenioo or a reply block from a user.
1
conversation.GetConversationEntriesCount( );
Copied!
Conversation Entries access from scripting is always limited to the last 15 history entries, hence the maximum value GetConversationEntriesCount can return is 15.
Access to conversation entries is not enabled on preview chatbots. This function will always return 0 (zero) when used in a preview chatbot.

GetConversationEntry

Return the a model representation of conversation entry at a specific index. The conversation entry can be either a Xenioo reply block or a user reply block.
1
conversation.GetConversationEntry( index );
Copied!
The entry model has the following properties:
Field
Value
Source
Indicates what generated this entry. It can be:
0: User
1: Xenioo (your chatbot)
2: System (any issue)
Date
The date of the entry in dd/MM/yyyy HH:mm:ss format
PartsCount
The number of parts contained in this entry.

GetConversationEntryPart

Return the full model of a conversation entry part at a specific index and part index. As an example a Xenioo reply block made by a text bubble and two buttons will be represented by a single conversation entry made by three parts.
1
conversation.GetConversationEntryPart( index, partindex );
Copied!
The part model has the following properties:
Field
Value
Type
The type of the entry. Refer to the AddReplyPart function for a short list of possible types.
SubType
The subtype of the part
Text
The text associated to the part
Command
The command, if any, associated to the part. If the part is a button this will be the unique payload
TypeDelay
The calculated type delay, in milliseconds.
PartsCount
The amount of child parts that create this part. Some parts, like a card carousel may be comprised of multiple subparts.
If the parent conversation entry is generated by Xenioo (your chatbot) or by the System, the maximum length of the text property will be cut at 128 characters maximum.
This brief script example can be copied and pasted in a Cloud Script action to create a variable containing the latest conversation entries:
1
var chatlog = "";
2
3
for( var i=0; i < conversation.GetConversationEntriesCount(); i++ ){
4
5
var entry = conversation.GetConversationEntry( i );
6
switch( entry.Source ){
7
case 0:
8
chatlog += "User:";
9
break;
10
case 1:
11
chatlog += "Chatbot:";
12
break;
13
case 2:
14
chatlog += "System:";
15
break;
16
}
17
18
for( var p=0; p < entry.PartsCount; p++ ){
19
var part = conversation.GetConversationEntryPart( i, p );
20
chatlog += part.Text + "\r\n";
21
}
22
23
chatlog += " (" + entry.Date + ")\r\n";
24
chatlog += "\r\n";
25
26
}
27
28
conversation.SetVariable( "chatlog", chatlog );
Copied!

GetConversationEntrySubPart

Return the full model of a conversation entry sub-part. As an example a Xenioo reply block made by a carousel will be represented by a single entry with one part (the element) containing at least two sub-parts (the carousel page and at least one button).
1
conversation.GetConversationEntrySubPart( index, partindex, subpartindex );
Copied!

Operators And Conversation Control

GetOnlineOperatorsCount

This function will return the number of online operators available for the current bot.
1
conversation.GetOnlineOperatorsCount( );
Copied!

GetOnlineOperator

This function will return an instance of the online operator found at index. This function must be called after requesting the total count of online operators using GetOnlineOperatorsCount.
1
conversation.GetOnlineOperator( index );
Copied!
Each operator instance will have the following structure:
1
{
2
Id:string; //The unique id of the operator
3
Email:string; //The email associated with the operator account
4
Group:string; //The operator group assigned during invitation
5
}
Copied!

GetOnlineOperators

This function will return a string containing all the emails of the operators detected as online for a chatbot. Each email is separated by a semicolon (;).
1
conversation.GetOnlineOperators( );
Copied!

TakOver

This function will take over the current conversation and assign it to the operator with the specified email. This function will return true if the operator is online and the conversation can be assigned, false otherwise.
1
conversation.TakeOver( email );
Copied!
When previewing your chatbot, online operator count will always be equal to one. All functions will return your current user details.
The following sample showcases a simple loop on all online operators. The resulting operators variable can be set in a text bubble to display the result.
1
var count = conversation.GetOnlineOperatorsCount();
2
var tx = "";
3
4
for( var i=0; i < count; i++ ){
5
var operator = conversation.GetOnlineOperator( i );
6
tx += operator.Email + " (" + operator.Group + ")\n";
7
}
8
9
conversation.SetVariable( "operators", tx );
Copied!

Utilities

Format

This method can return a formatted string for a number or date value according to a format specification string. The type of data supplied can be explicitly specified or can be guessed by the method.
1
conversation.Format( value, format );
2
conversation.Format( value, format, datatype );
3
conversation.Format( value, format, datatype, culture );
Copied!
Datatype can be set to date or number. If datatype is supplied the method will attempt to convert value to the specified datatype. If no conversion is possible an error will occur.
The culture parameter can be used to specified the source culture of the value. The source culture can determine how a value is represented. As an example a en-US culture will expect a dot as a decimal separator and and date in mm/dd/yyyy format.
Some examples below:
1
var money = conversation.Format( 100000, "#,###€" ); // == 100.000€
2
var cut = conversation.Format( 10.5301, "0.00" ); // == 10.53
3
var date = conversation.Format( new Date(), "dd/MM/yyyy" ); // == day/month/year
Copied!

GetNextRandom

This method can generate a random integer number ranging from min to max value (both included).
1
conversation.GetNextRandom( minvalue, maxvalue );
Copied!

XmlToJSon

This method will try to parse a given XML source text and transform it into a valid JSON representation. The JSON representation can then be transformed to an object instance using standard JavaScript parse method.
1
conversation.XmlToJSon( xmlsource );
Copied!
Last modified 2mo ago