Removing a message keyboard with the puzzlebot API

Views:12

Sometimes, after processing a request or completing an action, you need to remove the keyboard from a message that has already been sent. There is a method for this: tg.editMessageReplyMarkup. Below you'll find detailed instructions.

Written by Antony Pavlov, a developer of Telegram bots and mini apps.

Request

Once the request is executed, the keyboard is removed from the specified message.

https://api.puzzlebot.top/?token={{token_puzzlebot}}&method=tg.editMessageReplyMarkup&chat_id=-{{chat_id}}&message_id={{message_id}}&reply_markup=()

Request parameters

  1. token_puzzlebot - your bot's API token. You can get it in:

Settings → Integrations → Incoming requests → Generate API token

We recommend saving the token to a global variable and using it in all your requests. For example: {{token_puzzlebot}}

2. chat_id - the ID of the chat that contains the message. You can get it from the link to the message in the chat itself.

For example: https://t.me/c/2039518651/8020/22961
From the link, take: 2039518651
To use it in the API, add the -100 prefix: -1002039518651
This is the value used in the chat_id parameter.

3. message_id - the ID of the specific message whose keyboard you want to remove.

For example: https://t.me/c/2039518651/8020/22961
Message ID: 22961
This is the value to pass in the message_id parameter.

Getting the message ID automatically

puzzlebot provides these system variables:

LAST_BOT_MESSAGE_ID_****** LAST_USER_MESSAGE_ID_******

You often need to know in advance the ID of the next message the bot will send. This is handy when you want to write the message ID right into a button of that same message, so that pressing the button later removes the keyboard.

Use this formula:

if(LAST_BOT_MESSAGE_ID_****** > LAST_USER_MESSAGE_ID_******, LAST_BOT_MESSAGE_ID_******, LAST_USER_MESSAGE_ID_******)+1

How the formula works:

  1. Compares the IDs of the bot's and the user's last messages

  2. Picks the larger ID

  3. Adds 1

  4. Returns the ID of the next message

Usage example

Request to remove the keyboard:

https://api.puzzlebot.top/?token=YOUR_TOKEN&method=tg.editMessageReplyMarkup&chat_id=-1002039518651&message_id=22961&reply_markup=()

After the request is executed:

  • the message stays in the chat

  • the keyboard is removed

  • the user can no longer press the buttons in this message

The most common use cases:

  • processing requests

  • closing tickets

  • confirming user actions

  • disabling old buttons after an option has been chosen

  • preventing a button from being pressed twice

This approach helps you avoid processing the same action twice and makes the bot's interface clearer for users.

Was this page helpful?