Sha256: f0dc869b6897217d0bc76d440d726ad9e07ec1d9308be7a14d90cb22e8ea1f20

Contents?: true

Size: 1.12 KB

Versions: 6

Compression:

Stored size: 1.12 KB

Contents

module Telegram
  module Bot
    class UpdatesController
      # Use separate actions for different callback queries.
      # It doesn't require session support. Simply add `%{context}:` prefix to data.
      module CallbackQueryContext
        protected

        # Uses #context_from_callback_query as context name.
        # If context is present checks if `%context%_callback_query` is valid
        # action method and returns it if so. Context is stripped from data
        # in this case. Otherwise returns `super`.
        #
        # It wont raise ActionNotFound as MessageContext does,
        # because `data` param is controlled by client.
        def action_for_callback_query
          context, new_data = context_from_callback_query
          if context
            action_name = "#{context}_callback_query"
            [false, action_name, [new_data]] if action_method?(action_name)
          end || super
        end

        def context_from_callback_query
          data = payload['data']
          return unless data
          parts = data.split(':', 2)
          parts if parts.size > 1
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
telegram-bot-0.13.1 lib/telegram/bot/updates_controller/callback_query_context.rb
telegram-bot-0.13.0 lib/telegram/bot/updates_controller/callback_query_context.rb
telegram-bot-0.12.4 lib/telegram/bot/updates_controller/callback_query_context.rb
telegram-bot-0.12.3 lib/telegram/bot/updates_controller/callback_query_context.rb
telegram-bot-0.12.1 lib/telegram/bot/updates_controller/callback_query_context.rb
telegram-bot-0.12.0 lib/telegram/bot/updates_controller/callback_query_context.rb