Sha256: 561f279b6d238e5ba2f2eee73de65de4f6455fb08f2457bfefb39f275f0d5ff1

Contents?: true

Size: 611 Bytes

Versions: 3

Compression:

Stored size: 611 Bytes

Contents

class TelegramBot
  class PollListener
    def initialize(client, interval)
      @client    = client
      @interval  = interval
      @offset_id = nil
    end

    def message_received(msg)
      @client.append_history(msg)
      @client.handle(msg)
    end

    def start!
      loop do
        get_updates
        sleep @interval
      end
    end

    def get_updates
      updates = @client.get_updates(offset: @offset_id,
                                    limit: 50)
      updates.each do |update|
        @offset_id = update.id + 1
        message_received(update.message)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
telegram_bot_ruby-0.1.5 lib/telegram_bot/poll_listener.rb
telegram_bot_ruby-0.1.3 lib/telegram_bot/poll_listener.rb
telegram_bot_ruby-0.1.1 lib/telegram_bot/poll_listener.rb