Update: Bot Framework and Integration with Rails I turned GameBot into a runnable app with some bells and whistles at /dblock/slack-gamebot. Slack automatically parses and translates things like. message channel: data, text: "Sorry, what?" end end message channel: data, text: "Hi !" when /^bot/ then client. on :message do | data | case data when 'bot hi' then client. on :message do | data | # respond to messages end client. on :hello do puts 'Successfully connected.' end client. The slack-api gem uses eventmachine to listen on events from Slack. The above code returns a hash with the user information, including url, team and team id, user and user_id. token = ENV end client = Slack :: Web :: Client. Use the token to verify auth via the Web API. Create a new bot, and note its API token. This is something done in Slack, under integrations. gem 'slack-ruby-client', '~> 0.1.0' Create a New Bot Integration The hard part has been done for you in the slack-ruby-client gem. The Real Time Messaging API is a WebSocket-based API that allows you to receive events from Slack in real time and send messages as user. I do want to thank the author of the former gem, for getting me started. I’ve rewritten much of the implementation in a new gem slack-ruby-client, please use that for all your Slack Ruby needs! That library was slow to evolve and wasn’t clearly separating the Slack Web API with the Slack RealTime Messaging API. If you come here from slack-ruby-gem this tutorial no longer uses it. Slack-Ruby-ClientĪ quick note to readers. Let’s get a basic Ruby Slack integration going, using the Slack Real Time Messaging API this time. The endless levels of callback hell and promises have driven me sufficiently crazy to try and rewrite this in Ruby. I’ve been recently contributing to slack-pongbot, a node.js Slack bot for setting up ping-pong matches at Artsy.
0 Comments
Leave a Reply. |