Class: TelegramMeetupBot::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/telegram_meetup_bot/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token) ⇒ Client

Returns a new instance of Client.



5
6
7
# File 'lib/telegram_meetup_bot/client.rb', line 5

def initialize(token)
  @token = token
end

Instance Attribute Details

#tokenObject (readonly)

Returns the value of attribute token.



3
4
5
# File 'lib/telegram_meetup_bot/client.rb', line 3

def token
  @token
end

Instance Method Details

#runObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/telegram_meetup_bot/client.rb', line 9

def run
  begin
    Telegram::Bot::Client.run(token) do |bot|
      bot.listen do |message|
        if message.text
          messenger = Messenger.new(api: bot.api, chat_id: message.chat.id)
          CommandsHandler.new(message: message, messenger: messenger).process
        end
      end
    end
  rescue Telegram::Bot::Exceptions::ResponseError => e
    puts e
    sleep 1
    retry # run again on telegram server error
  end
end