【问题标题】:Telegram bot ASP.NET MVC InlineKeyboardButton电报机器人 ASP.NET MVC InlineKeyboardButton
【发布时间】:2021-08-23 17:41:18
【问题描述】:

在使用 C# 的 ASP.NET MVC 中,我无法接收 CallbackQuery。我有InlineKeyoardButton,但是当我在电报机器人中点击它时,它不起作用。

一切正常,所以内联按钮不起作用。

这是我的代码:

using System;
using System.Web.Mvc;
using Telegram.Bot;
using Telegram.Bot.Args;
using Telegram.Bot.Types;
using Telegram.Bot.Types.Enums;
using Telegram.Bot.Types.ReplyMarkups;

namespace FinalBot.Controllers
{
    public class HomeController : Controller
    {
        public static long chatId;
        public static string message;
        
        public static TelegramBotClient bot;
        [HttpPost()]
        public void Index(Update update)
        {
            bot = new TelegramBotClient("bot token");

            chatId = update.Message.Chat.Id;
            message = update.Message.Text;

            if (message.Contains("start"))
            {
                InlineKeyboardButton a = new InlineKeyboardButton()
                {
                    Text = "about",
                    CallbackData = "a"
                };

                InlineKeyboardButton[] row1 =
                {
                    a
                };

                InlineKeyboardMarkup inline = new InlineKeyboardMarkup(row1);

                bot.SendTextMessageAsync(update.Message.Chat.Id, "select", replyMarkup: inline);
            }

            if (update.CallbackQuery != null)
            {
                bot.SendTextMessageAsync("myChat ID", "callback is ok");
            }
        }
    }
}    

现在当有人点击内联按钮时,什么都不会发生我尝试了很多东西我仍然无法解决问题

//帮助//

【问题讨论】:

  • 嗨。你在botfother中设置了回调延迟吗?在botfother 中检查您的机器人设置
  • 嗨。我检查了我的机器人的设置,但设置中没有回调延迟(在 botfather 中)
  • 我仔细检查了一下,有/setinlinefeedback 设置。设置那个
  • 还没有工作。你有内联按钮和回调的示例代码吗??

标签: c# asp.net-mvc bots telegram


【解决方案1】:

这不起作用,因为 MessageCallback 的更新不同,Callback 更新无法为您提供 .Message 添加对.Message 的检查或更改处理Updates 的方式,因为用一种方法完成所有操作实际上是个坏主意

if (update.Message != null) {
   // process message here
   // or
   // ProcessMessage(update.Message);
   return;
}
if (update.CallbackQuery != null) {
   // process callback query here
   // or
   // ProcessCallback(update.CallbackQuery);
   return;
}

【讨论】:

    猜你喜欢
    • 2020-10-05
    • 2021-10-28
    • 1970-01-01
    • 2017-08-18
    • 2018-07-22
    • 2020-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多