c# - 在 C# Telegram Bots 中使用键盘编辑短信

标签 c# telegram telegram-bot

我使用内联键盘发送了一条消息(使用 SendTextMessageAsyncInlineKeyboardMarkup)。 当我第一次尝试编辑时 - EditMessageTextAsync(使用 InlineKeyboardMarkup)方法工作正常,但是当我第二次尝试修改此消息时,我得到了

Bad Request: message is not modified.

代码:

response = string.Format("...");
rkm = new InlineKeyboardMarkup();
//...
rkm.InlineKeyboard = new[]
{
    new[] { InlineKeyboardButton.WithCallbackData("...", "/filters") }
};
await client.EditMessageTextAsync(update.CallbackQuery.Message.Chat.Id, update.CallbackQuery.Message.MessageId, response, replyMarkup: rkm);

异常:

Bad Request: message is not modified at Telegram.Bot.TelegramBotClient.d__109`1.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) at AutoSearch.Notifications.Sources.Telegram.TelegramBot.d__7.MoveNext()

最佳答案

如果您想编辑键盘,请使用EditMessageReplyMarkupAsync

否则,如果您想编辑消息内容键盘,请使用EditMessageTextAsync

异常示例:

// Defining Message data
string text = "<b>Hello World</b>";
int myChatId = 142536987; // Some chat
InlineKeyboardButton btn = InlineKeyboardButton.WithCallbackData("DoSomething");

// Sending message
Message msg = await SendTextMessageAsync(myChatId, text, ParseMode.Html, true, false, 0, btn);



// New keyboard for message
InlineKeyboardButton newBtn = InlineKeyboardButton.WithCallbackData("Return");

// DON'T DO THAT:
// EXCEPTION!
//>>> MESSAGE IS NOT MODIFIDE!
// You must change the text...
msg = await EditTextMessageAsync(msg.Chat, msg.MessageId, text, true, newBtn);


// True way to edit the keyboard without text
msg = await EditMessageReplyMarkup(msg.Chat, msg.MessageId, newBtn);

关于c# - 在 C# Telegram Bots 中使用键盘编辑短信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47134866/

相关文章:

ffmpeg 将音频文件流式传输到 Telegram rtmp 服务器

python-2.7 - 如何删除回复键盘( Telegram Bot )

c# - 访客和管理员问题的表单登录

c# - 迁移到异步 : Repository

node.js - npm install 上缺少目录和文件

java - 如何在 Java 中的 Telegram bot 的 textview 上设置超链接?

android - 使用 Telegram bot api 创建简单的聊天

c# - 处理长时间运行的 WCF [OperationContract(IsOneWay = true)]

c# - 使用 WPF 和 XAML 以及数据绑定(bind)查看设计 View 中的 UI 更改?

c# - 保存发送给机器人的用户消息并将完成的表格发送给其他用户