Transferring chatbot conversations to a human

October 27, 2019 devadvin

Today, chatbots are being used more and more. However, when questions are ambiguous or difficult to answer, users often prefer to chat with humans like you and me rather than with a bot. Recently, I developed a little demo for a hackathon that does exactly this – it hands off a chatbot conversation to an insurance agent. As I thought, the use case and the type of solution are relevant for other areas as well, so I quickly wrote this blog to explain how I did it.

Architecture

The solution looks trickier than it is, so don’t be afraid to try this out yourself. Despite the various technologies involved, the idea really was to limit the complexity.

The chatbot

Initially, the user chats with the chatbot via Messenger. The dialog is configured in the Watson Assistant skill, using a graphical user interface.

Dialog

The dialog (in my case, an insurance claim) is configured in a tree structure. The nodes contain all the information, for example, the responses of the chatbot, the trigger conditions, the branches, and so on.

If the user wants to report hail damage, they are prompted for the vehicle identification number (license plate number). If later in the process they want to talk to a human, the user and an agent are called and connected with each other using an external telecommunications platform. The agent is also shown relevant information gathered by the chatbot so far (for example, the VIN). To initiate this action calling external systems (so-called programmatic call), it must be defined in one of the nodes of Watson Assistant.

    "actions": [
      {
        "name": "/..._dev/actions/gateway",
        "type": "server",
        "parameters": {
          "query_params": "?request=start_call&phoneNumber=%2B49...&vin=$vin&salesNumber=%2B49...",
          "target_route": "/wahandler",
          "target_hostname": "http://....eu-de.mybluemix.net"
        },
        "credentials": "$private.my_credentials",
        "result_variable": "$my_result"
      }
    ]

Making the call

Ultimately, the two phone numbers are used by Twilio to set up a connection between the client and the agent. Twilio is a telecommunication platform that can add voice, video, and messaging to applications. I used their standard clicktocall Node.js Twilio client and deployed it into a Node.js runtime environment on IBM Cloud.

Low-code application development

Node-RED is an easy-to-use prototyping tool that serves as a web front end for the agent and a platform for any additional demo scenarios. Typically, Node-RED applications are configured by wiring-up input and process and output nodes in a flow, but coding (for example, JavaScript or Python) is possible as well.

Node-RED

The application is a parameterizable handler, and currently, two use cases are implemented:

  • Return the current time (if the user asks the chatbot for it)
  • Initiate the phone handover (the actual flow is not shown in the previous image) by calling Twilio and displaying information on the dashboard

In all other cases, an error message is returned. This is accomplished by using:

  • An HTTP in the node receiving GET requests with parameters
  • A switch node that, depending on the parameter request, routes the request to the appropriate subflow

Serverless computing

Because Watson Assistant currently only supports IBM Cloud Functions for programmatic calls, I used it just as a gateway between the Watson Assistant service and the Node-RED application. IBM Cloud Functions is the serverless service on IBM Cloud and is based on Apache OpenWhisk. The gateway code (in this case, using Node.js, but other languages are possible as well) is quite straightforward:

  1. Call the Node-RED endpoint defined in the params.
  2. Wait for completion of the Node-RED application.
  3. Return the result (or error) to Watson Assistant.

     var rp = require('request-promise');
     function main(params) {
         var uri = params.target_hostname + params.target_route + params.query_params;
         return new Promise(function (resolve, reject) {
            rp(uri)
            .then(function (parsedBody) {
                obj = JSON.parse(parsedBody);
                resolve({ "gw_result": obj });
            })
            .catch(function (err) {
                resolve({ message: 'Error!!', error: err.toString() });
            });
         });
       }
    

Summary

Watson Assistant can take advantage of external systems, sending and receiving data to and from these systems using the programmatic call interface. The flexible architecture of the solution allows for a simple expansion by adding new intents to Watson Assistant and logic to Node-RED. Node-RED is a tool for demos and prototypes, especially for people with limited coding experiences like myself. Finally, I learned a bit or two about serverless computing.

If you want to build the demo yourself, please go to the GitHub repo.

Peter Schleinitz

Previous Article
Tips for troubleshooting Kubernetes node resource issues
Tips for troubleshooting Kubernetes node resource issues

Site reliability engineers can use this advice for working in a cloud environment with Kubernetes.

Next Article
Build in-demand skills at IBM Z Day on November 21st
Build in-demand skills at IBM Z Day on November 21st

Advance your tech skills, explore case studies, network, and gain insights from industry experts at this fr...

×

Want our latest news? Subscribe to our blog!

Last Name
First Name
Thank you!
Error - something went wrong!