我正在尝试使用节点js编写电报机器人,并且正在向用户发送键盘:
var keyboards = {
main_menu: {
reply_markup: {
keyboard: [
[{text: "Cards"}, {text: "Progress"}],
[{text: "Warning"}, {text: "Help"}]
]
}
}
};
bot.onText(/\/keyboard/, (msg) => {
console.log(keyboards.main_menu);
bot.sendMessage(msg.from.id, "Main menu", keyboards.main_menu);
console.log(keyboards.main_menu);
});
这就是我在控制台上所拥有的:
{ reply_markup: { keyboard: [ [Array], [Array] ] } }
{ reply_markup:
'{"keyboard":[[{"text":"Cards"},{"text":"Progress"}],[{"text":"Warning"}, {"text":"Help"}]]}',
chat_id: 276984822,
text: 'Main menu' }
所以我不知道为什么,但是在发送键盘后,Telegram将chat_id
和text
添加到我的键盘上。我该怎么办?
答案 0 :(得分:0)
我发现了解决方法-您应该像这样发送键盘:
bot.sendMessage(msg.from.id, "Main menu", {reply_markup: keyboards.main_menu});
实际上,下一个变体也会起作用:
bot.sendMessage(msg.from.id, "Main menu", {reply_markup: keyboards.main_menu.reply_keyboard});