I have a requirement where I need to download files/images/attachments from an existing Microsoft Teams Chat (s) so I have a few questions...
I've got my "way" of doing this, but I'm not sure if it's the "best" way so I suppose I am (please) asking you for some guidance on how to do this correctly.
With regards to my solution for downloading images of a one-on-one Chat I do these calls
- GET /chats (this returns all one-on-one chats for the current user)
- GET /chats/{chat-id}/messages
- GET /chats/{chat-id}/messages/{message-id}/hostedContents
- GET /chats/{chat-id}/messages/{message-id}/hostedContents/{hosted-content-id}/$value
Now with regards to attachments, the documentation states "chatMessageHostedContent resource type. Represents Teams content hosted in a chat message, such as images or code snippets. File attachments are not hosted content; they are stored in SharePoint or OneDrive."
So if I understand this right, if I attach a .pdf file in a Chat, this gets stored in SharePoint or OneDrive. In my use case the JSON response (when i get a list of one-on-one Chat messages or a specific message) has an "attachments" array which contains an "id" and "contentUrl" that has a SharePoint URL (for a .pdf file in this case). Is there an endpoint I can hit with the attachment."id" to download the content value? If not what is the recommended way to download the actual content?
So regarding this, I've also got a few mores questions if you could please try to answer:
- Is it possible to get a list of all Chat (s) of an organisation? According to this it's a no -> https://stackoverflow.com/a/62912307 (from the time of this writing this was over a year ago however)
- Is there a "better way" of downloading all files/attachments/images of an existing one-on-one chat through the Graph API than from the way I'm trying to do it?
- Do all file attachments go to the "Files" tab in a one-on-one Chat (is this hosted on SharePoint or OneDrive?) ?
For any future messages that comes through a Chat I guess I can create a subscription to see the message and attachments that are occurring as per the docs here https://learn.microsoft.com/en-us/graph/api/subscription-post-subscriptions?view=graph-rest-1.0&tabs=http .