Module: Xtend::TelegramAdapter
- Defined in:
- lib/xtend/telegram_adapter.rb
Instance Method Summary collapse
Instance Method Details
#run ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/xtend/telegram_adapter.rb', line 5 def run client.listen do || user = Lita::User.find_by_id(.from.id) user = Lita::User.create(.from.id, name: .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
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/xtend/telegram_adapter.rb', line 22 def (target, ) .each do || typing(target) if .is_a?(String) client.api.sendMessage(chat_id: target.room.to_i, text: ) elsif .is_a?(Hash) client.api.sendMessage(chat_id: target.room.to_i, **) else next end end end |
#typing(target) ⇒ Object
35 36 37 |
# File 'lib/xtend/telegram_adapter.rb', line 35 def typing(target) client.api.sendChatAction(chat_id: target.room.to_i, action: 'typing') end |