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.
SetVariable
This method will update the value of a variable with a given name. Multiple overloads are available for additional call details.
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.
DropTag
This method will drop a specific tag from the current conversation. No error is returned if the tag does not exist.
HasTag
This method will check the existence of specific tag and return true if found otherwise false.
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.
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.
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.
SwitchChannel
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.
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.
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.
DropAllShares
This method will delete and invalidate any shared URL currently active for the current conversation.
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.
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.
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.
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:
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.
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.
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.
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
PartsCount
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:
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).
SetMessageText
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.
Operators And Conversation Control
GetOnlineOperatorsCount
This function will return the number of online operators available for the current bot.
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.
Each operator instance will have the following structure:
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 (;).
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.
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.
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.
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:
GetNextRandom
This method can generate a random integer number ranging from min to max value (both included).
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.
Last updated