Class: Lita::Adapters::TelegramPlus
- Inherits:
-
Adapter
- Object
- Adapter
- Lita::Adapters::TelegramPlus
- Defined in:
- lib/lita/adapters/telegram_plus.rb
Instance Method Summary collapse
-
#initialize(robot) ⇒ TelegramPlus
constructor
A new instance of TelegramPlus.
-
#run ⇒ Object
Connect to Telegram and listen to incoming messages.
-
#send_messages(target, messages) ⇒ Object
Send messages to the Telegram bot api.
-
#shutdown ⇒ Object
Disconnect from Telegram.
Constructor Details
#initialize(robot) ⇒ TelegramPlus
Returns a new instance of TelegramPlus.
8 9 10 11 12 |
# File 'lib/lita/adapters/telegram_plus.rb', line 8 def initialize(robot) super @client = Telegram::Bot::Client.new(config.token, logger: ::Logger.new($stdout)) robot.trigger(:connected) end |
Instance Method Details
#run ⇒ Object
Connect to Telegram and listen to incoming messages
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/lita/adapters/telegram_plus.rb', line 15 def run @client.listen do || user = Lita::User.find_by_id(.from.id) user = Lita::User.create(id: .from.id, name: .from.first_name) unless user if user.name == user.id user = Lita::User.create(id: .from.id, name: .from.first_name) end chat = Lita::Room.new(.chat.id) source = Lita::Source.new(user: user, room: chat) .text ||= '' = Lita::Message.new(robot, .text, source) robot.receive() end end |
#send_messages(target, messages) ⇒ Object
Send messages to the Telegram bot api
35 36 37 38 39 |
# File 'lib/lita/adapters/telegram_plus.rb', line 35 def (target, ) .each do || @client.api.(chat_id: target.room.to_i, text: ) end end |
#shutdown ⇒ Object
Disconnect from Telegram
42 43 |
# File 'lib/lita/adapters/telegram_plus.rb', line 42 def shutdown end |