Chat Bots and how to build a Slack bot

Post on 20-Jan-2017

75 views 2 download

transcript

Chat Bots and how to build a SlackBot!!

Vasu JainSr. Software Engineer @ PayPal

Tweets at @vasujain

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 ??

TacoBot within the Slack

Domino’s Pizza Twitter Bot Facebook Bot for Flowers, eBay etc.

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

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

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 interactionOpen source bot builder platform for Node.jsTargets Slack, Facebook, Twilio currentlyhttp://howdy.ai/botkit

Using Botkit to develop a custom Bot using Slack RTM API.

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

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 ithttps://my.slack.com/services/new/bot

3. Capture token generated in #1, to be used to connect to Slack API4. Run a sample bot• npm start token=YOUR_TOKEN

5. Invite Bot to your team 6. Say Hello to your Bot

Lets Integrate an API in our bot ….

1. API to integrate – Github2. Get tokens and make first successful API call3. Convert REST Call into Node Code4. Write a controller using Intents from Slack input and

parsing them for API call5. Integrate Node code6. Parse API Response and construct Slack Response7. Happy Bot-ing !!

Demo for GitBit !!&

Questions

Thank You !!

Image Credits: • http://www.greenmellenmedia.com/wp-content/uploads/slack-chat.png• https://tctechcrunch2011.files.wordpress.com/2016/05/robot-customer-service.png• https://blog.zipfworks.com/content/images/2016/06/1-6J2T-ftDoHNGEvuMQiuWLA.jpeg• https://www.wired.com/wp-content/uploads/2015/08/SlackBot-featured1.jpg• https://cdn-images-1.medium.com/max/800/1*SRq8BmUQl1YWXTCbO859kw.png• https://robotsandpencils.com/wp-content/uploads/2016/03/Hero_graphic_BeepBoop@2x.png• https://beepboophq.storage.googleapis.com/_web/en_US/grande.edeb24.png• https://beepboophq.storage.googleapis.com/_web/en_US/venti.dba620.png