diff --git a/README.md b/README.md index f37d6b4..5e95fed 100644 --- a/README.md +++ b/README.md @@ -168,6 +168,20 @@ class Telegram::WebhookController < Telegram::Bot::UpdatesController end ``` +#### Reply helpers + +There are helpers to respond for basic actions. They just set chat/message/query +identifiers from update. See `ReplyHelpers` method for more information. +Here are this methods signatures: + +```ruby +def respond_with(type, params); end +def reply_with(type, params); end +def answer_inline_query(results, params = {}); end +def answer_callback_query(text, params = {}); end +def edit_message(type, params = {}); end +``` + #### Optional typecasting You can enable typecasting of `update` with `telegram-bot-types` by including diff --git a/lib/telegram/bot/updates_controller/reply_helpers.rb b/lib/telegram/bot/updates_controller/reply_helpers.rb index 9c00c7a..3e90954 100644 --- a/lib/telegram/bot/updates_controller/reply_helpers.rb +++ b/lib/telegram/bot/updates_controller/reply_helpers.rb @@ -38,6 +38,19 @@ module Telegram ) bot.answer_callback_query(params) end + + # Edit message from callback query. + def edit_message(type, params = {}) + params = + if query_id = payload['inline_message_id'] # rubocop:disable AssignmentInCondition + params.merge(inline_query_id: query_id) + elsif message = payload['message'] # rubocop:disable AssignmentInCondition + params.merge(chat_id: message['chat']['id'], message_id: message['message_id']) + else + raise 'Can not edit message without `inline_message_id` or `message`' + end + bot.public_send("edit_message_#{type}", params) + end end end end diff --git a/spec/telegram/bot/updates_controller/reply_helpers_spec.rb b/spec/telegram/bot/updates_controller/reply_helpers_spec.rb index 53537ca..c29111d 100644 --- a/spec/telegram/bot/updates_controller/reply_helpers_spec.rb +++ b/spec/telegram/bot/updates_controller/reply_helpers_spec.rb @@ -48,4 +48,8 @@ RSpec.describe Telegram::Bot::UpdatesController do end end end + + describe '#edit_message' do + skip 'TODO' + end end