Let the most excellent Keanu Reeves improve your Slack conversations.
The bot consists of three parts:
A Google Cloud Function that Slack calls whenever a given slack event occurs (e.g. message posted to chat). This function then invokes Dialogflow to do Natural Language Processing.
Dialogflow takes raw text and converts it into intents, actions, and entities. It can either respond directly with messages, or hand off to a fulfillment webhook for additional processing.
After Dialogflow has validated and converted a chat message into explicit actions and entities, it can call an HTTP webhook (Google Cloud Function) so we we can apply our business logic to those entities. This generates a response and sends it back to Dialogflow, which in turn calls the original Cloud Function to post a message to Slack.
-
Create a Slack App and install it on your team.
-
Create a Google Cloud Platform project.
-
Clone this repository to your local workstation:
$ git clone https://github.com/bretmcg/keanubot
-
Using your Slack and Dialogflow credentials, copy
dot.env.sample
to.env
using$ cp functions/dot.env.sample functions/.env
and add the API key correct values.Name Description APIAI_TOKEN
The Dialogflow client access token SLACK_BOT_TOKEN
The Slack Bot OAuth token. Slack Developers Console > OAuth & Permissions > Bot User OAuth Access Token SLACK_VERIFICATION_TOKEN
The Slack verification token. Slack Developer's Console > Basic Information > Verification Token -
Install the gcloud command line tool to manage your Google Cloud Platform project.
-
Deploy the event notification function
keanubot
to Cloud Functions:
cd functions/
gcloud beta functions deploy keanubot --trigger-http
- Add the
keanubot
function URL to the Slack event subscription page. It should be in the formathttps://REGION-PROJECT.cloudfunctions.net/keanubot
. - Deploy the Dialogflow fulfillment webhook.
gcloud beta functions deploy apiaifulfillment --stage-bucket <YOUR_CLOUD_STORAGE_BUCKET> --trigger-http
-
Add the
apiaifulfillment
function URL to the Dialogflow Fulfillment page, and make sure Webhook is Enabled.
$ cd functions/
$ npm install
- Add security token values to
.env
as before. $ node server.js
- In a new terminal window:
- Download ngrok and unzip into the
functions/
directory. - From
functions/
run$ ngrok http 3005
- Download ngrok and unzip into the
- Slack event subscription: add the local
keanubot
URL to the Slack app page. It should be in the formathttps://2f75d6e9.ngrok.io/keanubot
. - Dialogflow fulfillment URL: Add the local
apiaifulfillment
URL to the Dialogflow Fulfillment page, and make sure Webhook is Enabled. The URL should be in the formathttps://2f75d6e9.ngrok.io/apiaifulfillment