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 selectthe 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:
If you need to use other variable's value in your script variable function, use variables argument.
In this example script variable named script3 uses value of the other variable named one:
If you need the textual value of the variable, not the actual value, you can use variables.<name>.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 variables in order to perform the calculation, you can make use of the quriobot.async utility:
function(callback, variables) {
quriobot.async.mapValuesSeries({
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 it's arguments plus the following utility functions:
- quriobot.ajax(url, callback, data, headers, options) - perform http requests (GET if no dataparameter 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
- quriobot.store- storage object for saving persistent values between the visits and pages, if needed:
- quriobot.store.get(key: string) - get value by key
- quriobot.store.set(key, value, [expires]) - set value by the key, optional expires parameter is in seconds
- quriobot.Cookies - imported js-cookiespackage:
Create a cookie, valid across the entire site:
quriobot.Cookies.set('name', 'value')
Create a cookie that expires 7 days from now, valid across the entire site:
quriobot.Cookies.set('name', 'value', { expires: 7 })
Create an expiring cookie, valid to the path of the current page:
quriobot.Cookies.set('name', 'value', { expires: 7, path: '' })
Read cookie:
quriobot.Cookies.get('name') // => 'value'
quriobot.Cookies.get('nothing') // => undefined
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 messages or HTML fields:
- Use them in Action responses to easily connect the bot 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's in the value setting:
And then you can use it in the jump logic:
For every bot step, there's a corresponding system variable which 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}}
Quriobot
Friendly & Fun
Interact & Convert