Develop a Virtual Assistant with IBM Watson and .NET Core on IBM Cloud Code Engine-Part 2

In the previous article (Part 1) we developed and published a basic website with .NET Core, Docker and IBM Cloud Code Engine. In this article I will explain how to build a basic virtual assistant with IBM Watson, integrate it with the website, publish the new image and deploy the new version to IBM Cloud Code Engine. At the end you will have a functional virtual assistant publicly available on the Internet almost with NO code.

Our virtual assistant will be able to assist a New Bank customer with the following:

  1. Report a lost or stolen card
  2. Provide the products and services the Bank offers
  3. Explain financial and banking terms
  4. Provide the account balance for a specific bank account

In this article we will solve the first two topics, in Part 3 we will incorporate search capabilities to explain financial and banking terms with Watson Discovery and in Part 4 we will implement a serverless function with .NET Core and deploy it to IBM Functions service.

In order to build the assistant and integrate it with the website we will execute the following steps:

  1. Provision an instance of Watson Assistant on IBM Cloud
  2. Build the virtual assistant with Dialog an Intents
  3. Integrate the Watson Assistant widget with the website
  4. Generate the new docker image and deploy it to IBM Cloud Code Engine

Login to IBM Cloud and select Watson Assistant from the Catalog

https://cloud.ibm.com/catalog/services/watson-assistant

Select the Plus Trial plan and click on Create to provision your instance

Watson Assistant Plus Trial plan

By now you should have an instance of Watson Assistant Plus Trial

Instance of Watson Assistant with Plus Trial plan

Click on Launch Watson Assistant to open the service console.

Watson Assistant — Assistants

The first screen is the Assistants screen where you will have all your assistants. Click on Create assistant to create your assistant for New Bank.

On the create assistant dialog enter the name for your assistant and click on Create assistant.

Watson Assistant has the concept of Skills for developing a virtual assistant. The most common used skill is the Dialog skill which allows to define a conversational workflow. The Search skills provides integration with Watson Discovery for search capabilities using Natural Language Processing (we will use a Search skill with Watson Discovery in Part 3). A new type of skill is the Actions skill (still in Beta) which provides a new approach for building virtual assistants with Watson.

For our scenario we will start with a basic assistant using the Dialog skill.

Watson Assistant skills

Click on Add dialog skill.

In the next screen enter the name of your dialog skill, in my case the name is newbankdialogskill. Here you can select the Language that you would like to use for your assistant. I will use English but you could use the language of your preference. Click on Create dialog skill

Add a dialog skill to your virtual assistant

At this point we have our Virtual Assistant with a Dialog skill created and we are ready for its implementation.

Virtual Assistant with a dialog skill

Click on newbankdialogskill

New Bank Virtual Assistant dialog skill

The dialog skill interface is open, and we are ready to work with the different concepts. The most important concepts in Watson Assistant are:

  1. Dialog — Controls the conversation flow with the user
  2. Intents — Intents are phrases the user may enter and will in turn expect a single action to be performed.
  3. Entities — Represent synonyms and patterns

As mentioned before, in this article the first version of the assistant will assist the bank customer to report a lost or stolen card and provide information about the bank products and services. We will create one intent for each of these questions. Let’s start with the intent for a lost or stolen card.

Click on Create Intent

Create #reportLostCard intent

Enter #reportLostCard as the name for the intent, an optional description and click on Create intent

Enter the following examples to the intent in order to train Watson Assistant.

Examples for lost card intent

Feel free to enter more user examples as Watson Assistant will use them for improving its intent accuracy

Create the second intent for the question about products and services. In my case I used #whatProductsAndServices

Click on Create intent and add the following examples

User examples for #whatProductsAndServices intent

Now we will configure the dialog which is the heart of the virtual assistant an orchestrates the conversation with the user.

Go back from the Intents screen to the main Dialog skill screen and click on Dialog on the left

New Bank dialog skill with two intents

On the Dialog screen click on the dots of the Welcome node and then click on Add Node Below

New Bank virtual assistant dialog

This new node will recognize the #reportLostCard intent. We need to populate the following fields:

· Name — Enter report a lost card

· Intent — Enter #reportLostCard

· Response — Enter Sorry to hear that. We will block your card immediately and issue a new card for you.

#reportLostCard dialog node

Now we need to add a second node below the report lost card node. Click on the dots of the report lost card node and click on add node below. Enter the following values:

· Name — New Bank Products and Services

· Intent — Enter #whatProductsAndServices

· Response — Thanks for your question. We offer personal credit cards from VISA, Mastercard and American Express, personal loans, mortgage loans and car loans.

#whatProductsAndServices dialog node

Now we are able to test our basic virtual assistant! Click on Try it! on the top right of the screen.

Test your virtual assistant

Enter “Cant find my card” and wait for the assistant response.

As you can see the assistant responds to our question and we did not enter a phrase that was used for training. Watson Assistant understood that our intent was #reportLostCard ! You can try the #whatProductsAndServices intent. Remember that you can train Watson Assistant iteratively entering additional phrases to the intent in order to obtain better accuracy.

Watson Assistant provides an out of the box integration widget. In order to obtain the integration script for the widget go back to main screen of the virtual assistant.

Under Integrations click on the Web chat icon on the right.

Web chat options

Click on the Embed tab to obtain the integration script.

Script to embed the assistant on the website

Copy the code provided on the screen.

In Visual Studio open the file _Layout.cshtml under the folder Views / Shared

_Layout.chstml

Paste the code copied from Watson Assistant before the <\head> as shown below.

Script code from Watson Assistant copied in _Layout.csthml

Build and test locally the website pressing F5 on Visual Studio.

Local test of the Web Chat

Click on the Watson Blue icon on the bottom right of the screen and test the assistant.

Website with integrated widget running locally

Voila! Our assistant is working on the website!

Now that our application is working we can generate a new docker image and deploy it to IBM Code Engine as explained on the first part of this series.

In order to generate the new docker image we need to delete the Publish folder in Visual Studio.

From Solution Explorer delete the Publish folder.

Publish folder

Open a Command Line window (cmd) and navigate to the root folder of the project where the Dockerfile resides

Execute the following command to create the publish folder with the updated artifacts (as in Part 1)

dotnet publish -o ./publish

We are ready to create and publish the new image (v2) for our virtual assistant executing the following commands.

docker build -t username/newbankvirtualassistant:v2 .

docker push -t username/newbankvirtualassistant:v2

Our new image (v2) has been published to Dockerhub.

Verify that your image has been published to your repositories in Dockerhub.

The final step is to deploy the application with the updated image on IBM Cloud Code Engine.

Navigate to IBM Cloud Code Engine at https://cloud.ibm.com/codeengine/overview

Create your project as explained in Part 1 and deploy your application pointing to the updated image (v2) — docker.io/username/newbankvirtualassistant:v2

Deploy application image to IBM Cloud Code Engine

Remember that you can configure your runtime settings in the IBM Cloud Code Engine interface.

Runtime settings for application running on IBM Cloud Code Engine

Enter a name for your application and click on Deploy. After a few seconds the application Url link will be available to test the published application.

IBM Code Engine Application URL

Click on Application URL and the internet facing application with the Virtual Assistant will pop up and it is ready to go on IBM Cloud!

Published website with Watson Virtual Assistant

So far we have developed and deployed a virtual assistant with cloud native technologies including Docker and Kubernetes without code. Very impressive (at least for me :) )

In Part 3 we will include Search capabilities to our assistant using natural language with IBM Watson Discovery. Again with NO code at all.

Enjoy!

Software Solutions Architect with focus on Cloud and AI technologies