getChatMenuButton
Returns: MenuButtonOfficial docs ↗
Use this method to get the current value of the bot's menu button in a private chat, or the default menu button. Returns MenuButton on success.
Parameters
chat_idIntegerOptionalUnique identifier for the target private chat. If not specified, default bot's menu button will be returned
Returns
On success, the MenuButton object is returned.
GramIO Usage
ts
// Get the default menu button (no chat_id = global default)
const defaultButton = await bot.api.getChatMenuButton({});
console.log(`Default menu button type: ${defaultButton.type}`);ts
// Read the menu button configured for a specific private chat
bot.command("menuinfo", async (ctx) => {
const button = await bot.api.getChatMenuButton({
chat_id: ctx.chat.id,
});
if (button.type === "web_app") {
await ctx.send(`Menu opens Web App: ${button.web_app.url}`);
} else if (button.type === "commands") {
await ctx.send("Menu shows the bot command list.");
} else {
await ctx.send("Using Telegram's default menu button.");
}
});ts
// Audit whether a private chat has a custom menu button vs the global default
async function hasCustomMenuButton(chatId: number) {
const [chatButton, defaultButton] = await Promise.all([
bot.api.getChatMenuButton({ chat_id: chatId }),
bot.api.getChatMenuButton({}),
]);
return chatButton.type !== defaultButton.type;
}Errors
| Code | Error | Cause |
|---|---|---|
| 400 | Bad Request: chat not found | Invalid chat_id — must be an existing private chat the bot has had contact with |
| 400 | Bad Request: method is available for private chats only | chat_id points to a group or channel — only private chats are supported |
| 429 | Too Many Requests: retry after N | Rate limit hit — check retry_after, use the auto-retry plugin |
Tips & Gotchas
- Only works for private chats. Passing a group or channel
chat_idreturns an error. The menu button concept applies only to the bot's 1-on-1 chats with users. - Omit
chat_identirely to read the global default. When nochat_idis provided, the method returns the default menu button shown to all private-chat users who don't have a per-chat override. - Three possible button types. The result will be
MenuButtonCommands(shows the/commandslist),MenuButtonWebApp(opens a Web App URL), orMenuButtonDefault(Telegram's own default behaviour). - Pair with
setChatMenuButtonfor read-modify-write flows. Read the current button withgetChatMenuButton, modify as needed, then write back withsetChatMenuButton. - Per-chat overrides take precedence over the global default. A chat-specific button is shown instead of the default; if no override exists, the default is used.
See Also
- setChatMenuButton — set the menu button for a chat or the default
- MenuButton — the returned union type (
MenuButtonCommands,MenuButtonWebApp,MenuButtonDefault)