我开始开发电报机器人应用程序。我在向用户发送消息时使用自定义键盘。我需要知道的是如何从键盘按钮点击接收回复,以及如何响应用户的特定按钮点击。
读完电报后,我知道我必须从json中的电报api获取更新,我发现很难通过getUpdate方法反序列化json对象。
我想知道在用户键盘按钮上点击我将通过json getUpdate方法接收更新,通过反序列化我必须在c#代码的帮助下用特定消息响应user_id,这是一个正确的流程我要前往。我点了github的东西,但我没有得到它。
public async Task sndmsg()
{
var Bot = new Api("MY_TELEGRAM_TOKEN");
var rkm = new Telegram.Bot.Types.ReplyMarkups.ReplyKeyboardMarkup();
//rkm.ResizeKeyboard = true;
rkm.Keyboard = new Telegram.Bot.Types.KeyboardButton[][]
{
new Telegram.Bot.Types.KeyboardButton[]
{
new Telegram.Bot.Types.KeyboardButton("button 1")
},
new Telegram.Bot.Types.KeyboardButton[]
{
new Telegram.Bot.Types.KeyboardButton("button 2")
},
new Telegram.Bot.Types.KeyboardButton[]
{
new Telegram.Bot.Types.KeyboardButton("button 3")
},
new Telegram.Bot.Types.KeyboardButton[]
{
new Telegram.Bot.Types.KeyboardButton("button 4")
}
};
string cht_id = "201520743";
string txt = "this is keyboard in reply";
await Bot.SendTextMessage(cht_id, txt, false, false, 0, rkm);
}
我有这个,我想在用户点击特定按钮时回复。
我想知道:
我是否朝着正确的方向前进?
与bot聊天时请求响应流如何工作?
如何收到键盘按钮点击的响应,并回复用户单击该按钮。如果使用json,如果有人在c#?
有没有办法触发键盘按钮点击的回调网址,可以在服务器上解析,然后根据点击按钮发送给用户?
有人可以指导我朝正确的方向发展吗?
答案 0 :(得分:0)
请看这个例子:
答案 1 :(得分:0)
很遗憾,您无法在ReplyKeyboardMarkup
中按照自己的意愿进行操作。
因为这种类型的键盘单击会在单击的按钮上发送带有相同文本的消息。
如果用户单击按钮1 ,则电报将发送带有“按钮1”文本的消息。
但是ReplyKeyboardMarkup
在您需要请求联系,投票或位置时很有用。
我建议您使用InlineKeyboardMarkup
,以便在OnCallbackQuery
事件中接收数据