【发布时间】:2017-01-05 14:55:51
【问题描述】:
我开始开发电报机器人应用程序。我在向用户发送消息时使用自定义键盘。我需要知道的是如何从键盘按钮单击中接收回复,以及如何响应用户对特定按钮的单击。
在阅读电报机器人 api 后,我想到我必须从 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);
}
当用户单击特定按钮时,我想响应它。
我想知道:
我的方向是否正确?
与机器人聊天时请求响应流如何工作?
如何接收键盘按钮单击的响应,并针对该按钮单击回复用户。如果使用 json,如果有人用 c# 中的示例进行指导会很有帮助?
有没有办法触发键盘按钮点击的回调 url,可以在服务器上解决,然后根据该按钮点击向用户发送特定的回复?
有人可以指导我正确的方向吗?
【问题讨论】:
标签: c# json telegram telegram-bot