Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

microsoft teams - how to delete the posted adaptive messge in MSteams using c# code

the below code is getting error while deleting the message based on the channel id public async Task DeleteSentNotification( string conversationId, string recipientId, string serviceUrl, string tenantId, string name) { // Set the service URL in the trusted list to ensure the SDK includes the token in the request. MicrosoftAppCredentials.TrustServiceUrl(serviceUrl);

        var conversationReference = new ConversationReference
        {
            ServiceUrl = serviceUrl,
           
            Conversation = new ConversationAccount
            {
                TenantId = tenantId,
                Id = conversationId,
                name = name,(AdaptiveCard Json)
            },
        };
        await this.botAdapter.ContinueConversationAsync(
          botAppId: this.microsoftAppId,
          reference: conversationReference,
          callback: async (turnContext, cancellationToken) =>
          {
             try
              {
                    // Delete message.
                   await turnContext.DeleteActivityAsync(conversationReference);
              }
              catch (ErrorResponseException e)
              {
                  var errorMessage = $"{e.GetType()}: {e.Message}";
              }
          },
          cancellationToken: CancellationToken.None);

        // return response;
    }
question from:https://stackoverflow.com/questions/65860117/how-to-delete-the-posted-adaptive-messge-in-msteams-using-c-sharp-code

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

DeleteActivityAsync has two overloads, but they're both basically aimed towards deleting an "Activity" (i.e. a specific message or thread). If you want to use the overload that takes in a conversationReference, then that means your conversationReference needs to have the ActivityId set (see here for more on the property). Alternatively, you can use the overload that takes in an activityId (it looks like this: public System.Threading.Tasks.Task DeleteActivityAsync (string activityId, System.Threading.CancellationToken cancellationToken = default);), and then you need to pass in the activityId.

Essentially, as stated at the beginning of my answer, you're telling it to delete an "Activity", but you're not telling it which Activity. See here for the docs: https://docs.microsoft.com/en-us/dotnet/api/microsoft.bot.builder.turncontext.deleteactivityasync?view=botbuilder-dotnet-stable


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...