Reputation: 53
I have created a notification only bot using bot framework and following the documentation in the below link. https://learn.microsoft.com/en-us/microsoftteams/platform/bots/how-to/conversations/send-proactive-messages?tabs=dotnet
now, I want an option to delete a proactive notification sent by the bot. I looked into the following link but as far as I can tell, this is only for the conversation bot which creates turn context and activity Id. https://learn.microsoft.com/en-us/microsoftteams/platform/bots/how-to/update-and-delete-bot-messages?tabs=dotnet
I need to delete the notification sent to all the installed users. Is there any way to achieve this ?
Upvotes: 1
Views: 168
Reputation: 1039
When sending the proactive notification, keep track of the sent messages by storing their message IDs or conversation references.
To delete a proactive notification, use the UpdateActivityAsync method to update the original message with a deletion indicator. You can set the text property of the activity to a specific value (e.g., "This message has been deleted") or remove the content of the message.
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);}
Upvotes: 1