IBM/watson-conversation-slots-intro

Name: watson-conversation-slots-intro

Owner: International Business Machines

Description: A Chatbot for ordering a pizza that demonstrates how using the IBM Watson Assistant Slots feature, one can fill out an order, form, or profile.

Created: 2017-07-12 00:40:42.0

Updated: 2018-05-14 19:36:19.0

Pushed: 2018-05-17 20:20:16.0

Homepage: https://developer.ibm.com/code/patterns/assemble-a-pizza-ordering-chatbot-dialog/

Size: 2359

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Build Status

Creating a Pizza ordering Chatbot using Watson Assistant Slots feature

Watson Conversation is now Watson Assistant. Although some images in this code pattern may show the service as Watson Conversation, the steps and processes will still work.

In this Code Pattern, we will use the Watson Assistant Slots feature to build a chatbot that takes a pizza order. The needed information such as size, type, and ingredient choices can all be entered within one Assistant Node, unlike with previous versions of Assistant.

When the reader has completed this Code Pattern, they will understand how to:

Flow
  1. User sends messages to the application (running locally or on IBM Cloud).
  2. The application sends the user message to IBM Watson Assistant service, and displays the ongoing chat in a web page.
  3. Watson Assistant uses the Slots feature to fill out the required fields for a pizza order, and sends requests for additional information back to the running application.
Included Components
Featured technologies

Watch the Video

Running this application with Cloud Foundry on IBM Cloud

Running this application in a container with Kubernetes on IBM Cloud

Steps

Deploy to IBM Cloud

Deploy to IBM Cloud

Click the Deploy to IBM Cloud button and hit Create and then jump to step 5.

OR

Run in container

Run in a container on IBM Cloud, using these instructions.

OR

Run locally

Perform steps 1-5:

  1. Clone the repo
  2. Create IBM Cloud services
  3. Get IBM Cloud credentials and add to .env
  4. Configure Watson Assistant
  5. Run the application
1. Clone the repo

Clone watson-conversation-slots-intro locally. In a terminal, run:

$ git clone https://github.com/ibm/watson-conversation-slots-intro

We?ll be using the file data/watson-pizzeria.json to upload the Assistant Intents, Entities, and Dialog Nodes.

2. Create IBM Cloud services

Create the following service and name it wcsi-conversation-service:

3. Get IBM Cloud service credentials and add to .env file

As you create the IBM Cloud services, you'll need to create service credentials and get the username and password:

Move the watson-conversation-slots-intro/env.example file to /.env and populate the service credentials as you create the credentials:

tson conversation
ERSATION_USERNAME=<add_conversation_username>
ERSATION_PASSWORD=<add_conversation_password>
SPACE_ID=<add_conversation_workspace>
4. Configure Watson Assistant

Launch the Watson Assistant tool. Use the import icon button on the right

Find the local version of data/watson-pizzeria.json and select Import. Find the Workspace ID by clicking on the context menu of the new workspace and select View details.

Put this Workspace ID into the .env file as `WORKSPACE_ID``.

5. Run the application
If you used the Deploy to IBM Cloud button…

If you used Deploy to IBM Cloud, the setup is automatic.

If you decided to run the app locally…
m install
m start

Assistant Slots Discussion

The power of Slots is in how it reduces the number of nodes required to implement logic in your Watson Assistant Dialog. Here's a partial conversation Dialog using the old method:

And here's a more complete Dialog using slots, which puts all the logic in one Node!

Open up the Dialog, and we'll have a look:

Each slot represents a field to be populated in the chatbot: pizza_size, pizza_type, and pizza_topings. If they are not present, the user will be prompted, starting at the top, until all are populated via the associated variable ($pizza_size, $pizza_type, etc).

Click on the Configure icon to add more functionality:

Here, we can add a response for when this slot is filled (Found). Logic can be used for one ingredient:

or if there are greater than one ingredient added:

We've added logic to address yes or no answers to the question “Any extra toppings?“:

Click on the 3 circles icon to edit the json directly:

Here, we've set an empty value for the context: {“pizza_topings”} field, so that we can exit the loop by filling this slot.

Finally, we add responses for once the slots are all filled:

We start with the case where we have “pizza_topings”, by detecting that the array has size>0. Here, we first handle the case where the optional “pizza_place” slot is filled, and then handle the case where it is not.

Finally, we add handlers for the cases where the users answers to a prompt is not found. We've handlers for the intents “help” and “reset”:

Note that we edit the json directly when we handle the Reset. We'll set all the fields to null in order to begin again.

Assistant Example

Let's look at an example conversation and the associated json. With your Watson Pizzeria running, start a dialog and begin with telling the Pizza Bot you want a large pizza:

The 'User Input' shows you the “input”{“text”} field, as well as come of the “context” that is mostly used for Assistant to keep track of internal state. Scroll Down to Watson Understands and look at intents:

Note that the intent for “order” is detected. The entity “pizza_size” is now a slot that is filled out. We still have 2 required slots, “pizza_type” and “pizza_toppings”. The user will be prompted until these are filled out:

We can now see that all required slots are filled:

What if we wanted to tell the Watson Pizzeria that we wanted to eat the pizza there, in the restaurant? Too late! the slot for “pizza_place” is optional, so the user won't be prompted for it, and once the required slots are filled, we exit the “Pizza Ordering” dialog node. The user needs to fill out optional slots first. Type reset to start again and test this by adding the phrase “to eat there…“:

Troubleshooting

FAILED Could not find service <Watson_service> to bind to <IBM_Cloud_application>

If you name your service wcsi-conversation-service, this should work. When you use cf push, it is trying to bind to the services listed in the manifest.yml.

So, there are 2 ways you can get this to work:

NOTE: The Deploy to IBM Cloud button solves this issue by creating the services on the fly (with the correct names).

License

Apache 2.0

Links

Learn more


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.