您最好将 inlinekeyboard 用于“是/否”和您想要在按下“是”或“否”后显示的前一个键盘。这样,您可以编辑是/否内联键盘消息并显示新键盘。
您可以发送 inlineKeyboard 并通过检查它的 callBackQuery.Data 参数,您可以再次编辑发送的消息并显示您的新消息。
下面是一个示例更新消息 json:
{"update_id":14603298,
"callback_query":
{
"id": "479899181065761766",
"from": {
"id": 111735238,
"first_name": "eric",
"username": "...."
},
"message": {
"message_id": 22,
"from": {
"id": 3576731383,
"first_name": "the_bot_name",
"username": "mybot_bot"
},
"chat": {
"id": 111745258,
"first_name": "eric",
"username": "....",
"type": "private"
},
"date": 1492113810,
"text": "sent message"
},
"chat_instance": "5419183837652256438",
"data": "yes"
}}
因此,当用户单击是或否时,您将收到一条更新消息。基于上述更新消息,chatid 和 messageid 是已知的,因此使用 c# Telegram.Bot 库编辑代码如下:
var chatid= 111745258;
var messageid=22;
TelegramBotClient api = new TelegramBotClient("YOUR_TOKEN");
var new_keyboard = new InlineKeyboardMarkup(
new[]
{
new[]
{
new InlineKeyboardButton("step_1","step1") ,
},
new[]
{
new InlineKeyboardButton("step_2","step2"),
new InlineKeyboardButton("step_3","step3"),
},
new[]
{
new InlineKeyboardButton("step_4","step4"),
}
});
api.EditMessageReplyMarkupAsync(chatid, messageid, replyMarkup: new_keyboard);