Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
[Ruby Meditation #22] Building Slack Apps with ...
Search
Kirill Shevchenko
May 19, 2018
Programming
4
240
[Ruby Meditation #22] Building Slack Apps with Ruby
Kirill Shevchenko
May 19, 2018
Tweet
Share
More Decks by Kirill Shevchenko
See All by Kirill Shevchenko
[RubyWine #1] Event-Driven Architecture and Messaging Patterns for Ruby Microservices
kirillshevch
1
7.3k
Other Decks in Programming
See All in Programming
Babylon.js 8.0のアプデ情報を 軽率にキャッチアップ / catch-up-babylonjs-8
drumath2237
0
120
20250528 AWS Startupイベント登壇資料:AIコーディングの取り組み
procrustes5
0
130
#QiitaBash TDDでAIに設計イメージを伝える
ryosukedtomita
2
1.6k
❄️ tmux-nixの実装を通して学ぶNixOSモジュール
momeemt
1
140
型付け力を強化するための Hoogle のすゝめ / Boosting Your Type Mastery with Hoogle
guvalif
1
250
Prism.parseで 300本以上あるエンドポイントに 接続できる権限の一覧表を作ってみた
hatsu38
1
100
Spring gRPC で始める gRPC 入門 / Introduction to gRPC with Spring gRPC
mackey0225
2
420
複数アプリケーションを育てていくための共通化戦略
irof
9
3.5k
AI Coding Agent Enablement in TypeScript
yukukotani
17
8.1k
UPDATEがシステムを複雑にする? イミュータブルデータモデルのすすめ
shimomura
0
410
少数精鋭エンジニアがフルスタック力を磨く理由 -そしてAI時代へ-
rebase_engineering
0
150
事業戦略を理解してソフトウェアを設計する
masuda220
PRO
18
5.4k
Featured
See All Featured
KATA
mclloyd
29
14k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.6k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
10
860
Docker and Python
trallard
44
3.4k
Code Review Best Practice
trishagee
68
18k
Fontdeck: Realign not Redesign
paulrobertlloyd
84
5.5k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
15
900
The World Runs on Bad Software
bkeepers
PRO
68
11k
Making Projects Easy
brettharned
116
6.2k
Rails Girls Zürich Keynote
gr2m
94
13k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
3.9k
Documentation Writing (for coders)
carmenintech
71
4.8k
Transcript
Building Slack Building Slack Apps with Apps with Ruby Ruby
Integrations Overview Integrations Overview Slash Commands Custom Integrations Bot Users
Incoming Webhooks
Incoming webhooks Incoming webhooks A way to send messages to
Slack https://slack.com/apps/A0F7XDUAZ-incoming-webhooks
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
Example Example
Slash commands Slash commands A way to add /slash commands
Creating a new Slack App Command request authorization Command validation and response
Creating a Slack App Creating a Slack App https://api.slack.com/apps
Response Permission Response Permission
Adding a command Adding a command
Local HTTPS-Proxy Local HTTPS-Proxy ./ngrok http 9292
Response Sample Response Sample require 'sinatra' post '/' do 'OK'
end
None
Legacy custom integrations Legacy custom integrations Custom integrations Custom integrations
https://api.slack.com/custom-integrations/legacy-tokens
Bot users Bot users
Authentication Authentication
{ "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
Tools Tools https://github.com/slack-ruby (not affiliated 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.
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
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
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
Web API rate limit Web API rate limit https://api.slack.com/methods/chat.update
Interactive messages Interactive messages https://api.slack.com/interactive-messages
Message Formatting Message Formatting https://api.slack.com/docs/messages/builder
Walkie Bot Walkie Bot Prototyping Tool for Slack Bots https://github.com/FoundersAS/walkiebot
None
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
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!
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!
Ruby Websocket Clients Ruby Websocket Clients Faye::Websocket websocket-client-simple
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
Concurrent Processing Concurrent Processing eventmachine celluloid concurrent-ruby
slack-ruby-client slack-ruby-client Slack::RealTime.configure do |config| config.concurrency = Slack::RealTime::Concurrency::Celluloid # config.concurrency
= Slack::RealTime::Concurrency::Eventmachine end
None
Alternatives Alternatives https://github.com/slackapi/node-slack-sdk https://github.com/BlakeWilliams/Elixir-Slack
None
Testing? Testing?
API Updates API Updates https://slack.com/apps/A0F81R7U7-rss
Community Community https://community.botkit.ai
Thanks! Thanks! kirillshevch kirillshevch @kirill_shevch @kirill_shevch @kirill_shevch @kirill_shevch