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:

  • quriobot.ajax(url, callback, data, headers, options) - perform HTTP requests (GET if no data parameter is passed)
    • url - request URL
    • data - data to send as a request body (when set, the request method is set to POST
    • headers- headers object to apply as request headers
    • options - options object which currently supports:
      • method - request method
      • withCredentials - is a Boolean that indicates whether or not cross-site Access-Control requests should be made using credentials such as cookies, authorization headers or TLS client certificates. Setting withCredentials has no effect on same-site requests.
  • quriobot.dotObject - imported dot-object package
  • quriobot.URL - imported url-parse package
  • quriobot.flatten - imported flat package
  • quriobot.mustache - imported mustache package
  • quriobot.moment - imported moment package
  • quriobot.numeral - imported numeral package
  • quriobot.async - imported async package
  • storage object for saving persistent values between the visits and pages, if needed:
    • string) - get value by key
    •, value, [expires]) - set value by the key, optional expires parameter is in seconds
  • quriobot.Cookies - imported js-cookies package:
    • 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.

Edit this page

See also