Sha256: 2410412052b1c155c0be9825c95547722cce426ba31beaee492e29331227e2da

Contents?: true

Size: 1.53 KB

Versions: 11

Compression:

Stored size: 1.53 KB

Contents

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

        # Same as respond_with but also sets `reply_to_message_id`.
        def reply_with(type, params)
          payload = self.payload
          message_id = payload && payload['message_id']
          params = params.merge(reply_to_message_id: message_id) if message_id
          respond_with(type, 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

11 entries across 11 versions & 1 rubygems

Version Path
telegram-bot-0.11.3 lib/telegram/bot/updates_controller/reply_helpers.rb
telegram-bot-0.11.2 lib/telegram/bot/updates_controller/reply_helpers.rb
telegram-bot-0.11.1 lib/telegram/bot/updates_controller/reply_helpers.rb
telegram-bot-0.11.0 lib/telegram/bot/updates_controller/reply_helpers.rb
telegram-bot-0.10.2 lib/telegram/bot/updates_controller/reply_helpers.rb
telegram-bot-0.10.1 lib/telegram/bot/updates_controller/reply_helpers.rb
telegram-bot-0.10.0 lib/telegram/bot/updates_controller/reply_helpers.rb
telegram-bot-0.9.0 lib/telegram/bot/updates_controller/reply_helpers.rb
telegram-bot-0.9.0.alpha2 lib/telegram/bot/updates_controller/reply_helpers.rb
telegram-bot-0.9.0.alpha1 lib/telegram/bot/updates_controller/reply_helpers.rb
telegram-bot-0.8.0 lib/telegram/bot/updates_controller/reply_helpers.rb