使用 Bot Framework Emulator (v4) 更新已发送的自适应卡对我不起作用

Using Bot Framework Emulator (v4) updating an already sent adaptive card doesn't work for me

我尝试更新一张已发送的 message/adaptive 卡...或或多或少将已发送的自适应卡换成另一张。因此,我正在使用 UpdateActivityAsync() 函数。 在文档 (https://docs.microsoft.com/en-us/microsoftteams/platform/bots/how-to/update-and-delete-bot-messages?tabs=dotnet) 中,更新已发送消息或更新卡片的建议方法如下:

To update an existing message, pass a new Activity object with the existing activity ID to the UpdateActivityAsync method of the TurnContext class. For more information, see TurnContextClass.

var newActivity = MessageFactory.Text("The new text for the activity");
newActivity.Id = activityId; await
turnContext.UpdateActivityAsync(newActivity, cancellationToken);

To update existing card on a button selection, pass a new Activity object with updated card and ReplyToId as activity ID to the UpdateActivityAsync method of the TurnContext class. See TurnContextClass.

var activity = MessageFactory.Attachment(card.ToAttachment());
activity.Id = turnContext.Activity.ReplyToId; await
turnContext.UpdateActivityAsync(activity, cancellationToken);

这正是我想要做的。在 OnMembersAddedAsync() 函数中,我发送包含特定卡片的消息。对应的message/activityid保存在class成员_msgID中。然后,在用户按下该卡片上的提交按钮后,将调用 OnMessageActivityAsync() 函数并在其中创建一个新的 message/activity。将新消息的 ID 设置为存储在 (_msgId) 上的旧消息并调用更新函数,没有任何反应......甚至没有错误消息“机器人遇到错误或错误。”左右...

private static string _msgID = "";

protected override async Task OnMembersAddedAsync(IList<ChannelAccount> membersAdded, ITurnContext<IConversationUpdateActivity> turnContext, CancellationToken cancellationToken)
{
  var cardAttachment = CreateAdaptiveCardAttachment(Path.Combine(".", "Resources", "FeelingsCard.json"));
  var oldActivity = MessageFactory.Attachment(cardAttachment);
  await turnContext.SendActivityAsync(oldActivity, cancellationToken);

  _msgID = oldActivity.Id;
}

protected override async Task OnMessageActivityAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken)
{
  var newActivity = MessageFactory.Attachment(CreateAdaptiveCardAttachment(Path.Combine(".", "Resources", "EmotionsCard.json")));
  newActivity.Id = _msgID;
                    
  await turnContext.UpdateActivityAsync(newActivity, cancellationToken);
}

private static Attachment CreateAdaptiveCardAttachment(string filePath)
{
  var adaptiveCardJson = File.ReadAllText(filePath);
  var adaptiveCardAttachment = new Attachment()
  {
    ContentType = "application/vnd.microsoft.card.adaptive",
    Content = JsonConvert.DeserializeObject(adaptiveCardJson),
  };
  return adaptiveCardAttachment;
}

我是不是做错了什么或者我错过了什么?

非常感谢您的帮助!

模拟器是 Direct Line 客户端。 UpdateActivityAsync 适用于 Teams,但不适用于模拟器 (Webchat/Directline)。

https://docs.microsoft.com/en-us/azure/bot-service/bot-service-channels-reference?view=azure-bot-service-4.0#message-update

进行测试;您将不得不使用 Teams 和 Ngrok.