Following the instructions from this github repo. The below notes has instructions for event interaction mode. For socket mode, please refer to the main github repo’s READMEs. This integration deployment may be set up on any other hosting platform, these instructions will use Google’s App Engine. For cloud functions option, please refer to the main github repo’s READMEs.
-
Create a Slack app
- Create or Sign in to Slack
- Create a Slack app (app = bot)
- Adding scopes in “OAuth & Permissions” tab. Add
app_mentions:read, chat:write, im:history, im:read, im:write
- In the Slack API, go to the basic information for your app and install the app to your workspace.
- On installing the app to the workspace, you should be able to see a token in “OAuth & Permissions”. This is your
BOT_TOKEN.
- In “Basic information” section for the app, create an
APP_TOKEN under the “App-Level Tokens”.
- In Basic Information section for the app, click on
Show for Signing Secret. Copy and replace all token the values above in config/token.go file.
- On slack, go to the channel(s) you want the slack bot to have access to and invite the bot to the channel. Alternatively, you can type /invite on the channel
-
GCP setup
- Create a service account, fill in the details, and give it the “Dialogflow Client API” role.
- Create a key, download the resulting JSON key file.
- Save the JSON key file as
dialogflowcx.json inside the functions/config directory of the cloned repo (Notes: this is not recommended for production), else set the GOOGLE_APPLICATION_CREDENTIALS env variable on the deployment environment to the absolute path of Service Account JSON key file. If JSON key is saved inside the repo, then uncomment CREDENTIALS_PATH in the token.go file.
-
Create a dialogflow agent
- If you don’t already have a Dialogflow agent, you may create one or add a prebuilt agent.
-
Deploying via App Engine
- Clone this git repository onto your local machine or development environment: git clone [repository url]
- Open the root directory of the repository on your local machine or development environment. Changes in the app.yaml file
- If you have not done so already, copy (or export) your Service Account JSON key file to the desired subdirectory.
- Changes in token.go file. Open the token.go file and add all slack tokens as mentioned in the slack set up above. Also add the project id of your GCP project as well as the agent name in dialogflow. Important notes: To get the agent’s name, on dialogflow console, select the project, then you will see a console with a list of agents. Select the 3-dots button on the right of the agent, select “Copy name” from the dropdown list.
- Search and edit
dialogflowcx-handler.go
- Change region and language accordingly. Notes: these values should be parameterized.
- Deploying App Engine
- On the terminal, cd to the root directory of the cloned project and gcloud app deploy –project [project-id] This will deploy your project.
- To check the logs, gcloud app –project [project-id] logs tail -s default
- Record the url obtained from the deployment. This URL will be updated into slack’s event url. Request URL should get approved if the app was able to successfully respond back with the challenge parameter. This basically meant slack sent your URL some request, and you needed to respond with the challenge parameter, which you did!
-
Update the Slack app
- Enable event subscription. Go to the “event subscriptions” and enable events
app_mention, message.im. The event subscription will ensure slack sends the events when they occur to the link provided.
- The url to be entered is your dialogflow app’s url. Slack authorizes the link we provide, by sending a request with a challenge parameter and the app must respond with the challenge parameter. Plugin the url into the request url in interactivity and shortcuts tab in slack api. Ensure the bot events you need to subscribe to, are all selected. If not, then add and save them. Include app_mention and message.im
- Go to interactivity and shortcuts and enable interactivity. The url to be entered is your app’s url.
- Redeploy the app if needed
-
Important notes
- Make use of the Cloud Logging to debug
-
APPENDIX
- https://github.com/Sampriti-Mitra/dialogflow-slack-sdk