首页 文章

Telegram bot api从键盘按钮接收响应

提问于
浏览
0

我开始开发电报机器人应用程序 . 我在向用户发送消息时使用自定义键盘 . 我需要知道的是如何从键盘按钮点击收到回复,我如何响应用户的特定按钮点击 .

阅读电报bot 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);
}

我有这个,我想在用户点击特定按钮时回复 .

我想知道:

  • 我是否朝着正确的方向前进?

  • 与bot聊天时请求响应流如何工作?

  • 如何收到键盘按钮点击的响应并回复用户单击该按钮 . 如果使用json,如果某人在c#中引用了一个例子会有所帮助吗?

  • 有没有办法触发键盘按钮点击的回调网址,可以在服务器上解析,然后根据点击按钮发送给用户?

有人可以指导我正确的方向吗?

1 回答

相关问题