Building chatbots and virtual assistants continues to be extremely popular as users demand more functionality and better service around the clock. Watson Conversation offers an intuitive interface for developers and business experts to build interactive chatbots. With Watson Conversation, you can build your chatbot once and then deploy across multiple channels (web app, mobile app, call center, etc.) and platforms (Twitter, Facebook, Slack, etc.) to provide a consistent and engaging end-user experience.

Note that the main mission of a chatbot is to understand what the user is saying through natural language processing and collect enough information to take action and execute some functionality. To do so with Watson Conversation, you define a workspace which consists of intents (what does the user mean), entities (terms that provide specific information), and a dialog flow to orchestrate the interaction with the user based on intents, entities, and context.

It is important to understand that in addition to your Conversation service, you need to develop an application which integrates with your Conversation workspace to control the interaction with the users. Once the chatbot collects enough information from the user, it delivers such knowledge to the application which then executes some action. The action could simply be looking up an answer from a database or it could be more complicated and involves a physical action such as turning on the radio in the car. Furthermore, the flow of information between the application and the Conversation service is bi-directional and it is orchestrated through context variables. Effectively, the conversation service can send information to the application via context variables and the application can send information to the conversation service via context variables.

IBM Announces New and Advanced Watson APIs on the Cloud

 

In this blog, we show how you can integrate Watson Conversation service with another Watson service, namely Natural Language Understanding (NLU), to extract entities of interest. In some scenarios, it makes sense to define the entities of interest in your Conversation workspace; for example, when defining a “toppings” entity for a pizza ordering bot. However, in other scenarios, it is impractical to define all possible variations for an entity and it is best to rely on a service to extract the entity; for example, when extracting a “city” entity for a weather bot. We also illustrate how to integrate the information from Conversation service with a 3rd party API, namely the Weather Underground API, to look up the weather in a specific location of interest.

This section describes the commands and steps you need to execute to get the application up and running with Natural Language Understanding (NLU), Conversation, and Weather Underground API services. If you’d like more details, please follow the full tutorial and details.

Local Setup

This section describes how to set up your local space and clone a github repository into your local space. You will need a Bluemix account (free 30-day trial), IBM’s platform as a service offering, to provision Watson services. To run locally, you need the following:

 

Open a terminal window on your laptop and execute the following commands:

1.)  Download and install git

2.)  Download and install Cloud Foundry CLI

3.)  mkdir tlelab_workdir

4.)  cd tlelab_workdir

5.)  git clone https://github.com/joe4k/conversation-nlu.git

6.)  cd conversation-nlu

7.)  npm install => installs node packages defined in package.json

8.)  cp .env.example .env => we define service credentials in .env file

9.)  edit .env file and copy/paste the credentials for NLU, Conversation and Weather services (you will create these next).

Provisioning Watson Services

Please note that you need to provide unique names for the provision services. So if you get an error when executing the commands below, it could be because the name is not unique. To create Natural Language Understanding (NLU) and Conversation service credentials, on your terminal window, execute the following:

10.)  cf login -> connects you to your bluemix account

API endpoint: https://api.ng.bluemix.net

username:    your_bluemix_username

password:    your_bluemix_password

11.)  cf create-service conversation free tlelab-conv-service

-> create conversation using free plan and call it tlelab-conv-service

12.)  cf create-service-key tlelab-conv-service svcKey

13.)  cf service-key tlelab-conv-service svcKey

-> returns username and password credentials for conversation service

14.)  Copy the Conversation username and password to the .env file

CONVERSATION_USERNAME=username

CONVERSATION_PASSWORD=password

15.)  cf create-service natural-language-understanding free tlelab-nlu-service

-> create NLU service using free plan and call it tlelab-nlu-service

16.)  cf create-service-key tlelab-nlu-service svcKey

17.)  cf service-key tlelab-nlu-service svcKey

-> returns username and password credentials for NLU service

18.)  Copy NLU username and password to the .env file

NATURAL_LANGUAGE_UNDERSTANDING_USERNAME=username

NATURAL_LANGUAGE_UNDERSTANDING_PASSWORD =password

Weather Underground API

To get the weather, we will rely on the Weather Underground API. To use the weather underground api, you need to sign up for an apikey. Once you get the key, edit .env file and copy the weather api key to .env file.

WEATHER_API_KEY=weatherapikey

Integrating your Application with Conversation Workspace

The last piece of information we need is the WORKSPACE_ID. To get this, we need to create a workspace in our conversation service and build a conversation which involves defining intents, entities and building a dialog to orchestrate the interaction with the user. To do so:

  • Point your browser to http://bluemix.net
  • Login with your Bluemix credentials
  • Find your conversation service with the name tlelab-conv-service. Click to open the page for that service.
  • Find the Launch button and click it to launch the tooling for the conversation service.
  • Click Import to import a json file which defines the conversation workspace.

-> Choose file tlelab/conversation-nlu/training/car_workspace_nlu.json

  • This imports intents, entities, and the dialog for this conversation into a workspace called NLU_Car_Dashboard.

->Browse the various intents and entities as well as the dialog flow to get a better understanding of how these are defined.

  • Click on top left menu and navigate to “Back to workspaces”

-> this shows all the workspace tiles. In your case, you would only have 1 workspace titled NLU_Car_Dashboard

  • Click the Actions menu (top right of workspace tile)   to View details
  • Copy Workspace ID, edit .env file and add workspace id

WORKSPACE_ID=workspaceID

Running Application Locally

Now you’re ready to run the application. On the terminal command line, execute this command:

node server.js

Point your browser to http://localhost:3000

Experiment with conversation application

-> Ask things like: “What is the weather in Austin, TX”

Deploying Application to Bluemix

To push your application to Bluemix:

edit manifest.yml and change name to a unique name (tlelab-conv-jk)

cf push

point your browser to http://tlelab-conv-nlu-jk.mybluemix.net

Experiment with conversation application

-> Ask things like: “What is the weather in Austin, TX”

Conclusion

When designing your chatbot solution, Watson Conversation offers an intuitive and powerful interface for defining intents, entities and a dialog flow to control interaction with end-users. In your application, it is easy to integrate Watson Conversation with other services such as Watson Natural Language Understanding to extract entities in a more efficient and scalable manner. It is also seamless to integrate with 3rd party services such as Weather Underground API to execute an action such as looking up the weather forecast in a location of interest to the user.

 

Learn more about chatbots with Joe Kozhaya

Join The Discussion

Your email address will not be published. Required fields are marked *