Class: Kanal::Interfaces::Telegram::TelegramInterface
- Inherits:
-
Core::Interfaces::Interface
- Object
- Core::Interfaces::Interface
- Kanal::Interfaces::Telegram::TelegramInterface
- Defined in:
- lib/kanal/interfaces/telegram/telegram_interface.rb
Overview
This interface helps working with telegram
Instance Method Summary collapse
- #consume_output(output) ⇒ Object
- #create_input(message) ⇒ Object
-
#initialize(core, bot_token) ⇒ TelegramInterface
constructor
A new instance of TelegramInterface.
- #start ⇒ Object
Constructor Details
#initialize(core, bot_token) ⇒ TelegramInterface
Returns a new instance of TelegramInterface.
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/kanal/interfaces/telegram/telegram_interface.rb', line 15 def initialize(core, bot_token) super(core) @bot_token = bot_token @bot = ::Telegram::Bot::Client.new(bot_token) @core.register_plugin Kanal::Plugins::Batteries::BatteriesPlugin.new @core.register_plugin Kanal::Interfaces::Telegram::Plugins::TelegramIntegrationPlugin.new @link_parser = Kanal::Interfaces::Telegram::Helpers::TelegramLinkParser.new end |
Instance Method Details
#consume_output(output) ⇒ Object
36 37 38 |
# File 'lib/kanal/interfaces/telegram/telegram_interface.rb', line 36 def consume_output(output) send_output @bot, output end |
#create_input(message) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/kanal/interfaces/telegram/telegram_interface.rb', line 40 def create_input() input = @core.create_input if .attributes.key?(:data) # Inline button pressed input. = .data input.tg_chat_id = .from.id input.tg_username = .from.username else # Regular message received input.tg_chat_id = .chat.id input.tg_username = .chat.username || .from.username if !.text.nil? input.tg_text = .text end if !.photo.nil? # Array of images contains thumbnails, we take 3rd element to get the high-res image input.tg_image_link = @link_parser.get_file_link .photo.last.file_id, @bot, @bot_token end if !.audio.nil? input.tg_audio_link = @link_parser.get_file_link .audio.file_id, @bot, @bot_token end if !.video.nil? input.tg_video_link = @link_parser.get_file_link .video.file_id, @bot, @bot_token end if !.document.nil? input.tg_document_link = @link_parser.get_file_link .document.file_id, @bot, @bot_token end end input end |
#start ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/kanal/interfaces/telegram/telegram_interface.rb', line 28 def start ::Telegram::Bot::Client.run(@bot_token) do |bot| bot.listen do || router.consume_input create_input end end end |