In this developer journey we will create a Watson Conversation based chatbot that allows a user to: 1) find items to purchase using Watson Discovery, and 2) add and remove items from their cart by updating a Cloudant NoSQL Database.
When the reader has completed this journey, they will understand how to:
- Create a chatbot dialog with Watson Conversation
- Dynamically store and update a Cloudant NoSQL database based on chatbot results
- Seed data into Watson Discovery and leverage its natural language capabilities
- Manage and customize a Slack group to add a chatbot
Want to take your Watson app to the next level? Looking to leverage Watson Brand assets? Join the With Watson program which provides exclusive brand, marketing, and tech resources to amplify and accelerate your Watson embedded commercial solution.
- Bluemix Watson Conversation
- Bluemix Watson Discovery
- Bluemix Cloudant NoSQL DB
- Slack
- Python
NOTE: Perform steps 1-6 OR click the Deploy to Bluemix
button and hit Create
and then jump to step 5.
There is no web UI (only Slack), so don't use the
View app
button to see the app. Use the Bluemix dashboard to find and manage the app. Use your Slack UI to chat.
- Clone the repo
- Create Bluemix services
- Configure Watson Conversation
- Configure Watson Discovery
- Configure Slack
- Run the application
Clone the watson-online-store
locally. In a terminal, run:
$ git clone https://github.com/ibm/watson-online-store
We’ll be using the file data/workspace.json
and the folder
data/ibm_store_html/
Create the following services:
Launch the Watson Conversation tool. Use the import icon button on the right
Find the local version of data/workspace.json
and select
Import. Find the Workspace ID by clicking on the context menu of the new
workspace and select View details. Save this ID for later.
Optionally, to view the conversation dialog select the workspace and choose the Dialog tab, here's a snippet of the dialog:
Launch the Watson Discovery tool. Create a new data collection and give the data collection a unique name.
Seed the content by selecting Add data to this collection in the dialog,
choose the HTML files under data/ibm_store_html/
. When
completed, save the environment_id and collection_id.
Create a slack group or use an existing one if you
have sufficient authorization. (Refer to Slack's how-to
on creating new groups.) To add a new bot, go to the Slack group’s application settings
by navigating to https://<slack_group>.slack.com/apps/manage
and selecting the
Custom Integrations menu on the left.
Give the bot a fun name. Once created save the API Token that is generated
Run /invite <botame>
in a channel to invite the bot, or message it directly.
If you used Deploy to Bluemix
, most of the setup is automatic, but not
quite all of it. We have to update a few environment variables.
In the Bluemix dashboard find the App that was created. Click on Runtime
on the menu and navigate to the Environment variables
tab.
Update the three environment variables:
- Set
SLACK_BOT_TOKEN
to the token you saved in Step 5 - Set
SLACK_BOT_USER
to the name of your bot - It's probably OK to leave
CLOUDANT_DB_NAME
set towatson-online-store
Save the new values and restart the application, watch the logs for errors.
Copy the env.sample
to .env
, edit it with the necessary IDs
and run the application.
The USERNAME
, PASSWORD
, and URL
settings for each service can be obtained
from the Service Credentials
tab in BlueMix. The other settings were collected
during the earlier setup steps.
$ cp env.sample .env
### edit .env
$ python run.py
Start a conversation with your bot:
Add an item to your cart:
- Help! I'm seeing errors in my log
This is expected during the first run. The app tries to start before the Discovery service is fully created. Allow a minute or two to pass, the following message should appear:
Watson Online Store bot is connected and running!
- Setting environment variables for a local run
NOTE: This only needs to be set if the application is running locally.
The credentials for Bluemix services (Conversation, Cloudant, and Discovery), can
be found in the Services
menu in Bluemix, and selecting the Service Credentials
option.
# Watson conversation
CONVERSATION_USERNAME=<add_conversation_username>
CONVERSATION_PASSWORD=<add_conversation_password>
WORKSPACE_ID=<add_conversation_workspace>
# Cloudant DB
CLOUDANT_USERNAME=<add_cloudant_username>
CLOUDANT_PASSWORD=<add_cloudant_password>
CLOUDANT_DB_NAME=watson_online_store
CLOUDANT_URL=<add_cloudant_url>
# Watson Discovery
DISCOVERY_USERNAME=<add_discovery_username>
DISCOVERY_PASSWORD=<add_discovery_password>
DISCOVERY_ENVIRONMENT_ID=<add_discovery_environment>
DISCOVERY_COLLECTION_ID=<add_discovery_collection>
# Slack
SLACK_BOT_TOKEN=<add_slack_bot_token>
SLACK_BOT_USER=wos
If using the Deploy to Bluemix button some metrics are tracked, the following information is sent to a Deployment Tracker service on each deployment:
- Python package version
- Python repository URL
- Application Name (application_name)
- Application GUID (application_id)
- Application instance index number (instance_index)
- Space ID (space_id)
- Application Version (application_version)
- Application URIs (application_uris)
- Labels of bound services
- Number of instances for each bound service and associated plan information
This data is collected from the setup.py file in the sample application and the VCAP_APPLICATION
and VCAP_SERVICES
environment variables in IBM Bluemix and other Cloud Foundry platforms. This
data is used by IBM to track metrics around deployments of sample applications to IBM Bluemix to
measure the usefulness of our examples, so that we can continuously improve the content we offer
to you. Only deployments of sample applications that include code to ping the Deployment Tracker
service will be tracked.
To disable tracking, simply remove cf_deployment_tracker.track()
from the
run.py
file in the top level directory.