Class: TeleRb::TelegramBot

Inherits:
Object
  • Object
show all
Includes:
ActionsMethods, MediaMethods, MessageMethods, UserMethods
Defined in:
lib/telerb/telegram_bot.rb

Overview

class telegram bot

Instance Method Summary collapse

Methods included from UserMethods

#user_info

Methods included from ActionsMethods

#get_commands, #set_commands

Methods included from MediaMethods

#send_audio, #send_document, #send_photo, #send_sticker, #send_video

Methods included from MessageMethods

#forward_message, #send_location, #send_message

Constructor Details

#initialize(config) ⇒ TelegramBot

Returns a new instance of TelegramBot.



17
18
19
# File 'lib/telerb/telegram_bot.rb', line 17

def initialize(config)
  @config = config
end

Instance Method Details

#listen(&block) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/telerb/telegram_bot.rb', line 21

def listen(&block)
  loop do
    updates = get_updates(@config.offset)
    updates.each do |update|
      block.call update["message"] if block_given? && update["message"]
      @config.offset = update["update_id"] + 1
    end
  rescue StandardError => e
    puts "Error in listen method: #{e.message}"
  end
  sleep 2
end