Class: TelegramBot::Bot
- Inherits:
-
Object
- Object
- TelegramBot::Bot
- Defined in:
- lib/telegram_bot/bot.rb
Constant Summary collapse
- ENDPOINT =
'https://api.telegram.org/'
Instance Method Summary collapse
- #get_me ⇒ Object (also: #me)
- #get_updates(opts = {}, &block) ⇒ Object
-
#initialize(opts = {}) ⇒ Bot
constructor
A new instance of Bot.
- #send_message(out_message) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Bot
Returns a new instance of Bot.
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/telegram_bot/bot.rb', line 5 def initialize(opts = {}) # compatibility with just passing a token if opts.is_a?(String) opts = { token: opts } end @token = opts.fetch(:token) @timeout = opts[:timeout] || 50 @offset = opts[:offset] || 0 @logger = opts[:logger] || NullLogger.new @connection = Excon.new(ENDPOINT, persistent: true) end |
Instance Method Details
#get_me ⇒ Object Also known as: me
18 19 20 21 22 23 |
# File 'lib/telegram_bot/bot.rb', line 18 def get_me @me ||= begin response = request(:getMe) User.new(response.result) end end |
#get_updates(opts = {}, &block) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/telegram_bot/bot.rb', line 27 def get_updates(opts = {}, &block) return (opts) unless block_given? logger.info "starting get_updates loop" loop do = (opts) .each do || logger.info "message from @#{.chat.friendly_name}: #{.text.inspect}" yield end end end |