如何在 asp.net 电报机器人中添加内联按钮?
How to add Inline button in asp.net telegram bot?
如何添加内联按钮,因为此代码示例不起作用?
var keyboard = new InlineKeyboardMarkup
(
new InlineKeyboardButton[][]
{
// First row
new InlineKeyboardButton[] {
// First column (Button)
InlineKeyboardButton("one", "callback1"),
// Second column (Button)
InlineKeyboardButton("two", "callback2"),
},
}
);
您需要做的就是首先定义内联键盘,然后在向用户发送任何类型的消息时使用它。要定义内联键盘,您应该在程序中使用下面的代码 class:
private static InlineKeyboardMarkup myInlineKeyboard;
然后在你的主函数中,你必须使用如下代码:
myInlineKeyboard = new InlineKeyboardMarkup()
{
InlineKeyboard = new InlineKeyboardButton[][]
{
new InlineKeyboardButton[] // First row
{
new InlineKeyboardButton("option1","CallbackQuery1"), // First column
new InlineKeyboardButton("option2","CallbackQuery2") //Second column
}
};
最后,为了查看您的嵌入式键盘,您应该在发送消息或编辑消息时使用它,例如,如果您的消息是短信,您可以使用此代码:
await Bot.SendTextMessageAsync(chatId, "Your_Text", replyMarkup: myInlineKeyboard);
我已将此代码与 Telegram.Bot API 版本 13.0.0-beta-01 一起使用,效果非常好。但是如果你想使用这个 API 的最新版本,内联键盘的代码有点不同,但与此非常相似。
我对代码进行了一些修补程序,因此您可以 copy/paste 它
InlineKeyboardMarkup myInlineKeyboard = new InlineKeyboardMarkup(
new InlineKeyboardButton[][]
{
new InlineKeyboardButton[] // First row
{
InlineKeyboardButton.WithCallbackData( // First Column
"option1", // Button Name
"CallbackQuery1" // Answer you'll recieve
),
InlineKeyboardButton.WithCallbackData( //Second column
"option2", // Button Name
"CallbackQuery2" // Answer you'll recieve
)
}
}
);
如何添加内联按钮,因为此代码示例不起作用?
var keyboard = new InlineKeyboardMarkup
(
new InlineKeyboardButton[][]
{
// First row
new InlineKeyboardButton[] {
// First column (Button)
InlineKeyboardButton("one", "callback1"),
// Second column (Button)
InlineKeyboardButton("two", "callback2"),
},
}
);
您需要做的就是首先定义内联键盘,然后在向用户发送任何类型的消息时使用它。要定义内联键盘,您应该在程序中使用下面的代码 class:
private static InlineKeyboardMarkup myInlineKeyboard;
然后在你的主函数中,你必须使用如下代码:
myInlineKeyboard = new InlineKeyboardMarkup()
{
InlineKeyboard = new InlineKeyboardButton[][]
{
new InlineKeyboardButton[] // First row
{
new InlineKeyboardButton("option1","CallbackQuery1"), // First column
new InlineKeyboardButton("option2","CallbackQuery2") //Second column
}
};
最后,为了查看您的嵌入式键盘,您应该在发送消息或编辑消息时使用它,例如,如果您的消息是短信,您可以使用此代码:
await Bot.SendTextMessageAsync(chatId, "Your_Text", replyMarkup: myInlineKeyboard);
我已将此代码与 Telegram.Bot API 版本 13.0.0-beta-01 一起使用,效果非常好。但是如果你想使用这个 API 的最新版本,内联键盘的代码有点不同,但与此非常相似。
我对代码进行了一些修补程序,因此您可以 copy/paste 它
InlineKeyboardMarkup myInlineKeyboard = new InlineKeyboardMarkup(
new InlineKeyboardButton[][]
{
new InlineKeyboardButton[] // First row
{
InlineKeyboardButton.WithCallbackData( // First Column
"option1", // Button Name
"CallbackQuery1" // Answer you'll recieve
),
InlineKeyboardButton.WithCallbackData( //Second column
"option2", // Button Name
"CallbackQuery2" // Answer you'll recieve
)
}
}
);