Carrein
Carrein

Reputation: 3361

Editing Telegram bot messages using Ruby?

I have a telegram bot which is built with a Ruby Wrapper which prints out a inline keyboard message asking for user's input.

However, I would like to replace the message with a new one once the user clicks on an option.

    bot.api.edit_message_text(chat_id: message.from.id, 
        message_id: message.message_id,
        text: "What would you like Athena to do?",
        reply_markup: tasks_keyboard()
        )

I am running into the following error with the above code:

C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/telegram-bot-ruby-0.8.6.1/lib/telegram/bot/api.rb:76:in `call': Telegram API has returned the error. (ok: "false", error_code: "400", description: "Bad Request: message to edit not found") (Telegram::Bot::Exceptions::ResponseError)

This is the full code.

   Telegram::Bot::Client.run(token) do |bot|
  bot.listen do |message|
    case message
    when Telegram::Bot::Types::CallbackQuery
      case message.data
        bot.api.edit_message_text(chat_id: message.from.id, 
            message_id: message.id,
            text: "What would you like Athena to do?",
            reply_markup: tasks_keyboard()
            )

How do I reference (get the id) of the previous message to be edited?

Upvotes: 1

Views: 1099

Answers (1)

Carrein
Carrein

Reputation: 3361

message_id: message.message.message_id

I managed to get the message.id by using the above code, taken from the following thread here.

Upvotes: 1

Related Questions