How to use bot Variables

Using Variables throughout your bot is something an advanced bot can’t do without! On the Bot Settings > Variables section you can add them, name them and connect to a step in your bot or even a custom JavaScript function! Easy as that!

Please note that the Variables are case-sensitive and thus need to be written exactly the same!

Choosing the right Variable type

  • Name your variable and then select the desired variable type and set its settings:
    • Step variable type: Gets the value from the answer of the chosen step
    • String variable type: Gets the value from the entered static string (for example for storing often-used phrases like addresses or company names)
    • Script variable type: Gets the value from the provided javascript function, which can optionally access other variables allowing greater flexibility. In this example custom asynchronous function provides a value for the variable script2:
    • Enable Resolve variable server-side setting when you want to use an external HTTP endpoint that is secured with CORS If you need to use other variables’ values in your script variable function, use variables argument.
    • In this example script variable named script3 uses the value of the other variable named one:
    • If you need the textual value of the variable, not the actual value, you can use variable.text syntax
    • Please note that in case your script variable needs to use another script variable in order to calculate the result, you need to call the value with a callback. In this example script variable named script uses the value of another variable named script3 to calculate the result:
    • If you need to get values from more than one script variable in order to perform the calculation, you can make use of the quriobot.async utility:
function(callback, variables)  {
        script3: variables.script3.value,
        script4: variables.script4.value
}, function(getValue, key, cb) {
    getValue(function (res) {
        cb(null, res);
    }, variables)
}, function(err, results) {
    callback(results.script3 + results.script4)
**Important note:** Please keep in mind that the script-function scope is limited to its arguments plus the following utility functions:

Create a cookie, valid across the entire site:

quriobot.Cookies.set('name', 'value')

Where can you use these Variables? Almost everywhere!

  • Use them in your Chat Messages:
  • Use them as parameters in your redirect URL:
  • Use them within your Script chat texts or HTML fields:
  • Use them in Action responses to easily connect the bot to other services, such as your CRM, Slack, MailChimp newsletter signup, or email automation to name just a few examples!

How can I store the variable value along with the chat transcript, or use it in the jump logic?

It is possible to store the variable value for the chat transcript and/or the jump logic by adding a Goto step with that variable in the value setting:

And then you can use it in the jump logic:

For every bot step, there’s a corresponding system variable that uses the code name bot step setting:

so that, for example, if you have a bot step with the code name location_address, you can refer to its value as {{location_address}}

Using the complex step values in the variables

In the case of more complex step types, like date range, where you get an array of values instead of just one, you can have several variables out of a single-step answer using this approach:

Add 2 script variables as described above, and use the scripts below:

for variable 1:

function(callback, variables)  {
var value = JSON.parse(variables.dateRange.value)[0]

for variable 2:

function(callback, variables)  {
var value = JSON.parse(variables.dateRange.value)[1]

where dateRange is the name of your date range step variable.

The special syntax for variable substitution

In addition to the {{variable}} syntax, there are such options for the variable replacement, that can be especially useful for the JSON text:

  • {{variable.text}} - the textual value of the variable, not the actual value
  • {{variable.value}} - the actual value of the variable, not the textual value
  • "{{}}" - the integer value of the variable, useful for JSON text
  • "{{variable.float}}" - the float value of the variable, useful for JSON text
  • "{{variable.boolean}}" - the boolean value of the variable, useful for JSON text
  • "{{variable.json}}" - the JSON value of the variable, useful for JSON text
  • "{{variable.nullIfEmpty}}" - passes JSON null if the variable is empty and value of the variable otherwise, useful for JSON text

Edit this page

See also