簡體   English   中英

用戶在Telegram Bot API中單擊后如何隱藏ReplyKeyboardMarkup

[英]How to hide ReplyKeyboardMarkup after user click in Telegram Bot API

我正在使用Node.js telegram-bot-api

理念:

  1. 使用一個按鈕顯示自定義鍵盤 - “分享我的電話號碼”。
  2. 當用戶單擊此按鈕時,應發送聯系人並從屏幕上刪除按鈕。

這是我正在使用的代碼:

bot.sendMessage({
    text: 'Please give us your phone number',
    reply_markup: JSON.stringify({
        keyboard: [
            [{
                text: 'Share my phone number',
                request_contact: true
            }]
        ],
        resize_keyboard: true,
        one_time_keyboard: true
    })
});

問題:

  • 當用戶點擊“分享我的電話號碼”按鈕時,它會共享他的聯系人,但即使在此之后按鈕也可見。
  • 當我沒有使用request_contact標志時, one_time_keyboard正常工作(在使用后隱藏按鈕),但即使在這種情況下它只是隱藏按鈕,所以用戶可以點擊一個圖標將其帶回屏幕,這根本不好。

如果我在這里做錯了,請告訴我。 謝謝

找到了。

這是一個解決方案:

bot.sendMessage({
    chat_id: message.chat.id,
    text: 'Some text...',
    reply_markup: JSON.stringify({
        hide_keyboard: true
    })
});

hide_keyboard已更名為remove_keyboardAPI 2.3

bot.sendMessage({
    chat_id: message.chat.id,
    text: 'Some text...',
    reply_markup: JSON.stringify({
        remove_keyboard: true
    })
});

您應該使用editMessageReplyMarkup並在收到客戶端用戶的點擊后使用空字符串( '' )更新該消息的replyMarkup

更新這適用於內聯鍵盤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM