如何删除 Microsoft 团队机器人中仅通知机器人发送的主动消息?

问题描述 投票:0回答:1

我使用机器人框架创建了一个仅通知机器人,并遵循以下链接中的文档。 https://learn.microsoft.com/en-us/microsoftteams/platform/bots/how-to/conversations/send-proactive-messages?tabs=dotnet

现在,我想要一个选项来删除机器人发送的主动通知。我查看了以下链接,但据我所知,这仅适用于创建回合上下文和活动 ID 的对话机器人。 https://learn.microsoft.com/en-us/microsoftteams/platform/bots/how-to/update-and-delete-bot-messages?tabs=dotnet

我需要删除发送给所有已安装用户的通知。有什么办法可以实现这个目标吗?

botframework microsoft-teams teams-toolkit
1个回答
0
投票
  1. 发送主动通知时,通过存储消息 ID 或对话引用来跟踪已发送的消息。

  2. 要删除主动通知,请使用 UpdateActivityAsync 方法使用删除指示符更新原始消息。您可以将活动的文本属性设置为特定值(例如,“此消息已被删除”)或删除消息的内容。

    private async Task DeleteNotificationAsync(string messageId, string serviceUrl){
    var conversationReference = new ConversationReference
     {
         ServiceUrl = serviceUrl,
         Conversation = new ConversationAccount { Id = messageId }
     };
     var botAdapter = (BotFrameworkAdapter)_adapter;
     var botCallback = new BotCallbackHandler(BotCallback);
     await botAdapter.ContinueConversationAsync(_appId, conversationReference, botCallback, default(CancellationToken));
     // Update the original message with a deletion indicator
     var updatedMessage = new Activity
     {
         Id = messageId,
         Type = ActivityTypes.Message,
         Text = "This message has been deleted"
     };
     await botAdapter.UpdateActivityAsync(conversationReference, updatedMessage);}
    
© www.soinside.com 2019 - 2024. All rights reserved.