search

Chat widget API


FAQ Bot has a simple API to allow interactions between the page hosting the widget and the bot. This article details the possible interactions, and is aimed at a technical (developer) audience.

There are three types of interactions between the page and bot

  1. Opening / Closing the bot
  2. Set context
  3. Ask Questions / Trigger Engagements

The API is accessed via the faqbot object i.e. faqbot.open()

 

Available API operations

  • askQuestion - asks a question on the user's behalf
  • clearChatHistory - creates a new conversation for the same user
  • clearUserAndChatHistory - creates a new user and conversation
  • close - closes the chat window
  • mount - adds the bot back on to the page (i.e. makes it visible again)
  • open - opens up the widget to show chat window
  • setContext - sets context
  • toggleMenu - opens the widget menu
  • triggerEngagementEvent - triggers an engagement event
  • unmount - Removes the bot from the page entirely

 

Opening / Closing the chatbot

This can be done by calling the open or close api calls.

for example:

faqbot.open();

Asking questions 

This can be done with 

faqbot.askQuestion("What products are on sale?");

The question will be asked of the bot exactly as if the user had typed the question themselves into the widget.

Triggering events

faqbot.triggerEngagementEvent("eventName") This will trigger an engagement called "eventName"

for example:

faqbot.triggerEngagementEvent("salesEngagement");

Setting context

You can share information from the page to the bot (eg location, logged in user name, URL, etc).
The bot can store this information about the user as context. This can be provided by the page via the setContext api call:

faqbot.setContext({contextKey: "contextValue"})

e.g.

faqbot.setContext({email: "[email protected]"})

You will need to have corresponding context keys set up  - find out more.

 

Other considerations

Ensure chatbot is loaded before trying to interact with it

Something to consider when writing your Javascript to interact with the bot is that it may not have loaded yet. You will need to wrap your calls to the API around checking it has loaded and trying again in a timeout. 

e.g.

function openBot() {
  if (window.faqbot) {
    faqbot.open();
  } else {
   setTimeout(openBot, 500);
  }
}

Helpful?