Sha256: e66dd556db3b0a1d7398cdb9996b77b09ea6fbd5372621622b6643e48e478e8e

Contents?: true

Size: 741 Bytes

Versions: 1

Compression:

Stored size: 741 Bytes

Contents

module Fluent
  require 'fluent/mixin/config_placeholders'
  require 'slack-rtmapi'

  class SlackRTMInput < Fluent::Input
    Fluent::Plugin.register_input('slackrtm', self)

    config_param :tag, :string
    config_param :token, :string

    def start
      super
      @messages_thread = Thread.new do
        url = SlackRTM.get_url token: token
        client = SlackRTM::Client.new websocket_url: url
        client.on(:message) do |data|
          emit(data)
        end
        client.main_loop
      end
      @messages_thread.abort_on_exception = true
    end

    def shutdown
      Thread.kill(@messages_thread)
    end

    def emit(data)
      time = Time.now.to_i
      Fluent::Engine.emit(tag, time, data)
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fluent-plugin-slackrtm-0.2.3 lib/fluent/plugin/in_slackrtm.rb