Class: Nanobot::Channels::Telegram
- Inherits:
-
BaseChannel
- Object
- BaseChannel
- Nanobot::Channels::Telegram
- Defined in:
- lib/nanobot/channels/telegram.rb
Overview
Telegram channel integration using the telegram-bot-ruby gem. Listens for messages via long polling and shows typing indicators.
Instance Attribute Summary
Attributes inherited from BaseChannel
Instance Method Summary collapse
-
#send(message) ⇒ Object
Send a reply to a Telegram chat, splitting at the 4096-char limit.
- #start ⇒ Object
- #stop ⇒ Object
Methods inherited from BaseChannel
#allowed?, #initialize, #running?
Constructor Details
This class inherits a constructor from Nanobot::Channels::BaseChannel
Instance Method Details
#send(message) ⇒ Object
Send a reply to a Telegram chat, splitting at the 4096-char limit.
40 41 42 43 44 45 46 47 |
# File 'lib/nanobot/channels/telegram.rb', line 40 def send() return unless @bot stop_typing(.chat_id) (.content, 4096).each do |chunk| @bot.api.(chat_id: .chat_id, text: chunk) end end |
#start ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/nanobot/channels/telegram.rb', line 14 def start @running = true ::Telegram::Bot::Client.run(@config.token) do |bot| @bot = bot register_commands(bot) bot.listen do || break unless @running next unless .is_a?(::Telegram::Bot::Types::Message) next unless .text start_typing(.chat.id.to_s) ( sender_id: .from.id.to_s, chat_id: .chat.id.to_s, content: .text ) end end end |
#stop ⇒ Object
34 35 36 |
# File 'lib/nanobot/channels/telegram.rb', line 34 def stop @running = false end |