Sha256: eb032d7abd9c4b610faac9396f92cc7ba1979ef638789bc6d3adc80b67f18338

Contents?: true

Size: 1.81 KB

Versions: 3

Compression:

Stored size: 1.81 KB

Contents

# frozen_string_literal: true

module Kanal
  module Interfaces
    module Telegram
      module Plugins
        # This class registers properties and hooks for telegram bot library integration
        class TelegramIntegrationPlugin < Kanal::Core::Plugins::Plugin
          def name
            :telegram_properties
          end

          def setup(core)
            register_parameters core
            register_hooks core
          end

          def register_parameters(core)
            core.register_input_parameter :tg_chat_id, readonly: true
            core.register_input_parameter :tg_username, readonly: true
            core.register_input_parameter :tg_text, readonly: true
            core.register_input_parameter :tg_button_pressed, readonly: true
            core.register_input_parameter :tg_image_link, readonly: true
            core.register_input_parameter :tg_audio_link, readonly: true
            core.register_input_parameter :tg_video_link, readonly: true
            core.register_input_parameter :tg_document_link, readonly: true

            core.register_output_parameter :tg_chat_id
            core.register_output_parameter :tg_text
            core.register_output_parameter :tg_image_path
            core.register_output_parameter :tg_audio_path
            core.register_output_parameter :tg_video_path
            core.register_output_parameter :tg_document_path
            core.register_output_parameter :tg_reply_markup
          end

          def register_hooks(core)
            core.hooks.attach :input_just_created do |input|
              input.source = :telegram
            end

            core.hooks.attach :output_before_returned do |input, output|
              output.tg_chat_id = input.tg_chat_id if output.tg_chat_id.nil?
            end
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
kanal-interfaces-telegram-0.4.2 lib/kanal/interfaces/telegram/plugins/telegram_integration_plugin.rb
kanal-interfaces-telegram-0.4.1 lib/kanal/interfaces/telegram/plugins/telegram_integration_plugin.rb
kanal-interfaces-telegram-0.4.0 lib/kanal/interfaces/telegram/plugins/telegram_integration_plugin.rb