Perefin / watson-online-store

Code for Cognitive Developer Journey that uses Watson Conversation and Watson Discovery. This application demonstrates a simple abstraction of a chatbot interacting with a Cloudant NoSQL database, with a Slack UI.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build Status

Creating a Retail Chatbot using Watson Conversation, Discovery and Database Services

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

Flow

Included Components

  • Bluemix Watson Conversation
  • Bluemix Watson Discovery
  • Bluemix Cloudant NoSQL DB
  • Slack
  • Python

Steps

Perform steps 1-6 or choose the Deploy to Bluemix button and jump to step 5.

Deploy to Bluemix

  1. Clone the repo
  2. Create Bluemix services
  3. Configure Watson Conversation
  4. Configure Watson Discovery
  5. Configure Slack
  6. Run the application

1. Clone the repo

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/

2. Create Bluemix services

Create the following services:

  • Watson Conversation
  • Watson Discovery
  • Cloudant NoSQL DB

3. Configure Watson Conversation

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 selecting 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:

4. Configure Watson Discovery

Launch the Watson Conversation 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 configuration_id.

5. Configure Slack

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.

6. Run the application

Copy the env.sample to .env, edit it with the necessary IDs and run the application.

$ cp env.sample .env
$ # edit .env
$ python run.py

Sample output

Start a conversation with your bot:

Add an item to your cart:

Troubleshooting

  • Sample .env to use:
  # Watson conversation
  CONVERSATION_USERNAME=e6ca86f1-302a-4803-b408-7949c7abaa1a
  CONVERSATION_PASSWORD=PQ6fjelpPyPx
  WORKSPACE_ID=19849a01-19e4-47ad-bg3f-6cafe376aeed

  # Cloudant DB
  CLOUDANT_USERNAME="715ac810-921f-4290-92fc-061642ee4b3a-bluemix"
  CLOUDANT_PASSWORD="25fdf0c1411d2584b693c9f8aeda9b260b23656ec32c0da0839ed1cf7c2bd594"
  CLOUDANT_DB_NAME="cloudant_online_store"
  CLOUDANT_URL="https://715ac810-921f-4290-92fc-061642ee4b3a-bluemix.cloudant.com"

  # Watson Discovery
  DISCOVERY_USERNAME=03c25743-4728-448e-b3ed-3b198e6edd65
  DISCOVERY_PASSWORD=4LDhpX27q7QZ
  DISCOVERY_ENVIRONMENT_ID=a2e0e223-aec9-458e-95b5-d4d618e1ae6d
  DISCOVERY_COLLECTION_ID=d06e9ddf-7c27-4dce-b80f-dca8768a72d8

  # Slack
  SLACK_BOT_TOKEN=xoxb-cbe837f60865-bjgftpFM6tnJXTvZzIw8Ihui
  SLACK_BOT_NAME=hal

License

Apache 2.0

About

Code for Cognitive Developer Journey that uses Watson Conversation and Watson Discovery. This application demonstrates a simple abstraction of a chatbot interacting with a Cloudant NoSQL database, with a Slack UI.

License:Apache License 2.0


Languages

Language:Python 100.0%