Slide 1

Slide 1 text

Building Slack Building Slack Apps with Apps with Ruby Ruby

Slide 2

Slide 2 text

Integrations Overview Integrations Overview Slash Commands Custom Integrations Bot Users Incoming Webhooks

Slide 3

Slide 3 text

Incoming webhooks Incoming webhooks A way to send messages to Slack https://slack.com/apps/A0F7XDUAZ-incoming-webhooks

Slide 4

Slide 4 text

Incoming webhooks Incoming webhooks require 'slack/incoming/webhooks' slack = Slack::Incoming::Webhooks.new( 'WEBHOOK_URL' ) slack.post 'Useful information' https://github.com/shoyan/slack-incoming-webhooks

Slide 5

Slide 5 text

Example Example

Slide 6

Slide 6 text

Slash commands Slash commands A way to add /slash commands Creating a new Slack App Command request authorization Command validation and response

Slide 7

Slide 7 text

Creating a Slack App Creating a Slack App https://api.slack.com/apps

Slide 8

Slide 8 text

Response Permission Response Permission

Slide 9

Slide 9 text

Adding a command Adding a command

Slide 10

Slide 10 text

Local HTTPS-Proxy Local HTTPS-Proxy ./ngrok http 9292

Slide 11

Slide 11 text

Response Sample Response Sample require 'sinatra' post '/' do 'OK' end

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

Legacy custom integrations Legacy custom integrations Custom integrations Custom integrations https://api.slack.com/custom-integrations/legacy-tokens

Slide 14

Slide 14 text

Bot users Bot users

Slide 15

Slide 15 text

Authentication Authentication

Slide 16

Slide 16 text

{ "access_token": "xoxp-XXXXXXXX-XXXXXXXX-XXXXX", "scope": "commands,bot", "team_name": "Team Installing Your Bot", "team_id": "XXXXXXXXXX", "bot":{ "bot_user_id":"UTTTTTTTTTTR", "bot_access_token":"xoxb-XXXXXXXXXXXX-TTTTTTTTTTTTTT" } } Response Response

Slide 17

Slide 17 text

Tools Tools https://github.com/slack-ruby (not aļ¬ƒliated with Slack) slack-ruby-bot slack-ruby-bot Provides DSL for building text commands. slack-ruby-client slack-ruby-client A Ruby and command-line client for the Slack Web and Real Time Messaging APIs.

Slide 18

Slide 18 text

slack-ruby-bot slack-ruby-bot require 'slack-ruby-bot' class PongBot < SlackRubyBot::Bot command 'ping' do |client, data, match| client.say(text: 'pong', channel: data.channel) end end PongBot.run A Minimal Bot SLACK_API_TOKEN=... bundle exec ruby pongbot.rb

Slide 19

Slide 19 text

Slack Web API Slack Web API The Web API is a collection of , all with URLs in the form: HTTP RPC-style methods https://slack.com/api/FAMILY_METHOD.method

Slide 20

Slide 20 text

slack-ruby-client slack-ruby-client client = Slack::Web::Client.new( token: 'SLACK_BOT_TOKEN' ) client.chat_postMessage( channel: '#general', text: 'Hello World' ) https://api.slack.com/methods/chat.postMessage

Slide 21

Slide 21 text

Web API rate limit Web API rate limit https://api.slack.com/methods/chat.update

Slide 22

Slide 22 text

Interactive messages Interactive messages https://api.slack.com/interactive-messages

Slide 23

Slide 23 text

Message Formatting Message Formatting https://api.slack.com/docs/messages/builder

Slide 24

Slide 24 text

Walkie Bot Walkie Bot Prototyping Tool for Slack Bots https://github.com/FoundersAS/walkiebot

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

Slack RTM Slack RTM The Real Time Messaging API is a WebSocket-based API that allows you to receive from Slack in real time. events

Slide 27

Slide 27 text

rtm.connect rtm.connect Workspace https://api.slack.com/methods/rtm.connect wss://slack-msgs.com/websocket/uid These URLs are only valid for 30 seconds, so connect quickly!

Slide 28

Slide 28 text

client = Slack::RealTime::Client.new( token: 'SLACK_BOT_TOKEN' ) client.on :message do |data| client.message( channel: data.channel, text: "Hi <@#{data.user}>!" ) end client.start!

Slide 29

Slide 29 text

Ruby Websocket Clients Ruby Websocket Clients Faye::Websocket websocket-client-simple

Slide 30

Slide 30 text

Multiple connections Multiple connections Workspace 1 Workspace 2 Workspace N wss://slack-msgs.com/websocket/uid wss://slack-msgs.com/websocket/uid wss://slack-msgs.com/websocket/uid

Slide 31

Slide 31 text

Concurrent Processing Concurrent Processing eventmachine celluloid concurrent-ruby

Slide 32

Slide 32 text

slack-ruby-client slack-ruby-client Slack::RealTime.configure do |config| config.concurrency = Slack::RealTime::Concurrency::Celluloid # config.concurrency = Slack::RealTime::Concurrency::Eventmachine end

Slide 33

Slide 33 text

No content

Slide 34

Slide 34 text

Alternatives Alternatives https://github.com/slackapi/node-slack-sdk https://github.com/BlakeWilliams/Elixir-Slack

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

Testing? Testing?

Slide 37

Slide 37 text

API Updates API Updates https://slack.com/apps/A0F81R7U7-rss

Slide 38

Slide 38 text

Community Community https://community.botkit.ai

Slide 39

Slide 39 text

Thanks! Thanks! kirillshevch kirillshevch @kirill_shevch @kirill_shevch @kirill_shevch @kirill_shevch