Microsoft Bot Framework: Handing off to a human for agents/supervisors with C# and the BotBuilder SDK
Supervising bot conversations
One advanced concept for bots built using the Microsoft Bot Framework is handing over conversations to human supervisors (or agents). For instance when the bot is no longer able to automatically process a request, or if the end-user of the bot is frustrated/stumped and wants some assistance.
There is already some great content out there on this concept which goes into more detail on the user scenarios: https://docs.microsoft.com/en-us/bot-framework/bot-design-pattern-handoff-human. In addition, I've collated some resources and tips below in order to assist you.
FlightBot: Example Bot-HandOff scenario
Let's look at an example high level scenario together, in which there are 3 participants:
- Dave (human) - Customer/bot end-user
- FlightBot (some code) - bot built using the MS Bot Framework
- Colin (human) - Call center booking agent
Flightbot has been developed to walk the user through a series of questions to capture travel location, dates etc. This turn-by-turn conversation can easily be automated by the bot. However, In this scenario Dave has very specific travel requirements and so wants to discuss with a booking agent directly. FlightBot see's the request for human assistance and alerts the call center booking agent (Colin) there is an end-user waiting for a response. Colin accepts the request and takes charge of the conversation, directly typing responses to Dave on behalf of FlightBot.
The request for human assistance does not need to be explicit. For example the sentiment of the users responses could be monitored and if reaches a certain threshold, the bot-handoff is initiated.
To understand the whole bot-handoff concept further, watch my colleague, Hannah Krager, give a great talk here: https://channel9.msdn.com/events/Build/2017/P4075
Assuming, you're still with me - it's time to get the code samples up and running:
A word of caution, the additional libraries to assist with this are in a state of heavy flux and provided as samples only. If you're ok with that, read on fellow bot developer <''>
If you're a Node.js fan, you can start here: https://github.com/palindromed/Bot-HandOff and read an article by Lilian Kasem, one of the authors of it here: https://www.microsoft.com/reallifecode/2017/06/30/bot-to-human-handover-in-node-js/. However, given the title of this article, I'm looking at the C# SDK.
Now, if you prefer C#, it's a little bit more trickier.
However, my colleague Tomi Paananen has created a great library to help available here: https://github.com/tompaana/intermediator-bot-sample. You can also read his accompanying blog post on this: http://tomipaananen.azurewebsites.net/?p=1851.
Again, did I mention these libraries are in a state of flux? I'll try and keep this post updated with changes :) For transparency, the video samples shown below are actually based off my fork here: https://github.com/daltskin/intermediator-bot-sample (pull request outstanding).
Update 15/08/2017: PR now merged into repo: https://github.com/tompaana/intermediator-bot-sample
In addition, there are a few moving parts to getting this up and running depending which scenario you want you agents/supervisors to use. When debugging this locally, you'll end up with quite a few windows open as you need to run a number of things.
Scenario 1: Channel <-> channel
This is the most straight forward, all you'll need is your bot running and then use different channels to simulate different users. In the video I use a combination of Skype, Webchat and Slack. I then use Slack as the supervisor channel by running: "agent watch". This begins listening for any requests for assistance to the bot - instigated by any use of the term "human" from the end-user.
[video width="1216" height="684" mp4="https://msdnshared.blob.core.windows.net/media/2017/08/Bot-HandOff2.mp4"][/video]
Here are some other Agent commands you can run followed by the accompanying results:
- Agent options - menu list of commands that you can run
- Agent waiting - display all pending human hand-off requests
Scenario 2: Channel <-> call center (Agent UI)
If you're looking for the Agent UI scenario you'll also need the Webchat agent written by Bill Barnes here: https://github.com/billba/agent as well as the intermediator C# sample bot running locally (again follow the Readme.md to ensure you're endpoints are correctly configured with ngrok/bot framework portal settings).
To get it to build I needed to run the following commands:
npm install firstname.lastname@example.org npm run build npm run start
The Agent will then poll against your bot endpoint eg: http://803705b8.ngrok.io/api/agent/1 - looking to see if it needs to spin up any webchat controls for any user requesting a "human" to talk to. The nice feature of this scenario is that a single agent can manage multiple conversations at a time. The video below shows what this looks like to setup and run with a a user requesting assistance on Skype:
[video width="1920" height="1080" mp4="https://msdnshared.blob.core.windows.net/media/2017/08/Agent-UI.mp4"][/video]