class Telegraphist::Bot

Attributes

client[RW]
first_name[RW]
id[RW]
username[RW]

Public Class Methods

create(authentication_token) click to toggle source
# File lib/telegraphist/bot.rb, line 7
def self.create(authentication_token)
  client = Client.new(authentication_token)
  new(client.get(:getMe)['result'].merge(client: client))
end

Public Instance Methods

send_message(chat_id, text) click to toggle source
# File lib/telegraphist/bot.rb, line 29
def send_message(chat_id, text)
  client.post(:sendMessage, query: {chat_id: chat_id, text: text})
end
update_loop(&block) click to toggle source
# File lib/telegraphist/bot.rb, line 12
def update_loop(&block)
  last_update = nil
  loop do
    updates(last_update).try(:each) do |update|
      block.call(update)
      last_update = [last_update, update.update_id + 1].compact.max
    end
    sleep 1
  end
end
updates(offset=nil) click to toggle source
# File lib/telegraphist/bot.rb, line 23
def updates(offset=nil)
  (client.get(:getUpdates, query: {offset: offset})['result'] || []).map do |update|
    Model::Update.new(update)
  end
end