跳至主要內容

聊天選單按鈕:setChatMenuButton(commands、web_app、default)

用 setChatMenuButton 設定左側選單:commands / web_app / default;全域與私訊作用域;HTTPS≤2048 且不要求本 Bot 已登記 MiniApp。

一句話結論

setChatMenuButton 只設定聊天輸入框左側選單按鈕(commands / web_app / default),不會建立或移除右側 Reply Keyboard。省略 chat_id 為全域預設;帶 chat_id 時覆寫已與 Bot 互動過的私訊


總覽

輸入框左右是兩套獨立控件:左側 Menu Button(本文)與右側 Reply Keyboard 切換(見底部自訂鍵盤指南)。參數級權威以 core.mp.net/bots 為準。

左側選單 vs 右側 Reply Keyboard

  • 左側 — Menu Button:setChatMenuButton / getChatMenuButton。類型:commandsweb_appdefault

  • 右側 — Reply Keyboard:只能透過訊息 reply_markupReplyKeyboardMarkup / Remove)下發。選單 API 不會展開或隱藏它。

  • 改一側不會影響另一側。

類型:commands / web_app / default

type

效果

commands

左側展示 Bot 指令清單。

web_app

左側展示帶文案的按鈕,點擊開啟 HTTPS URL(text + web_app.url)。

default

清除該作用域的顯式覆寫(省略 menu_button 效果相同)。

同一作用域下 commandsweb_app 互斥。

作用域:省略 chat_id vs 私訊 chat_id

  • 省略 chat_id設定該 Bot 的全域選單。

  • chat_id必須是已與本 Bot 互動過私訊,對該會話覆寫。

  • getChatMenuButton 回讀(作用域規則相同)。回傳值不會描述右側 Reply Keyboard 是否可見。

web_app:任意 HTTPS ≤ 2048

以官方為準(覆蓋 PRD 表述)

Menu Button 的 web_app 接受 text 加上任意合法 HTTPS URL(最長 2048)不要求本 Bot 已登記 MiniApp、不要求 MiniApp ID。(內嵌鍵盤 / Reply Keyboard 的 web_app 歸屬規則另論,勿照搬到這裡。)

  • 按鈕文案 text 最長 64

  • URL 必須是 HTTPS

BotFather 路徑(簡述)

也可在 BotFather 的 Bot「選單按鈕 / Menu Button」設定裡配置左側選單。與 setChatMenuButton 控制的是同一側控件;需要依會話覆寫或自動化時優先用 API。

最小請求範例

POST https://call.mp.net/bot/bot<token>/setChatMenuButton
{
"menu_button": {
"type": "web_app",
"text": "Open App",
"web_app": { "url": "https://example.com/app" }
}
}

相關

  • 底部自訂鍵盤:下發、切換、一次隱藏與移除(本欄目)

  • 核心訊息方法詳解:getMe、getUpdates、sendMessage(reply_markup)

權威來源

與產品 PDF 衝突時,以 core.mp.net/bots 為準。

是否回答了您的問題?