Think 2021: New tools have the developer ecosystem and IBM building together Learn more

IBM Developer Blog

Follow the latest happenings with IBM Developer and stay in the know.

Learn about a demo that transfers a chatbot conversation to a human when questions are ambiguous or difficult to answer.

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.


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.


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": ""
        "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.


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) {
            .then(function (parsedBody) {
                obj = JSON.parse(parsedBody);
                resolve({ "gw_result": obj });
            .catch(function (err) {
                resolve({ message: 'Error!!', error: err.toString() });


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.