Bot Possession: A Customer Service Solution
What is bot possession?
Bot possession is a concept that you, as a bot administrator, can monitor your bot’s conversations in realtime, and “take over” a conversation with one of your users at any point.
Imagine a call center, where customers are connected to one-on-one conversations with service representatives. Many companies are beginning to use chatbots to handle increasing numbers of help desk phone calls, but what if the customer has a question that the chatbot is unable to answer? Bot possession allows a single agent to monitor dozens of conversations with the chatbot, and step in to a conversation when the chatbot is unable to provide the customer with a relevant response.
In this tutorial, we’ll be building the interfaces necessary to implement bot possession. We’ll be using Firebase to store the bot’s conversations in realtime, so that they can be monitored through a dialog interface.
Once you’ve downloaded the repository, insert your Pandorabots API credentials and botname into js/index.js so that your user can connect to your bot:
var pb = new Pandorabot("aiaas.pandorabots.com", APP_ID, BOTNAME, USER_KEY);
Note: talk.js relies on cookies to remember the identity of your users. Most browsers, unfortunately, will try to prevent you from setting cookies on local files. To use the code in the repository, you will either need to enable file cookies in your browser, or host the files on a server.
If you don’t have a server to work with, navigate to directory where the files live, and run:
$ python -m SimpleHTTPServer 8000
You can now visit your interface at localhost:8000.
Firebase is a realtime cloud database that recently joined the Google Cloud platform. It allows multiple clients to sync with the same data. This is perfect for our application, because both the user and the agent need realtime access to the database.
Firebase can be a great utility for developers; they offer a free Hacker Plan that should be sufficient to complete this tutorial.
Once you’ve created an account and a new Firebase application, you’ll need to insert your database’s URI into js/index.js, js/log.js, and js/agent.js to connect each interface. You can do this near the top of each file, where the new Firebase instance is created:
... var fb = new Firebase("https://your-app.firebaseio.com/"); ...
Information is stored in Firebase in JSON objects, each of which we’ll be assigning a particular property type. Each of our three interfaces listens for additions to the database, and depending on the type and client_name associated with the new object, they will each respond accordingly. Our framework includes models for different types of messages, as well as changes (i.e., possessed or not possessed) during the conversation.
Conversations between your bot and an end-user will occur in one of two different “states”: possessed or not possessed. The default state is not possessed, meaning that, at the start of a new conversation, a user will initially be chatting with your bot.
Conversing with the bot
This screenshot shows the default index.html page, as the user is talking to the bot. Each time the bot responds, a new object is pushed to Firebase. This contains the user’s input, the bot’s response, along with some other information like the user’s unique client_name and a timestamp of the interaction.
The log.html page listens for user/bot interactions that get pushed to the database, and streams them in chronological order. As the users are talking to your bot, you can see the interactions being added to the log in realtime.
Conversing with a human agent
Clicking on a client_name found on the dialog page will open a new page that allows you to talk directly to the user in question. At this point, the conversation has been possessed, so all of the user’s inputs will bypass the bot and be pushed directly to Firebase. Inputs sent from the agent appear with a green icon, to distinguish between responses that were sent from the bot.
You may also click the “End Possession” button on agent.html to return the conversation to the bot. You can still monitor the user’s conversation with the bot from the agent interface.
Note: the Dialog page has a button that will clear all the logs from the dialog window. It achieves this by emptying your Firebase (useful if you don’t need to store all of your interactions).
Getting the bot to talk first
Oftentimes, customer support chatbots fail because the user assumes they can say anything to the bot and expect a correct or relevant response. Most of these types of bots have domain-specific knowledge, so it can be helpful to prompt your user’s input by having the bot speak first. This will eliminate many situations in which you might be compelled to possess the conversation yourself.
We can do this by taking advantage of the HTML onload event. When this event triggers, we can send a hardcoded input to the bot using the doStart function defined in index.js:
... <body onload="doStart('INIT CONVO');"> ...
Then, in your AIML, you can create a category that contains the remarks you’d like the bot to initialize the conversation with:
<category> <pattern>INIT CONVO</pattern> <template> Hello there, I am a virtual customer service agent. Try asking me some questions about my company's products or services. </template> </category>
Congratulations! If you’ve completed this tutorial, then you are now armed with an interface to implement basic bot possesion. As always, we encourage you to take this code and add your own unique features and customizations. From there, you can deploy your own customer service bot to your website to help significantly reduce the live chat load for your human representatives.
Finally, remember to keep an eye out for related upcoming tutorials, which will explore:
- Creating a Virtual Customer Service Representative bot in just a few quick steps
- Using Firebase to log conversations in your application
Originally published at blog.pandorabots.com on October 30, 2014.