Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Building Slack Apps with Ruby – Kirill Shevchenko

105 views

Published on

Ruby Meditation #22
May 19, 2018
Dnipro

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Building Slack Apps with Ruby – Kirill Shevchenko

  1. 1. Building SlackBuilding Slack Apps withApps with RubyRuby
  2. 2. Integrations OverviewIntegrations Overview Slash Commands Custom Integrations Bot Users Incoming Webhooks
  3. 3. Incoming webhooksIncoming webhooks A way to send messages to Slack https://slack.com/apps/A0F7XDUAZ-incoming-webhooks
  4. 4. Incoming webhooksIncoming webhooks require 'slack/incoming/webhooks' slack = Slack::Incoming::Webhooks.new( 'WEBHOOK_URL' ) slack.post 'Useful information' https://github.com/shoyan/slack-incoming-webhooks
  5. 5. ExampleExample
  6. 6. Slash commandsSlash commands A way to add /slash commands Creating a new Slack App Command request authorization Command validation and response Sending messages through Slack Web API
  7. 7. Creating a Slack AppCreating a Slack App https://api.slack.com/apps
  8. 8. Response PermissionResponse Permission
  9. 9. Adding a commandAdding a command
  10. 10. Local HTTPS-ProxyLocal HTTPS-Proxy ./ngrok http 9292
  11. 11. Response SampleResponse Sample require 'sinatra' post '/' do 'OK' end
  12. 12. Legacy custom integrationsLegacy custom integrations Custom integrationsCustom integrations https://api.slack.com/custom-integrations/legacy-tokens
  13. 13. Bot usersBot users
  14. 14. ToolsTools https://github.com/slack-ruby slack-ruby-botslack-ruby-bot Provides DSL for building text commands. slack-ruby-clientslack-ruby-client A Ruby and command-line client for the Slack Web and Real Time Messaging APIs.
  15. 15. slack-ruby-botslack-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
  16. 16. AuthenticationAuthentication
  17. 17. { "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" } } ResponseResponse
  18. 18. Slack Web APISlack Web API The Web API is a collection of , all with URLs in the form: HTTP RPC-style methods https://slack.com/api/METHOD_FAMILY.method�
  19. 19. slack-ruby-clientslack-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
  20. 20. Web API rate limitWeb API rate limit https://api.slack.com/methods/chat.update
  21. 21. Interactive messagesInteractive messages https://api.slack.com/interactive-messages
  22. 22. Message FormattingMessage Formatting https://api.slack.com/docs/messages/builder
  23. 23. Walkie BotWalkie Bot Prototyping Tool for Slack Bots https://github.com/FoundersAS/walkiebot
  24. 24. Slack RTMSlack RTM The Real Time Messaging API is a WebSocket-based API that allows you to receive �from Slack in real time.events
  25. 25. rtm.connectrtm.connect Workspace https://api.slack.com/methods/rtm.connect wss://slack-msgs.com/websocket/uid
  26. 26. 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!
  27. 27. Ruby Websocket ClientsRuby Websocket Clients Faye::Websocket websocket-client-simple
  28. 28. Multiple connectionsMultiple 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
  29. 29. Concurrent ProcessingConcurrent Processing eventmachine celluloid concurrent-ruby
  30. 30. slack-ruby-clientslack-ruby-client Slack::RealTime.configure do |config| config.concurrency = Slack::RealTime::Concurrency::Celluloid # config.concurrency = Slack::RealTime::Concurrency::Eventmachine end
  31. 31. AlternativesAlternatives https://github.com/slackapi/node-slack-sdk https://github.com/BlakeWilliams/Elixir-Slack
  32. 32. API UpdatesAPI Updates https://slack.com/apps/A0F81R7U7-rss
  33. 33. CommunityCommunity https://community.botkit.ai
  34. 34. Thanks!Thanks! kirillshevchkirillshevch @kirill_shevch@kirill_shevch @kirill_shevch@kirill_shevch

×