Sha256: 39e2a144cb8bb24d8670547d13c9fdcbf9919eaa23cd582eb9b30db83342832c

Contents?: true

Size: 1.38 KB

Versions: 3

Compression:

Stored size: 1.38 KB

Contents

module Telegram
  module Bot
    class UpdatesController
      module ReplyHelpers
        # Helper to call bot's `send_#{type}` method with already set `chat_id` and
        # `reply_to_message_id`:
        #
        #     reply_with :message, text: 'Hello!'
        #     reply_with :message, text: '__Hello!__', parse_mode: :Markdown
        #     reply_with :photo, photo: File.open(photo_to_send), caption: "It's incredible!"
        def reply_with(type, params)
          method = "send_#{type}"
          chat = self.chat
          payload = self.payload
          params = params.merge(
            chat_id: (chat && chat['id'] or raise 'Can not reply_with when chat is not present'),
            reply_to_message: payload && payload['message_id'],
          )
          bot.public_send(method, params)
        end

        # Same as reply_with, but for inline queries.
        def answer_inline_query(results, params = {})
          params = params.merge(
            inline_query_id: payload['id'],
            results: results,
          )
          bot.answer_inline_query(params)
        end

        # Same as reply_with, but for callback queries.
        def answer_callback_query(text, params = {})
          params = params.merge(
            callback_query_id: payload['id'],
            text: text,
          )
          bot.answer_callback_query(params)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
telegram-bot-0.7.4 lib/telegram/bot/updates_controller/reply_helpers.rb
telegram-bot-0.7.3 lib/telegram/bot/updates_controller/reply_helpers.rb
telegram-bot-0.7.2 lib/telegram/bot/updates_controller/reply_helpers.rb