Sha256: 6654b654028db33defea4fa6a8ec8985d948f29a804a8ce35e6ae8821e481540

Contents?: true

Size: 700 Bytes

Versions: 2

Compression:

Stored size: 700 Bytes

Contents

module Telegram
  module Bot
    class Client
      attr_reader :api, :offset, :timeout

      def self.run(*args, &block)
        new(*args).run(&block)
      end

      def initialize(token, timeout = 20)
        @api = Api.new(token)
        @offset = 0
        @timeout = timeout
      end

      def run
        yield self
      end

      def listen
        loop do
          response = api.getUpdates(offset: offset, timeout: timeout)
          next unless response['ok']

          response['result'].each do |data|
            update = Types::Update.new(data)
            @offset = update.update_id.next
            yield update.message
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
telegram-bot-ruby-0.2.5 lib/telegram/bot/client.rb
telegram-bot-ruby-0.2.4 lib/telegram/bot/client.rb