Home > Chat bot API

Categories: |


(Last Updated On: April 15, 2019)

****If you would like to test our BETA Chat Bot API, please start a chat with us or email us at support@snapengage.com****

Our chat bot API allows you or your developers create your own chat bot or build a connection with 3rd party bot providers. Through the API the bot can take chats from your website visitors, respond to messages with text messages or button options, transfer to a group of agents, to a widget, a specific agent,… Please make sure you are on the Design studio, otherwise this will not work.

In this article we will give you an example we’ve created that is hosted on Google Cloud platform, and how to connect it.

The below is just an example on how to configure our example of code, but the possibilities are endless!

In this article, we will show you how to make a customizable chatbot that can fulfill many of your needs, how to host the code on Google and use the bot with SnapEngage. We will give you an example we’ve created that is hosted on Google Cloud platform, and how to connect it. The Bot will then be able to take your clients chats, and you can configure the responses, and provide the visitor with different options in text or buttons view, with options to transfer to a group of agents, to a widget, to a specific agent, changing the widget as well as closing the chat. The bot will also be able to ban a visitor, ban their IP, or even direct them to a website using the go to command.

On our example, we are going to host the code on Google Cloud Platform, and this will be our endpoint. At the time this article was written, Google was offering a year for free, but check if this is still the case, as there may be a cost involved. You may be able to use other options for this.

  • Head over to https://console.cloud.google.com/ and create a new account if you don’t have one already.
  • Then head over to Cloud Functions
  • From the next page’s menu, create a new function, and from the following page give it a name. You will also choose “Node.js 8” under runtime, and type “processJSON” under function to execute. Also copy the URL onto your clipboard.
  • You will then paste the code on the box, and hit create. (we will go through our code example later on this article).
  • Then head over to the SnapEngage admin dashboard, go to settings, and click on add bot.
  • Select custom bot API
  • Then enter the endpoint (which is the URL you’ve previously copied onto your dashboard from Google Cloud), make sure there are no spaces the end of the URL, as you may have copied a space from Google Console, add the authorisation token which is on your code (we will also go through that later on this article) and give it a name. Also notice the button which allows you to turn it on or off. The bot will able to handle 10 concurrent chats.

Now download our template here if you want to work with it and make changes. And below, we will analyse the code a little further.

In the next part of the code you will determine what response the bot should give depending on the question. Here, if you type anything, you will be presented with 5 buttons (see line 4)

Each of those buttons will take a different action. For example, I’m searching for a chat system would transfer you to a SnapEngage agent and so would I would like to try SnapEngage would give you information on how to start a free trial, I am looking for a career opportunity would give you two options, and depending on which option, it would either give you information, or connect you to an agent.

These are the commands that the bot can handle :

For example, if you wanted to redirect a visitor to a website using the goto command, you would write something like this :

What we showed above was the example we worked with, and something you can use as a template, but if you would like to start from scratch, here is some technical information :

On the admin dashboard :

Bot Alias: Bot name showed to visitors
Endpoint URL: Internet facing endpoint hosted on the client web services, receiving a HTTP POST request from SnapEngage
Authorization Token: Token that is included in the https header as “authorization”
Tags: Optional, standard SnapEngage routing by tag feature

Payload :

On each message routed to the chat bot, SnapEngage makes a call to the webhook with the following information:
– the chat widget ID: to uniquely identifying the chat widget on the SnapEngage side – this is a String in UUID format
– the chat session ID: to uniquely identify the chat session, and to allow the logic at the webhook receiver to keep the context

–  the event type: this field specifies the type of message, i.e. visitor message, system message (page change, end of chat, etc.)  [chatStarted, chatClosed, message]
– the message content: can be text sent by the visitor or a system message information

Other information to pass through as well:

– if the chat was a proactive chat, the proactive prompt needs to be passed to the API for providing the bot the relevant context

Chat started :

Note: The “proactiveMessage” is the message that was displayed to the visitor as part of the proactive prompt. If it was a non-proactive chat then the element would not be included.

Chat Ended :

Chat Message :

Response payload :

The “parameters” element would be used in conjunction with certain operations such as GOTO, TRANSFER, or SWITCH_WIDGET

Did you find this article helpful?

Not HelpfulNeeds WorkSo-soHelpfulVery Helpful (1 votes, average: 5.00 out of 5)
Loading ... Loading ...

Published March 26, 2019