/watsonbot

Watson Conversation Slack Bot

Primary LanguagePythonApache License 2.0Apache-2.0

watsonbot

Watson Conversation Slack Bot

Get started with the Watson Conversation Service by creating your very own Slack Chat Bot. This demo will walk you through all of the necessary steps to configure your Watson Conversation service, set up your Slack bot, and deploy your application to Bluemix. You will be chatting with Watson in no time!

Prerequistes

Python

Slack

Bluemix

Git

Steps

Set up the Watson Conversation Service

  1. See the instructions for setting up and configuring your Watson Conversation Service.

Clone project and update for your Slack bot

  1. Git clone this sample project

$ git clone git@github.com:kostickm/watsonbot.git

  1. Change to your the newly cloned repo

$ cd watsonbot/

  1. Create a new Slack bot, you will be assigned a Slack API Token

  2. Export your assigned Slack API Token

# Windows
$    set SLACK_BOT_TOKEN=<SLACK_BOT_TOKEN>

# macOS/Linux
$    export SLACK_BOT_TOKEN='<SLACK_BOT_TOKEN>'
  1. Install the slackclient python package
$    pip install slackclient
  1. Run the print_bot_id.py script
$    python print_bot_id.py
Bot ID for 'watsonbot' is <SLACK_BOT_ID>
  1. Save both of these credentials for use later in this tutorial

  2. Copy the env.sample file to a new file named .env

# Windows
$    copy env.sample .env

# macOS/Linux
$    cp env.sample .env
  1. Open and update the .env. file with your Slack credentials
# Slack
SLACK_BOT_TOKEN=<add_slack_bot_token>
SLACK_BOT_ID=<add_slack_bot_id>
  1. Open and update the .env. file with your Watson Conversation credentials
# Watson conversation
CONVERSATION_USERNAME=<add_conversation_username>
CONVERSATION_PASSWORD=<add_conversation_password>
WORKSPACE_ID=<add_conversation_workspace>
  1. Open the manifest.yml file and replace <Your-App-Name> with the unique name of your app
---
applications:
 - name: <Your-App-Name>
   domain: mybluemix.net
   memory: 128M
   health-check-type: none
   buildpack: https://github.com/cloudfoundry/buildpack-python.git
  1. Open the setup.py file and replace <Your-App-Name>with the unique name of your app
# Always prefer setuptools over distutils
from setuptools import setup

long_description = ('This is a sample Watson Conversation Slack chat bot.')

setup(
    name='<Your-App-Name>',
    version='1.0.0',
    description='Watson Slack Chat Bot',
    long_description=long_description,
    license='Apache-2.0'
)
  1. Optional: Run locally to test

Note: Make sure to set/export all environment variables located in the .env file before running locally. Also pip install all python packages listed in the requirements.txt file.

$ python watsonbot.py

Chat with your watsonbot by sending a Slack message starting with @watsonbot.

Deploy to Bluemix

You are now ready to deploy your application to Bluemix.

Note: You may also use the shorthand command bx instead of bluemix.

  1. Log into Bluemix CLI using your Bluemix credentials

$ bluemix api https://api.ng.bluemix.net

$ bluemix login

  1. From your local app directory deploy your app to Bluemix

$ bluemix app push

Chat with Watson

  1. Check that your app is running in Bluemix

  1. Test out your deployed app in Slack. Chat with your watsonbot by sending a Slack message starting with @watsonbot.

Next Steps

  • Check out the other Watson Python SDK examples
    • Add in the Watson Language Translation service
    • Add in the Watson Tone Analyzer service
  • Incorporate an API (Weather, Calendar, Github, etc.)
  • Have Watson tell you a joke