Remark: This repo is under contruction, feedback, questions, issues are welcome.

Handover from chatbot to phone call

A chatbot using the Watson Assistant services which continues the dialog via phone should the client prefer to talk to an agent.

Problem statement

While chatbots are widely used by companies to get information from clients, sometimes users stop the conversation for various reasons (duration of the dialog, unclear question). In those cases a handover to an agent helps continue the dialog.

Architecture

The Watson Assistant service is the basis of the chatbot: the Skill controls the dialog, the Assistant is used as an interface to Messenger. The solution leverages Node-RED as a prototyping platform, controlling the application and the web frontend.

Architecture

The Watson Assistant service can do programmatic calls to integrate with backend systems using IBM Cloud Functions. So I created a small gateway to call Node-RED from the Watson Assistant service.

Twilio is a developer platform for communications to add capabilities like voice, video, and messaging to applications. I used the standard clicktocall Node.js repo and integrated it into the solution.

Assumptions & Prereqs

  • Some experiences with IBM Cloud, Node-RED, and Watson Assistant is needed
  • Twilio account and paid virtual phone number
  • Free ngrok account, if you want to run and test the Twilio client locally (nice to have, but not necessary)
  • IBM Cloud account (consumption should be within the free lite plan) for a permanent deployment of the Twilio client

Use Case Description

Initially the client chats via Messenger with the Watson Assistant chatbot.

If she initiates a handover to an agent:

  • Twilio calls the phones of the client and the phone of an agent subequently,
  • The two start to talk,
  • The status of the preceding chatbot conversation is displayed on the Node-RED dashboard to the agent.

Installation Instructions

The following steps provide an overall overview what needs to be done. Some understanding of app development and IBM Cloud are required to follow along.

Twilio

Preparation

  • Get a Twilio account, note down your account SID.
  • Create a project.
  • A token is needed for authentication, which you can find under general settings. If prompted, enter the password again.
  • Verify two phone numbers that you want to call later. You could, for example use your landline (client) and cell number (agent).
  • Buy a virtual phone number, if you don't have one already.

Local Twilio Client

The Twilio Click To Call client is used to control the communication. It is available for several languages and we are using Node.js and the Express framework.

  • Clone this repository onto your laptop
  • Go to the Twilio client folder and install the dependencies
$ cd Twilio client click-to-call
$ npm install

You can also clone the original and more current version directly from the Twilio repository. See Click To Call with Node.js and Express for documentation

  • Start the Twilio client
$ export TWILIO_ACCOUNT_SID=youraccountsid
$ export TWILIO_AUTH_TOKEN=yourauthtoken
$ export TWILIO_NUMBER=yourvirtualtwilionumber
$ node app.js

The client is running but it needs to be accessible from the Twilio platform. So open another terminal windows and start the VPN tunnel, that exposes the local REST APIs on the web.

$ ./ngrok http 3000
  • Perform a test, go to https://your_address.ngrok.io:3000
  • Enter the verified phone numbers of the client and the agent localtest
  • The two phones should ring subsequently and there's also a voice message

Twilio client on IBM Cloud

  • Login into IBM Cloud from command line, use the organization/space you would like to push the Node.js to
  • Change the app name in manifest file manifest.yml and push the local app to the IBM Cloud (cf push)
  • set the environment variables TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN, TWILIO_NUMBER of the deployed app
  • Perform the test again, use the route to the app on IBM Cloud

Node-RED on IBM Cloud

  • Create a Node-RED instance and import node-red.json
  • Go to the Twilio flow Twilio Flow
  • Open the function node use test numbers and modify the numbers and the URL of the Twilio client
  • Open the Call Twilio Client on IBM Cloud node and modify the URL
  • Deploy the changes
  • Click on the test injection node, you should see a message from Twilio in the debug pane

IBM Cloud Functions

{
        "query_params": "?request=start_call&phoneNumber=%2B491725555555&vin=ABC&salesNumber=%2B493615555555",
        "target_route": "/wahandler",
        "target_hostname": "http://yournodereddomain.mybluemix.net"
}
  • Go to the Endpoints section and note the API key

Watson Assistant

You can now share the URL of the assistant or the Messenger bot name with your users.