【问题标题】:Telegram bot api receive response from keboard buttonsTelegram bot api 从键盘按钮接收响应
【发布时间】: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);
}

当用户单击特定按钮时,我想响应它。

我想知道:

  1. 我的方向是否正确?

  2. 与机器人聊天时请求响应流如何工作?

  3. 如何接收键盘按钮单击的响应,并针对该按钮单击回复用户。如果使用 json,如果有人用 c# 中的示例进行指导会很有帮助?

  4. 有没有办法触发键盘按钮点击的回调 url,可以在服务器上解决,然后根据该按钮点击向用户发送特定的回复?

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

【问题讨论】:

标签: c# json telegram telegram-bot


【解决方案1】:

请看这个例子:

Telegram.Bot.Example in c#

【讨论】:

    【解决方案2】:

    很遗憾,您不能在ReplyKeyboardMarkup 中按照您的意愿执行此操作。

    因为这种类型的点击键盘会在点击按钮上发送带有相同文本的消息。

    如果用户点击按钮 1,电报将发送带有文本“按钮 1”的消息。

    ReplyKeyboardMarkup 在您需要联系、投票或位置请求时很有用。


    我建议您使用InlineKeyboardMarkup,您将在OnCallbackQuery 事件中接收数据

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-15
      • 1970-01-01
      • 1970-01-01
      • 2016-08-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多