What Are Variables in Scripted Chatbots?
Introduction
Getting to grips with variables in a scripted chatbot is essential for crafting engaging and interactive conversations. Variables enable the chatbot to store and manage data, which helps make interactions more tailored and impactful. In this article, we’ll explore the various types of variables used in scripted chatbots and how they can boost your chatbot's capabilities.
System Variables
At the start of a session, the following system variables are automatically generated:
- $startSequence
- The text that initiated the current session, kicking off the entry step.
- $conversationClientId
- The ID that identifies the client. For instance, on WhatsApp, this will be a phone number; on Apple Business Chat, it’s a hash.
- $conversationClientIdNormalized
- A normalized (00) version of the conversationClientId, specifically for use with phone numbers.
- $conversationHostId
- The ID that identifies the hosts. For more details, see $conversationClientId.
- $conversationClientName
- The name of the client, though this may not be supported by all channels.
- $channel
- The channel through which the conversation occurs.
- $chatId
- A fixed hash based on the channel, conversationClientId, and conversationHostId.
System Functions
When a session begins, the following system functions are automatically created:
- $GetNow()
- Fetches the current time based on the specified parameters.
-
- TimeZone is a required parameter that lets you specify the time zone for which to retrieve the time. You can use any time zone supported by the tz database. Check the "TZ identifier" column in the table on that page for the appropriate value.
- Format is also required and allows you to define the format for the time. For example, using
yyyy-MM-dd hh:mm:ss
will give you the current year, month, day, hour, minute, and seconds. You can find all possible formatting options here and here. - Language is an optional third parameter that allows you to specify the language for the output. For instance, if you request the weekday and provide
it-IT
, you’ll receive the weekday in Italian. A list of supported language tags can be found here. Refer to the "Language tag" column in the table on that page for the appropriate value. If you skip this parameter, the output will default to "en-US".
- For example, to get the current date and time in the timezone of our HQ in Breda, you would use:
$GetNow("Europe/Amsterdam", "yyyy-MM-dd hh:mm:ss")
. - It can also be fun to get the current day. Let’s spice it up by getting the Italian version:
$GetNow("Europe/Amsterdam", "dddd", "it-IT")
.
Variables from Input
Variables can be generated from user input. For more details on how this works, please check the input step in the steps docs.
Variables from Regular Expressions
Variables can also be created from the entry input provided by the user. For further information on this, refer to the entry step in the steps docs.