Jordy is my best friends. This is my an experiment to create a Slack bot. The Slack API provides fully features and heavily documented, which means it can be easy to get confused to getting start to trap the message event from Slack or push message to Slack Webhook.
In the repository, I implement Slack bot application with the Slack Node.js SDK and Express for HTTP Framework.
- Create new app https://api.slack.com/apps?new_app=1.
- Click "Add features and functionality > Bots" for choosing the features and configure your bot.
- Grant oAuth for
bot
permission. - Copy token from OAuth & Permissions menu.
You can configure your bot profile in Basic Information.
https://slack.dev/node-slack-sdk/tutorials/local-development
Usecase: Create BOT to listening workspace events
Your bot can subscribe all or specific of event in Slack such as new message in your channels.
- Start your node server. I am running using port
:3000
for the example. - Start
ngrok http 3000
I using ngrok for expose my node application to publicly accessible URL. This is how to setup https://api.slack.com/tutorials/tunneling-with-ngrok. - Go to Event Subscriptions menu, then enter your url. For example
https://8e8ec2d7.ngrok.io/slack/events
. - Grant oAuth Scope for bot event subscribe.
Read more about events https://api.slack.com/events/message
Use case: Interactive Messages
https://slack.dev/node-slack-sdk/interactive-messages
- https://girliemac.com/blog/2016/10/24/slack-command-bot-nodejs/
- https://github.com/slackapi/template-slash-command-and-dialogs/blob/master/src/index.js
- https://api.slack.com/interactivity/slash-commands
- https://scotch.io/tutorials/create-a-custom-slack-slash-command-with-nodejs-and-express
Interactive BOT Design tools
Use Slack Block Kit and Block Kit Builder to create interactive messages.
Use case: POST message back to Slack
https://api.slack.com/methods/chat.postMessage
https://hubot.github.com/ provides capability to create a Slack bot and also contains give developer to use the tools to easily developer their own slack application.