Search code examples
botframework

how to properly delete or update activities on bot framework?


I can't find a guide on documentation for make this possible. I tried to use TurnContext.UpdateActivity, but I'm getting an error.

My code:

IMessageActivity responseActivity = MessageFactory.Text("Test ctm");
responseActivity.Id = userProfile.messageToDelete;
responseActivity.Conversation = turnContext.Activity.Conversation;
responseActivity.ServiceUrl = turnContext.Activity.ServiceUrl;
//await turnContext.DeleteActivityAsync(userProfile.messageToDelete, cancellationToken: cancellationToken);
await turnContext.UpdateActivityAsync(responseActivity, cancellationToken);

The last line throws the exception:

Microsoft.Bot.Schema.ErrorResponseException: 'Operation returned an invalid status code 'NotFound''

What could be wrong? Can you share any code sample?


Solution

  • The Emulator is built on top of Web Chat, and unfortunately, Web Chat does not support updating or deleting activities at the moment. For more details, take a look at this comment in Web Chat's source code and this open issue in the Web Chat repository for adding support for deleteActivity and updateActivity.

    Hope this helps!