Can I control the bot programmatically?

Quriobot provides a basic Javascript API which you can use to control Quriobot’s behavior

Note: as we are actively developing it, new features are added as we go, but we always try to keep backward compatibility.

If you include widget code on your page, the global quriobot object will be available and it has such methods:

  • quriobot.init (options) - initialize the bot if the explicit initialization was passed via widget URL API so your embed widget code will look like this:
<script type="text/javascript">
  if (!Array.isArray(window.qbOptions)) {
    window.qbOptions = []
  }
  window.qbOptions.push({
    "use":"sadfasdfasdfas/wj0M8mVgeJrRW4qY",
    "init": "explicit",
    "onScriptLoad": "quriobotLoaded"
  });
</script>
<script type="text/javascript" src="https://static.botsrv.com/website/js/widget2.ea14eec4.js" integrity="sha384-eIQOpcMrVK2La47/uGhqpJMnpRZ4rtYQpRgr1/EbeF2HLFSPGoMsegUKf2xJUcuP" crossorigin="anonymous" async defer></script>

this allows you to have full control of the moment when the bot appears on the screen (event the sticky avatar part). Please note that onScriptLoad parameter is passed, this is a global-scoped callback function that will be called once the Quriobot widget script is fully loaded and so quriobot.init can be called

<script type="text/javascript">
   function quriobotLoaded(){
       quriobot.init({
           context: {
                myContextName: "my context value"
           }
       })
   }
</script>
<script type="text/javascript">
  if (!Array.isArray(window.qbOptions)) {
    window.qbOptions = []
  }
  window.qbOptions.push({
    "use":"sadfasdfasdfas/wj0M8mVgeJrRW4qY",
    "init": "explicit",
    "onScriptLoad": "quriobotLoaded"
  });
</script>
<script type="text/javascript" src="https://static.botsrv.com/website/js/widget2.ea14eec4.js" integrity="sha384-eIQOpcMrVK2La47/uGhqpJMnpRZ4rtYQpRgr1/EbeF2HLFSPGoMsegUKf2xJUcuP" crossorigin="anonymous" async defer></script>

then you can use context in your script variables like quriobot.options.context.myContextName:

function(callback, variables) {
    callback(quriobot.options.context.myContextName)
}

and even more! QB automatically will prepare API methods for you for all your context values in form of:

{%api.qb_myContextName%}

Note that if your context is a nested object, you can still access the nested values by flattening it using _separator:

{%api.qb_myContextName_nested_value%}

You can also override context from the URL using qb . prefix and JSON encoding:

http://my-qb-page.com?qb.myContextValue="my value"
  • quriobot.start([bot_path], [language], [entryPoint], [isComplete])- start the bot if it’s not set to be autostarted on the page load.
    • if the bot_path is passed and it’s different from the previous bot path, the bot will be switched to a new path. Bot Path is shown on the *Embed Code tab
    • language parameter, if passed, will force the bot language. It can have the values described here.
    • entryPoint parameter, if passed, will force the bot entry point step. Step keys can be obtained from the Step settings:
    • isComplete parameter, if passed false, will not finish the previous conversation when you switch between the bots and instead store the state of the previous bot (if the setting for the saving of the bot is enabled)
  • quriobot.restart() store the results for the current chat and restart the chat
  • quriobot.show_frame()- show the bot frame if it’s not shown
  • quriobot.hide_frame()- hide the bot frame if it’s shown
  • quriobot.destroy()- destroy the bot widget and the frame completely. This is essentially the reverse of quriobot. init. After calling this method, in order to show the bot again, quriobot. init has to be called
  • quriobot.hide() - hides the bot widget completely
  • quriobot.show() - shows the bot widget
  • quriobot.goto(key)- moves the bot conversation directly to the passed step. Step keys can be obtained from the Step settings:

Options object has such properties:

  • language - current bot language
  • autoStart - auto-start timeout
  • autoStartCount - auto start after count
  • restoreState - restore bot state
  • restartAfterClose - restart after close
  • position - bot position
  • positionRtl - bot position for RTL languages
  • preventExitIfIncomplete - prevent bot exit if the response is incomplete
  • visitor - The object with the visitor details, has such properties:
    • id - to use this ID for the local response storage, as well as the visit counts
    • firstName - first name
    • lastName - last name
    • email - email
    • phone - phone number
    • gender - gender (number), 0 - male, 1 - female)
    • avatar - avatar image URL
    • timezone - timezone offset, number, in hours
  • botOffset - Object with the bot offset, has such properties:
    • top - bot offset top
    • bottom - bot offset bottom
  • stickyAvatarOffset - Object with the sticky avatar offset, has such properties:
    • bottom - sticky avatar offset bottom
  • stickyAvatarPopup - The object with the sticky avatar popup (soft-start), has such properties:
    • autoShowAfterClosed - auto show sticky avatar popup after bot is closed
    • image - sticky avatar image
  • showStickyAvatar - show sticky avatar, value can be one of: ‘always’, ’never’, ‘closed’
  • avatarImage - bot avatar image
  • context - context data
  • showStickyAvatar - ‘always’ - always show sticky avatar, ’never’ - never show, ‘closed’ - show after the first close
  • ga - track bot actions with Google Analytics
  • preload - preload the bot prior to actually starting
  • showCloseButton - show bot close button(s)
  • entryPoint - step key to use as an entry point
  • onAnswer - function(results, question, answer) on answer callback
  • onAnswerRedo - function(results, question, answer) - on answer redo callback
  • onExit - function(results) - on exit callback
  • onFinish -function(results) - on finish callback
  • onLeave - function(results) - on leave callback
  • onRedo - function(results, question, answer) on redo callback
  • onReturn - function(results) - on return callback
  • onValidate - function(results, callback) - on validate callback
  • onSave - function(results, responseId, callback) on save callback
  • onUpdate - function(results, responseId, callback) on update callback
  • onLoad - function(data) - on load callback
  • onQuestion - function(results, question) on question callback
  • onStart - function(results) on start callback
  • onInit - function() - on init callback
  • onLiveChat - function() - on the live chat mode switch

Edit this page

Tags
See also