Share via

Replace Image files with bot using API in MS Teams chat

Kalinga Somana 25 Reputation points
2023-12-12T04:31:33.94+00:00

Hi Everyone,

We are developing an MS Teams bot where we have a use case to replace an Image file with another Image file. We have implemented the scenario using the SharePoint APIs. But there is an issue with it. If we download the file from the SharePoint list of files, we get the replaced file but if we try to download the file from Teams Chat Preview, we can still download the original file, not the replaced one.

I have looked over the network logs, the image file is getting saved in two different endpoints (SharePoint and asyncgw.teams.microsoft.com) and asyncgw.teams.microsoft.com is used for previewing and downloading the file from the teams chat.

Is there any way we can point the download URL in MS Teams image preview to the SharePoint image URL or can we replace the file in asyncgw.teams.microsoft.com with some API call?

Thanks!

Microsoft Teams | Development
Microsoft Teams | Development

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

Microsoft Security | Microsoft Graph
0 comments No comments

1 answer

Sort by: Most helpful
  1. Prasad-MSFT 10,496 Reputation points Microsoft External Staff Moderator
    2023-12-12T05:45:07.7466667+00:00

    When you replace a file using the SharePoint APIs, the file is updated in the SharePoint document library. However, the Teams chat preview may still show the original file until the cache is refreshed.

    To address this issue, you can try the following approaches:

    1. Clear the cache: You can try clearing the cache in Teams to force it to fetch the latest version of the file. This can be done by signing out and signing back into Teams or by clearing the Teams cache from the settings.
    2. Use the Graph APIs to update the file in Teams: Instead of relying on the SharePoint APIs alone, you can also use the Graph APIs to update the file in Teams. The Graph APIs allow you to send chat messages with file attachments, which can be used to update the file in the Teams chat. By sending a new chat message with the updated file attachment, you can ensure that the latest version of the file is displayed in the Teams chat preview.
    POST /v1.0/teams/{teamId}/channels/{channelId}/messages
    Content-Type: application/json
    
    {
      "body": {
        "contentType": "html",
        "content": "<attachment id=\"{attachmentId}\"></attachment>"
      },
      "attachments": [
        {
          "@odata.type": "#microsoft.graph.fileAttachment",
          "name": "Updated Image",
          "contentBytes": "{base64EncodedFileContent}"
        }
      ]
    }
    

    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.

    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.