Skip to content

getChatMenuButton

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_idIntegerOptional
Unique 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

CodeErrorCause
400Bad Request: chat not foundInvalid chat_id — must be an existing private chat the bot has had contact with
400Bad Request: method is available for private chats onlychat_id points to a group or channel — only private chats are supported
429Too Many Requests: retry after NRate limit hit — check retry_after, use the auto-retry plugin

Tips & Gotchas

  • Only works for private chats. Passing a group or channel chat_id returns an error. The menu button concept applies only to the bot's 1-on-1 chats with users.
  • Omit chat_id entirely to read the global default. When no chat_id is 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 /commands list), MenuButtonWebApp (opens a Web App URL), or MenuButtonDefault (Telegram's own default behaviour).
  • Pair with setChatMenuButton for read-modify-write flows. Read the current button with getChatMenuButton, modify as needed, then write back with setChatMenuButton.
  • 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)