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


This method will return the current value of a specified variable. If the variable does not exist, an empty string is returned.

conversation.GetVariable( variablename );


This method will update the value of a variable with a given name. Multiple overloads are available for additional call details.

conversation.SetVariable( variablename, variablevalue );
conversation.SetVariable( variablename, variablevalue, setmode );
conversation.SetVariable( variablename, variablevalue, replacewith, setmode );

The setmode parameter defines the mode used to update the target variable. You can use the following table as a reference for the parameter.




Default. The value will be overwritten


Append. The value will be added to the end of the current value


Concatenate. The value will be added to the end of the current value, separated by a comma


Add. Xenioo will attempt to sum the given value to the current value of the variable


Subtract. Xenioo will attempt to subtract the given value from the current value of the variable


Divide. Xenioo will attempt to divide current value of the variable by the given value


Multiply. Xenioo will attempt to multiply current value of the variable by the given value


ReplaceString. All occurences of the given value inside the current value will be replaced by replacewith value


RemoveString. The given value will be removed from the current variable value


ClearValue. The current value of the variable will be set to an empty string value


This method will create a new tag and attach it to the current conversation.

conversation.SetTag( tagname );


This method will drop a specific tag from the current conversation. No error is returned if the tag does not exist.

conversation.DropTag( tagname );


This method will check the existence of specific tag and return true if found otherwise false.

conversation.HasTag( tagname );

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.


This method will return the current value of the specified global variable. If the variable does not exist, an empty string is returned.

conversation.GetGlobalVariable( variablename );


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.

conversation.SetGlobalVariable( variablename, variablevalue );
conversation.SetGlobalVariable( variablename, variablevalue, expireminutes );

Conversation Flow and Data


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.

conversation.GoTo( targetbehaviour, targetinteraction );


The SwitchChannel method will change the current conversation channel. Any pending message created during the method execution will be delivered to the new channel. The target channel must be online.

conversation.SwitchChannel( channelname );

The method will return true if the switch is successful, otherwise false.

The method does not check the conversation data against the new channel: switching a Web conversation to a WhatsApp conversation without a user phone number will not deliver any message.


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.

conversation.GetShareURL( expiretime, takover, autohandover );


This method will delete and invalidate any shared URL currently active for the current conversation.

conversation.DropAllShares( );


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.

conversation.Log( text );


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.

conversation.Log( text );


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.

conversation.AddReplyPart( text );
conversation.AddReplyPart( type, text, command );
conversation.AddReplyPart( type, text, command, commandvariable );
conversation.AddReplyPart( type, text, command, commandvariable, targetbehaviour, targetinteraction );

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




Quick Button




Question (Blocking)









The following cloud script snippet shows how to add dynamic buttons inside a chat flow:

  The Xenioo variable colors_list holds a simple JSON built like this:
      "colorid": "A",
      "color": "Red"
      "colorid": "B",
      "color": "Blue"
      "colorid": "C",
      "color": "Yellow"
  JSON.parse transform it into a full object that can be iterated to 
  create multiple chat buttons

var colors = JSON.parse( conversation.GetVariableValue( "colors_list" ) );
for( var i=0; i < colors.length; i++ ){
                              "1"                 /* part type. 1 is button */, 
                              colors[i].color,    /* part text. We're using color name */
                              colors[i].colorid,  /* command payload. Its the value we want in our postback. We are using ID */ 
                              "picked_color",     /* postback target variable name. we can use this later in our chatbot */
                              "",                 /* button target behaviour. We leave it empty: its the current one */
                              "Color Selected"    /* button target interaction. We go to "Selected Color" you see in the diagram */


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.

conversation.GetConversationEntriesCount( );

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.


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.

conversation.GetConversationEntry( index );

The entry model has the following properties:




Indicates what generated this entry. It can be:

0: User

1: Xenioo (your chatbot)

2: System (any issue)


The date of the entry in dd/MM/yyyy HH:mm:ss format


The number of parts contained in this entry.


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.

conversation.GetConversationEntryPart( index, partindex );

The part model has the following properties:




The type of the entry. Refer to the AddReplyPart function for a short list of possible types.


The subtype of the part


The text associated to the part


The command, if any, associated to the part. If the part is a button this will be the unique payload


The calculated type delay, in milliseconds.


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:

var chatlog = "";

for( var i=0; i < conversation.GetConversationEntriesCount(); i++ ){
    var entry = conversation.GetConversationEntry( i );
    switch( entry.Source ){
        case 0:
            chatlog += "User:";
        case 1:
            chatlog += "Chatbot:";
        case 2:
            chatlog += "System:";
    for( var p=0; p < entry.PartsCount; p++ ){
        var part = conversation.GetConversationEntryPart( i, p );
        chatlog += part.Text + "\r\n";
    chatlog += " (" + entry.Date + ")\r\n";
    chatlog += "\r\n";

conversation.SetVariable( "chatlog", chatlog );


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).

conversation.GetConversationEntrySubPart( index, partindex, subpartindex );


Changes the text of the current user message. The change happens only in the reply processing pipeline. The original user message is still displayed in the conversation.

conversation.SetMessageText( text );

Operators And Conversation Control


This function will return the number of online operators available for the current bot.

conversation.GetOnlineOperatorsCount( );


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.

conversation.GetOnlineOperator( index );

Each operator instance will have the following structure:

    Id:string;       //The unique id of the operator 
    Email:string;    //The email associated with the operator account 
    Group:string;    //The operator group assigned during invitation


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 (;).

conversation.GetOnlineOperators( );


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.

conversation.TakeOver( email );

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.

var count = conversation.GetOnlineOperatorsCount();
var tx = "";

for( var i=0; i < count; i++ ){
    var operator = conversation.GetOnlineOperator( i );    
    tx += operator.Email + " (" + operator.Group + ")\n";

conversation.SetVariable( "operators", tx );



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.

conversation.Format( value, format );
conversation.Format( value, format, datatype );
conversation.Format( value, format, datatype, culture );

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:

var money = conversation.Format( 100000, "#,###€" );    // == 100.000€
var cut = conversation.Format( 10.5301, "0.00" );     // == 10.53
var date = conversation.Format( new Date(), "dd/MM/yyyy" ); // == day/month/year


This method can generate a random integer number ranging from min to max value (both included).

conversation.GetNextRandom( minvalue, maxvalue );


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.

conversation.XmlToJSon( xmlsource );

Last updated