Module: Ruboty::SlackRTM::Client::ReactionAddedClient

Included in:
Ruboty::SlackRTM::Client
Defined in:
lib/ruboty/slack_reaction_added/extension/client.rb

Instance Method Summary collapse

Instance Method Details

#on_text(&block) ⇒ Object

def initialize(websocket_url:)

Ruboty.logger.info websocket_url.to_s
super(websocket_url: websocket_url)

end



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ruboty/slack_reaction_added/extension/client.rb', line 12

def on_text(&block)
  @client.on(:message) do |message|
    case message.type
    when :ping
      Ruboty.logger.debug("#{Client.name}: Received ping message")
      send('', type: 'pong')
    when :pong
      Ruboty.logger.debug("#{Client.name}: Received pong message")
    when :text
      block.call(JSON.parse(message.data))
    when :reaction_added
      case message.data.item.type
      when :message
        # Ruboty.logger.info message.data
        block.call(JSON.parse(message.data))
      else
        Ruboty.logger.warn("#{Client.name}: Received unknown reaction item type=#{message.data.item.type}: #{message.data}")
      end
    else
      Ruboty.logger.warn("#{Client.name}: Received unknown message type=#{message.type}: #{message.data}")
    end
  end
end