How do I pass a context to my bot via URL?

While the generic approach to passing a programmatic context is using JS API init, there’s an easier way of passing a context via just an URL query (get parameters).

Using the script variables, add such script variable with the name my_parameter:

function(callback, variables) {
  var my_parameter = new quriobot.URL(window.location.href, true).query.my_parameter || ""
  callback(my_parameter)
}

If you need this parameter to be persistent across multiple visits and pages, use quriobot.store utility:

function(callback, variables) {
  var key = 'qb.my_parameter';
  var my_parameter = quriobot.store.get(key);
  if (!my_parameter) {
    my_parameter = new quriobot.URL(window.location.href, true).query.my_parameter || "";
    quriobot.store.set(key, my_parameter)
  }
  callback(my_parameter)
}

You can then pass it like

https://my-page.com?my_parameter=value

Then you can use it in the chat texts like:

{{my_parameter}}

If you need to use the parameters in the response Advanced conditions or Response connections, then the way to go would be to use the GoTo step, use

{{my_parameter}}

in the value field:

Edit this page

Tags
See also