You can now delete (and un-delete) Microsoft Teams messages via Graph APIs
There are two new API endpoints that developers can now use when working with Microsoft Teams chat messages.
These mirror behavior that has been available in the Teams client for a while: the ability to delete a message, and then un-delete it if required).
A new method has been added to “soft delete” messages. which can now programmatically be done on any of one of:
- One-to-one or group chats
- channel chats
- replies to chat messages
Either type has a slightly different endpoint URL, because the location of the chatMessage is in slightly different places.
Slightly confusingly, Microsoft have chosen not to use the DELETE method, but instead use a POST method to a /softDelete method with an empty body. So, the three different delete calls one could make, for each of the message types above is (in order):
- POST /users/{userId}/chats/{chatsId}/messages/{chatMessageId}/softDelete
- POST /teams/{teamsId}/channels/{channelId}/messages/{chatMessageId}/softDelete
- POST /teams/{teamId}/channels/{channelId}/messages/{messageId}/replies/{replyId}/softDelete
You will need either ChannelMessage.ReadWrite or ChatMessage.ReadWrite (based on where the chat is located).
Important note: this call is only for delegated permissions right now. There are no application permissions for these calls, and no way for an application to delete messages without the user being present.
Un-delete that soft delete
As is made very clear by the name of the API call, this is a soft-deletion, and there is a way to reverse the decision and retrieve any deleted messages.
For each of the /softDelete method calls, there is a corresponding /undoSoftDelete method. Same POST method. Same empty body.
Right now, both of these new methods are only available on the /beta endpoint, and are not yet Generally Available.