Remark: This repo is under contruction, feedback, questions, issues are welcome.
A chatbot using the Watson Assistant services which continues the dialog via phone should the client prefer to talk to an agent.
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.
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.
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.
- 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
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.
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.
- 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.
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
- The two phones should ring subsequently and there's also a voice message
- 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
- Create a Node-RED instance and import node-red.json
- Go to the 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
- Create an IBM Cloud Functions Node.js action using gateway.js, also Getting Started
- The connection to Node-RED can be tested by entering parameters (Change Input button) and starting the action (Invoke button)
{
"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
- Create a Watson Assistant Service, see also the Getting Started Guide
- Create a new skill by importing JSON skill file https://github.com/gitjps/chatbot_phone_handover/blob/master/skill-claim.json
- Go to the dialog and adapt the following nodes
- yes, call agent (URL, phone numbers)
- welcome (API key)
- current time (URL)
- claim damage (API key)
- Test Use the Try Out button
- Create an assistant for web browser (test environment) and Messenger
You can now share the URL of the assistant or the Messenger bot name with your users.