Sha256: 4fe37e6c3b27679ff256c663bab316598a58c7a9d7ce432a4c18d70bfea0919e

Contents?: true

Size: 631 Bytes

Versions: 4

Compression:

Stored size: 631 Bytes

Contents

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

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

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

      def run
        yield self
      end

      def listen
        loop do
          response = api.getUpdates(offset: offset)
          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

4 entries across 4 versions & 1 rubygems

Version Path
telegram-bot-ruby-0.2.3 lib/telegram/bot/client.rb
telegram-bot-ruby-0.2.2 lib/telegram/bot/client.rb
telegram-bot-ruby-0.2.1 lib/telegram/bot/client.rb
telegram-bot-ruby-0.2.0 lib/telegram/bot/client.rb