Sha256: 517c71716d630dc25515cd4702da8e9e086c740fc7ee03c933f1c0ca826fa153

Contents?: true

Size: 1.12 KB

Versions: 2

Compression:

Stored size: 1.12 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_message, readonly: true
            core.register_output_parameter :tg_text
            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 :input_before_router do |input|
              input.body = input.tg_message.text
            end

            core.hooks.attach :output_before_returned do |input, output|
              output.tg_text = output.body
            end
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
kanal-interfaces-telegram-0.1.2 lib/kanal/interfaces/telegram/plugins/telegram_integration_plugin.rb
kanal-interfaces-telegram-0.1.1 lib/kanal/interfaces/telegram/plugins/telegram_integration_plugin.rb