我想使用自定义键盘来获取选定的选项。如何从电报机器人的键盘输入中得到响应?
如何获取选定的选项?有没有例子?
我的问题是由 “节点的电报僵尸API”
在这里找到答案:How to get the response of the keyboard selection?
是否有C#的任何解决方案?
我想使用自定义键盘来获取选定的选项。如何从电报机器人的键盘输入中得到响应?
如何获取选定的选项?有没有例子?
我的问题是由 “节点的电报僵尸API”
在这里找到答案:How to get the response of the keyboard selection?
是否有C#的任何解决方案?
当您拨打SendTextMessageAsync
时,您将传递指定“自定义回复键盘”的IReplyMarkup
对象。我不太了解Telegram Bot API,但这看起来与您链接的GitHub问题所提及的功能相同。
似乎有several implementations listed in the API documentation。我怀疑要么InlineKeyboardMarkup
或ReplyKeyboardMarkup
是你在找什么。
我在寻找ReplyKeyboardMarkup –
要创建自定义键盘,您必须发送短信并通过IReplyMarkup
。所选选项作为可在OnMessage
事件中处理的消息发送。当您将ReplyKeyboardHide
设置为回复标记时,您可以隐藏自定义键盘。
下面是一个例子:
private const string FirstOptionText = "First option";
private const string SecondOptionText = "Second option";
private async void BotClientOnMessage(object sender, MessageEventArgs e)
{
switch (e.Message.Text)
{
case FirstOptionText:
await BotClient.SendTextMessageAsync(e.Message.Chat.Id, "You chose the first option", replyMarkup:new ReplyKeyboardHide());
break;
case SecondOptionText:
await BotClient.SendTextMessageAsync(e.Message.Chat.Id, "You chose the second option", replyMarkup:new ReplyKeyboardHide());
break;
default:
await BotClient.SendTextMessageAsync(e.Message.Chat.Id, "Hi, select an option!",
replyMarkup: new ReplyKeyboardMarkup(new[]
{
new KeyboardButton(FirstOptionText),
new KeyboardButton(SecondOptionText),
}));
break;
}
}
我希望这有帮助!
您使用哪个库访问Telegram Bot API? –
我使用telegram.bot –