Update and delete messages sent from your bot - Teams (2024)

  • Article

Important

The code samples in this section are based on version 4.6 and later versions of the Bot Framework SDK. If you are looking for documentation for earlier versions, see the bots - v3 SDK section in the Legacy SDKs folder of the documentation.

Your bot can dynamically update messages after sending them instead of having them as static snapshots of data. Messages can also be deleted using the Bot Framework's DeleteActivity method.

Update messages

You can use dynamic message updates for scenarios, such as poll updates, modifying available actions after a button press, or any other asynchronous state change.

It is not necessary for the new message to match the original in type. For example, if the original message contains an attachment, the new message can be a simple text message.

  • C#
  • TypeScript
  • Python
  • REST API

To update an existing message, pass a new Activity object with the existing activity ID to the UpdateActivityAsync method of the TurnContext class.

// Send initial messagevar response = await turnContext.SendActivityAsync(MessageFactory.Attachment(card.ToAttachment()), cancellationToken);var activityId = response.Id; // Fetch activity id.// MessageFactory.Text(): Specifies the type of text data in a message attachment.var newActivity = MessageFactory.Text("The new text for the activity");newActivity.Id = activityId;// UpdateActivityAsync(): A method that can participate in update activity events for the current turn.await turnContext.UpdateActivityAsync(newActivity, cancellationToken);

Now that you have updated messages, update the existing card on button selection for incoming activities.

Update cards

To update the existing card on button selection, you can use ReplyToId of incoming activity.

  • C#
  • TypeScript
  • Python
  • REST API

To update existing card on a button selection, pass a new Activity object with updated card and ReplyToId as activity ID to the UpdateActivityAsync method of the TurnContext class.

// Returns a message activity that contains an attachment.var activity = MessageFactory.Attachment(card.ToAttachment());activity.Id = turnContext.Activity.ReplyToId;// A method that can participate in update activity events for the current turn.await turnContext.UpdateActivityAsync(activity, cancellationToken);

Now that you have updated cards, you can delete messages using the Bot Framework.

Delete messages

In the Bot Framework, every message has its unique activity identifier. Messages can be deleted using the Bot Framework's DeleteActivity method.

  • C#
  • TypeScript
  • Python
  • REST API

To delete a message, pass that activity's ID to the DeleteActivityAsync method of the TurnContext class.

foreach (var activityId in _list){ // When overridden in a derived class, deletes an existing activity in the conversation. await turnContext.DeleteActivityAsync(activityId, cancellationToken);}

Code sample

The following code sample demonstrates basics of conversations:

Sample nameDescription.NETNode.jsPythonManifest
Teams Conversation BasicsThis sample shows how to use different bot conversation events available in bot framework v4 for personal and teams scope.ViewViewViewView

Next step

See also

Update and delete messages sent from your bot - Teams (2024)

FAQs

Update and delete messages sent from your bot - Teams? ›

Messages can be deleted using the Bot Framework's DeleteActivity method. To delete a message, pass that activity's ID to the DeleteActivityAsync method of the TurnContext class. To delete a message, pass that activity's ID to the deleteActivity method of the TurnContext object.

Is there a way to delete a message sent on Teams? ›

  1. Go to the chat.
  2. Hover over the message you sent and select More options .
  3. Choose Delete .
  4. Your message will be removed from the chat. If you removed the wrong message, select Undo.

Does deleting a message on Teams delete it for both people? ›

Replies (1) 

If a message is deleted after the person has seen it, it will disappear from the other person's Teams. This is the same whether the person has seen it or not.

How do I delete power automate messages? ›

So let's get started on deleting Power Automate posts in Teams.
  1. Step 1: Open the Teams App. ...
  2. Step 2: Navigate to the Channel with the Power Automate Post. ...
  3. Step 3: Find the Power Automate Post. ...
  4. Step 4: Click on the Three Dots Icon. ...
  5. Step 5: Select “Delete Message” from the Dropdown Menu.

Can admin see deleted Teams messages? ›

Deleted chat or channel messages cannot be restored directly. If you have a compliance retention policy or legal hold in place for Teams messages, an administrator can recover these from the Compliance center via eDiscovery search. If compliance hasn't been enabled, the deleted messages are gone forever!

Why can't i delete my messages on Teams? ›

There's no option to delete a full chat in Microsoft Teams. But you should be able to delete or edit your own messages. If you have no delete option in Microsoft Teams, there could be a few reasons for this. Revoked privileges: If you can't delete a sent message, an admin may have removed this ability for you.

How long does Teams keep chat history? ›

At the end of the retention period (30 days from day 1), the message is permanently deleted typically within 1-7 days after the minimum of 1 day, and then won't be returned with eDiscovery searches.

When you delete messages does it delete for the other person? ›

If you delete the message or conversation, the other person will still have a record of it. But it will appear on your phone like a new conversation. If you want to delete sent messages, you can use secure messaging apps like Telegram and Signal.

Where do deleted Teams messages go? ›

When a message is deleted in a private chat, an end-user does not have a way to recover the message, as it does not go to the Recycle Bin. It can be recovered by an administrator from the Compliance center via eDiscovery search. Not all MS Teams content is “eDiscoverable” – check this documentation for what is.

When you delete a conversation does it delete for the other person? ›

If you hide a conversation and then chat with that person again, your chat history reappears (if it's turned on). Delete conversation—Permanently deletes your copy of a conversation's history. It doesn't delete the conversation from other participants' history.

How do you Delete team chat history? ›

  1. From the Chat tab, find the chat you want to delete. Note: You can delete one-on-one, group, and meeting chats.
  2. Hover over the chat and select More options .
  3. Select Delete chat. and then confirm that you want to delete it by tapping Yes, delete. You'll then leave the meeting or group chat.

How do I remove bots from Microsoft Teams chat? ›

> Mute. next to the name of the bot you want to remove. Once you remove a bot, your teammates will no longer be able to @mention that bot in the team, and it will no longer be able to post to that team.

Can you tell if someone is on Teams mobile or desktop? ›

As far as i know, unfortunately, the status between desktop and mobile is not dependent to each other. The status is based on your activity on each devices so you will be needing to update manually the statuses for both devices.

Can you delete a text message for both people? ›

You can't delete messages, attachments, and conversations for anyone else.

How do you delete a conversation on both sides? ›

Google Messenger Delete Old Messages

You can delete old or unwanted conversations from Messages, move them into your archives, or mark all messages as read. Note: Some of the following steps only work on Android 6.0 and up. Generally, open the Message app, touch and hold each conversation, and tap Delete.

Top Articles
Latest Posts
Article information

Author: Dean Jakubowski Ret

Last Updated:

Views: 6219

Rating: 5 / 5 (50 voted)

Reviews: 89% of readers found this page helpful

Author information

Name: Dean Jakubowski Ret

Birthday: 1996-05-10

Address: Apt. 425 4346 Santiago Islands, Shariside, AK 38830-1874

Phone: +96313309894162

Job: Legacy Sales Designer

Hobby: Baseball, Wood carving, Candle making, Jigsaw puzzles, Lacemaking, Parkour, Drawing

Introduction: My name is Dean Jakubowski Ret, I am a enthusiastic, friendly, homely, handsome, zealous, brainy, elegant person who loves writing and wants to share my knowledge and understanding with you.