In this code pattern, we will create a Slack app using Python, Docker, Kubernetes on IBM Cloud, and TRIRIGA Assistant. The code provided will guide you in adding a Slack app to your Slack Workspace that will allow your TRIRIGA users to perform Workplace Service functionality through Slack utilizing the Watson Assistant add-on to TRIRIGA.
When you have completed this code pattern, you will understand more about:
- Defining a Slack app
- Deploying applications in Kubernetes
- Provisioning a TRIRIGA Assistant
- Capabilities of the TRIRIGA Assistant
The following are required to use this software:
-
An IBM TRIRIGA instance that is accessible via the internet
-
Importing and performing setup steps for TRIRIGA Assistant which includes provisioning of TRIRIGA Assistant Services by the IBM AI Applications - TRIRIGA Voice Enablement team.
-
Access to a Slack workspace with privileges to create Slack applications.
-
Docker for deploying in Kubernetes Service: Windows, Mac, Getting Started
-
ngrok for local testing
-
An IBM Cloud account
Tririga-Bot has a handful of environment variables that need to be set.
First, copy the sample.env
file to .env
.
Edit the .env
file and provide the following information:
PORT
- the port the application will respond to.API_KEY
- a key needed to prevent unwanted access to this app. This can be anything you wish.
To complete the Slack Settings you need to create a slack app using Slack UI at https://api.slack.com/apps
. You also may have to Request to Install
the app before you change the settings below.
BOT_NAME
is the name you gave your bot in slackSLACK_WEBHOOK_SECRET
is the verification token slack sends with every request to your botSLACK_BOT_USER_TOKEN
is the OAuth token for your bot to use to access slackOAuth & Permissions
Scopes
add the followingBot Token Scopes
- 'app_mentions:read'
- 'channels:history'
- 'chat:write'
- 'chat:write.customize'
- 'im:history'
- 'im:read'
- 'im:write'
- 'reactions:read'
- 'users:read'
Event Subscriptions
Enable Events
should be ONRequest URL
should be '<URL to bot>/slack' (when running locally, this will be thehttps://xxx.ngrok.io/slack
URL. See NGROK section below.)Subscribe to Bot Events
add the following events- 'message.channels'
- 'message.im'
Interactive Components
Interactivity
should be ONRequest URL
should be '<URL to bot>/slack/handle_action'
TA_INTEGRATION_ID
- the Integration ID provided by the IBM AI Applications - TRIRIGA Voice Enablement Team.
Optionally, you can connect this slackbot to a Watson Assistant created in your own Watson Assistant Service. The following information can be found on the Assistant's Settings page after creating the Assistant in your Watson Assistant Service. Note, without a Skill provided by the IBM AI Applications - TRIRIGA Voice Enablement Team, connecting the Slackbot to Watson Assistant will not access data in TRIRIGA.
WA_IAM_KEY
- The Service Credentials Api Key.WA_ASSISTANT_ID
- The Assistant ID.
$ ngrok http 8080
$ docker build .
$ docker run --env-file .env -p 8080:8080 YOUR_BUILD_ID_HERE
Direct Message the bot with hi
to start a conversation.
Prerequisites: IBM Cloud CLI
$ ibmcloud cf push my-tririga-bot -f manifest.yml
$ ibmcloud cf app my-tririga-bot
The Deploy to IBM Cloud Kubernetes Service Getting Started Guide should be very helpful in this process as well as IBM Cloud Kubernetes Overview.
1. Push the Docker image to IBM Cloud Registry (ICR) by tagging the Docker build and pushing to ICR. Replace us.icr.io
with the container registry domain in your region.
$ ibmcloud cr namespace-add tririga-bot
$ docker tag YOUR_BUILD_ID_HERE us.icr.io/tririga-bot/my-tririga-bot:1
$ docker push us.icr.io/tririga-bot/my-tririga-bot:1
$ ibmcloud ks cluster create classic --name my-tririga-bot
$ ibmcloud ks cluster config --cluster my-tririga-bot
3. Copy yaml/sample.deployment.yml
to deployment.yml
and provide values as in .env
file as well as registry domain.
$ kubectl create -f deployment.yml
$ kubectl get pods
$ kubectl describe pod my-tririga-bot
If having trouble getting Kubernetes to pull the image, see this help document on Image Pull Secrets
$ kubectl expose deployment my-tririga-bot --type NodePort --port 8080 --target-port 8080
$ kubectl describe service my-tririga-bot
$ ibmcloud ks workers --cluster my-tririga-bot
http://<Public-IP>:<NodePort>/slack
http://<Public-IP>:<NodePort>/slack/handle_action
Here's an example of the type of discussion you can have with the assistant through slack.
- IBMCloud - Service provider and application hosting environment
- Watson Assistant - NLU service for understanding user intent and other bot inputs.
- Slack Apps - The API and framework for communicating to and from Slack
- IBM TRIRIGA - Facility management software solution by IBM
We use SemVer for versioning. For the versions available, see the tags on this repository.
This project is licensed under the MIT License - see the LICENSE file for details