The document discusses how to build chatbots for the messaging platform Slack, including what Slackbots are, how they interact with users through APIs, and how to develop custom Slackbots using frameworks like Botkit that simplify interacting with the Slack API and building bot functionality like responding to commands and events. It provides an overview of setting up a bot user on Slack, programming it using Node.js and libraries, and includes an example of integrating an API like GitHub into a Slackbot.
Roadmap to Membership of RICS - Pathways and Routes
Build a SlackBot with Node.js
1. Chat Bots and how
to build a SlackBot!!
Vasu Jain
Sr. Software Engineer @ PayPal
Tweets at @vasujain
2. What is a Chatbot, Slack, SlackBot ..
A Chatbot is a computer program which conducts a
conversation via audio or textual methods.
E.g. Alexa, automated text based chat bots for
Slack, Facebook etc.
Slack is a cloud-based messaging app for team
collaboration. Got very popular due to app integrations.
Slack teams consist of channels, users (humans and bots)
SlackBot ??
3. TacoBot within the Slack
Domino’s Pizza Twitter Bot Facebook Bot for Flowers, eBay etc.
4. What can a Slackbot do
Slack Bot interact with a user on a Slack team by
1. Connecting to Slack’s RTM API and opening a web-socket connection with Slack.
• Bot user will Monitor and process channel activity
• Post messages and react to users
• Web API to post formatted messages, attachments, emoji
• Make messages interactive with buttons
2. Listening to Slack Events via HTTP based Events API aka Slack Webhooks .
Configure events at https://api.slack.com/events
5. Developing a SlackBot …
Two Kinds of Slack bot you can develop :
1. Custom Bots
- Custom for a team’s requirements
- Can be used for company’s process automation etc.
2. Bot Users attached to Slack App
- For distribution to other teams
- Governed by OAuth permission scopes
- Distributed via Slack Button or Slack Appstore
6. Programming a Slack bot ….
1. Make authenticated API calls and consume Slack RTM API
2. Use existing library (such as node-slack-client)
https://github.com/slackhq/node-slack-client
3. Botkit Framework :
Does heavy lifting for Slack API interaction
Open source bot builder platform for Node.js
Targets Slack, Facebook, Twilio currently
http://howdy.ai/botkit
Using Botkit to develop a custom Bot using Slack RTM API.
7. Project Structure …
• node_modules contain botkit module – generated by npm install
• package.json specifies your project details and dependencies
• index.js is the main entry point file.
• Util.js for utility functions
• Config.json for string sensitive data
• Npm-debug.log created by default for error logging
• lib directory containing slack libraries
Clone : https://github.com/vasujain/slack-bot-github
8. Developing a Custom SlackBot …
1. Install Botkit
• From NPM
• npm install --save botkit
• From Github
• git clone git@github.com:howdyai/botkit.git
• npm install
2. Create a new bot user integration and customize it
https://my.slack.com/services/new/bot
3. Capture token generated in #1, to be used to connect to Slack API
4. Run a sample bot
• npm start token=YOUR_TOKEN
5. Invite Bot to your team
6. Say Hello to your Bot
9. Lets Integrate an API in our bot ….
1. API to integrate – Github
2. Get tokens and make first successful API call
3. Convert REST Call into Node Code
4. Write a controller using Intents from Slack input and
parsing them for API call
5. Integrate Node code
6. Parse API Response and construct Slack Response
7. Happy Bot-ing !!