Class: Tegawa::Bot

Inherits:
Object
  • Object
show all
Defined in:
lib/tegawa/bot.rb

Instance Method Summary collapse

Constructor Details

#initialize(token, channel_id) ⇒ Bot

Returns a new instance of Bot.



7
8
9
10
11
12
13
14
15
# File 'lib/tegawa/bot.rb', line 7

def initialize(token, channel_id)
  @token = token
  @channel_id = channel_id
  @queue = Tegawa.queue
  @logger = Tegawa.logger

  @bot = Telegram::Bot::Client.new(@token)
  @logger.info "Ready to forward messages to channel: #{@channel_id}"
end

Instance Method Details

#runObject



17
18
19
20
21
22
23
# File 'lib/tegawa/bot.rb', line 17

def run
  # FIXME: needs a thread pool to stop flooding
  while (message = @queue.pop)
    @logger.info "Forwarding message to telegram"
    @bot.api.send_message(chat_id: @channel_id, text: message)
  end
end