Upgrade to Pro — share decks privately, control downloads, hide ads and more …

[Ruby Meditation #22] Building Slack Apps with ...

[Ruby Meditation #22] Building Slack Apps with Ruby

Kirill Shevchenko

May 19, 2018
Tweet

More Decks by Kirill Shevchenko

Other Decks in Programming

Transcript

  1. Incoming webhooks Incoming webhooks A way to send messages to

    Slack https://slack.com/apps/A0F7XDUAZ-incoming-webhooks
  2. 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
  3. Slash commands Slash commands A way to add /slash commands

    Creating a new Slack App Command request authorization Command validation and response
  4. { "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
  5. 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.
  6. 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
  7. 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
  8. 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
  9. 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!
  10. 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