ACME WhatsApp Banking — IBM Watson & Amazon AWS

Victor Paulo
5 min readAug 29, 2019

--

This post is related to ACME WhatsApp banking, if you didn’t read the initial part, please click here to start from the beginning.

As part of the WhatsApp Banking we decided to add some IBM Watson features such as IBM Watson Assistant and Text-to-Speech. The first one is aimed to help the conversation between the customer and the virtual manager chatbot whereas the second one is to translate the response from the chatbot translated to voice.

To get started we need:

  1. Create an account on IBM Cloud console (aka.: Bluemix)
  2. Spinning-up IBM Watson Assistant and Speech-to-Text
  3. Getting and saving the credentials
  4. Developing the Chatbot
  5. Installing Watson SDK for Node.js
  6. Creating the code (putting all together)
  7. Amazon AWS S3 Configuration

Create an account on IBM Cloud

In order to create an account please go to IBM Cloud console here.

Spinning-up IBM Watson Assistant and Speech-to-Text

Go to the menu and select Watson and then services. After that, select the service as shown below and provision them one-by-one. There is a Lite plan which is free, up to 10.000 messages for Assistant and 10.000 characters for Text-to-Speech service per month.

IBM Watson services

Getting and saving the credentials

You need to extract the API credentials from the console and import them in a .env file for the Watson application we are going to develop.

  • IBM Watson Assistant API
API key IBM Watson Assistant

Unlike Text-to-Speech API, the Assistant API needs two more information: Assistant ID and Workspace ID.

  • IBM Watson Text-to-Speech
  • Creating .env to store the credentials for Node.js application
.env file with the API credentials for Node.js

The .env content should be moved from .env file into kubernetes secret to avoid the information be exposed when creating and publishing the docker image.

Developing the Chatbot

  • Creating the Watson Assistant Dialog

IBM Assistant interface shown below is where you create your conversation dialogs sequence and how it should be performed. You can also enrich your dialog text with the response from an external API call. In the example below, for the New Mortgage Customer dialog, I am calling the products microservice to retrieve the list of mortgage products when the customer type intention for it.

In order to call an external API, we need to configure the webhook URL and we need to expose our microservice to the internet as HTTP(s) using POST method.

Here the communication flow is from IBM Watson Assistant to our GKE cluster.

IBM Watson Assistant — Webhook configuration
IBM Watson Assistant — Dialog creation

The following code is a node.js application to retrieve product information to enrich the chatbot information. The products are retrieved from MongoDB.

ACME Product Microservices
  • Installing Watson SDK for Node.js

Watson SDK for Node.js can be installed via npm package manager utility as stated below.

$ npm install ibm-watson --save

The IBM Watson Assistant and Twilio WhatsApp integration code

The following code outlines how to integrate IBM Watson Assistant with Twilio WhatsApp sandbox.

Calling IBM Watson Assistant from WhatsApp

Here the communication flow is from GKE cluster to IBM Watson Assistant, IBM Text-to-Speech and Twilio.

Adding up IBM Watson Text-to-Speech in the solution

I decided to add a new feature on our ACME WhatsApp banking where the user can type a text beginning with a special character to indicate that he/she wants the response as audio instead of plain text.

Challenge:

The Twilio API expects a URL to send the audio to the WhatsApp UI, so we need to get the audio stream from the response of text-to-speech API and store it somewhere. I decided to use AWS S3 to store the Audio file and get the required URL.

IBM Text-to-Speech API

Amazon AWS

This section outlines how I create a code to store the audio response from IBM Watson Text-to-Speech API on AWS S3.

Amazon AWS S3 Configuration

On AWS cloud, I am using S3 Object Store to store the audio from IBM Watson text-to-speech API.

To get started on AWS S3, you just need to create a user on AWS console and then create a bucket which is a repository where you can store any kind of file including web applications if you want.

S3 Bucket on AWS

It's important to create a user and grant access to it to upload files using the S3 API.

Audio files generated by Text-to-Speech API stored on S3

Creating your component library for AWS S3

I created a small node.js library to hide the logic to S3 by exposing it as promise for asynchronous calls.

$ npm install aws-sdk --save
AWS S3 library
  • Creating .env to store the credentials for AWS library
The .env file with AWS credentials

This is the end of our journey, I hope you have enjoyed this post series where I’ve shown how to design and implement a fictitious ACME WhatsApp Banking, please let me know your thoughts so that we can learn together.

--

--

Victor Paulo

“We are what we repeatedly do. Excellence then, is not an act but a habit.” — Aristotle