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!
- See the instructions for setting up and configuring your Watson Conversation Service.
- Git clone this sample project
$ git clone git@github.com:kostickm/watsonbot.git
- Change to your the newly cloned repo
$ cd watsonbot/
-
Create a new Slack bot, you will be assigned a Slack API Token
-
Export your assigned Slack API Token
# Windows
$ set SLACK_BOT_TOKEN=<SLACK_BOT_TOKEN>
# macOS/Linux
$ export SLACK_BOT_TOKEN='<SLACK_BOT_TOKEN>'
- Install the
slackclient
python package
$ pip install slackclient
- Run the
print_bot_id.py
script
$ python print_bot_id.py
Bot ID for 'watsonbot' is <SLACK_BOT_ID>
-
Save both of these credentials for use later in this tutorial
-
Copy the
env.sample
file to a new file named.env
# Windows
$ copy env.sample .env
# macOS/Linux
$ cp env.sample .env
- 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>
- 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>
- 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
- 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'
)
- 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
.
You are now ready to deploy your application to Bluemix.
Note: You may also use the shorthand command bx
instead of bluemix
.
- Log into Bluemix CLI using your Bluemix credentials
$ bluemix api https://api.ng.bluemix.net
$ bluemix login
- From your local app directory deploy your app to Bluemix
$ bluemix app push
- Check that your app is running in Bluemix
- Test out your deployed app in Slack. Chat with your
watsonbot
by sending a Slack message starting with@watsonbot
.
- 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