Share via

Can we use the edit message option of teams in bot

lakshmi 821 Reputation points
2023-12-15T04:47:21.3933333+00:00

Hi Team,

I wanted to use the same team edit message option for a chatbot. We have personal chats and team channels. Personal chat users can send messages to teams channels.

In normal personal chat, we can send messages and edit afterward.

The same can be done in bot, but the edited message will not be resend to the teams channel or to personal chat.

Can we implement the same feature in bot also

Microsoft Teams | Development
Microsoft Teams | Development

Building, integrating, or customizing apps and workflows within Microsoft Teams using developer tools and APIs

Microsoft Teams | Microsoft Teams for business | Other

2 answers

Sort by: Most helpful
  1. Prasad-MSFT 10,471 Reputation points Microsoft External Staff Moderator
    2023-12-19T12:57:53.96+00:00

    When a message is edited by a bot, the edited message will not be automatically resent to the Teams channel or personal chat.

    You can use the updateActivity method from the Bot Framework SDK to edit message. This method allows you to update the content of a previously sent message.

    public async Task OnMessageActivityAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken)
    {
        // Get the original message
        var originalMessage = turnContext.Activity;
    
        // Update the message content
        originalMessage.Text = "This is the updated message.";
    
        // Update the message using the updateActivity method
        await turnContext.UpdateActivityAsync(originalMessage, cancellationToken);
    
        // Send a confirmation message
        await turnContext.SendActivityAsync("Message updated successfully.", cancellationToken: cancellationToken);
    }
    

    Ref: https://learn.microsoft.com/en-us/microsoftteams/platform/bots/how-to/update-and-delete-bot-messages?tabs=dotnet

    Thanks, 

    Prasad Das


    If the response is helpful, please click "Accept Answer" and upvote it. You can share your feedback via Microsoft Teams Developer Feedback link. Click here to escalate.

    Was this answer helpful?


  2. ChetanSharmamsft 1,036 Reputation points Microsoft External Staff Moderator
    2023-12-15T06:48:34.49+00:00

    Hello lakshmi -
    You can capture edit message activity:
    When you edit a message, the bot gets a notification of the edit message activity.

    To get an edit message activity notification in a bot, you can override OnTeamsMessageEditAsync handler.

    Also, based on it, you can again send the appropriate message to the target audience.

    Reference doc link:
    https://learn.microsoft.com/en-us/microsoftteams/platform/bots/how-to/conversations/conversation-messages?tabs=dotnet1%2Capp-manifest-v112-or-later%2Cdotnet2%2Cdotnet3%2Cdotnet4%2Cdotnet5%2Cdotnet#get-edit-message-activity

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.