No commit activity in last 3 years
No release in over 3 years
Connects to Slack Real Time Messaging (RTM) API to receive events. Runs on EventMachine. Use this gem to create your own bot by registering event handlers.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

slack-rtm-receiver

Gem Version Code Climate

A Ruby gem. It connects to Slack Real Time Messaging API to receive events. Runs on EventMachine.

Requirements

Getting Started

Install

$ gem install slack-rtm-receiver

Use

require 'slack-rtm-receiver'

Create an object to respond to received events. You can subclass EventHandler.

class MyHandler < SlackRTMReceiver::EventHandler
  def process_event(event, session)
    if event[:text] == 'hi'
      res_event = {
        type: 'message',
        channel: event[:channel],
        text: 'Hi!'
      }
      session.send_event(res_event)
    end
  end
end
SlackRTMReceiver.add_event_handler(MyHandler.new)

Or, you can pass a block. The following works the same as above.

SlackRTMReceiver::EventHandler.add_type('message') do |event, session|
  if event[:text] == 'hi'
    res_event = {
      type: 'message',
      channel: event[:channel],
      text: 'Hi!'
    }
    session.send_event(res_event)
  end
end

Start the reactor to connect to Slack.

opts = {token: 'xoxb-1234abcd5678efgh'}
SlackRTMReceiver::Reactor.run(opts)