Class: Lita::Adapters::Telegram
- Inherits:
-
Adapter
- Object
- Adapter
- Lita::Adapters::Telegram
- Defined in:
- lib/lita/adapters/telegram.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
-
#initialize(robot) ⇒ Telegram
constructor
A new instance of Telegram.
- #run ⇒ Object
- #send_messages(target, messages) ⇒ Object
Constructor Details
#initialize(robot) ⇒ Telegram
Returns a new instance of Telegram.
8 9 10 11 |
# File 'lib/lita/adapters/telegram.rb', line 8 def initialize(robot) super @client = ::Telegram::Bot::Client.new(config.telegram_token, logger: ::Logger.new($stdout)) end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
4 5 6 |
# File 'lib/lita/adapters/telegram.rb', line 4 def client @client end |
Instance Method Details
#run ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/lita/adapters/telegram.rb', line 13 def run client.listen do || user = Lita::User.find_by_name(.from.username) user = Lita::User.create(.from.username) unless user chat = Lita::Room.new(.chat.id) source = Lita::Source.new(user: user, room: chat) .text ||= '' msg = Lita::Message.new(robot, .text, source) robot.receive(msg) end end |
#send_messages(target, messages) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/lita/adapters/telegram.rb', line 28 def (target, ) .each do || client.api.sendChatAction(chat_id: target.room.to_i, action: 'typing') client.api.sendMessage(chat_id: target.room.to_i, text: ) end end |