Skip to content

Instantly share code, notes, and snippets.

@evenevan
Last active September 6, 2024 06:23
Show Gist options
  • Save evenevan/ca4e79fe3f346dc86599d9d53daa35de to your computer and use it in GitHub Desktop.
Save evenevan/ca4e79fe3f346dc86599d9d53daa35de to your computer and use it in GitHub Desktop.
Export Microsoft Teams chats with a work or school account
@count1234hall
Copy link

count1234hall commented Jul 20, 2023

Thanks again for giving it a shot!

Unfortunately, I got a new error, similar to the first:

Need admin approval
unverified
This app may be risky. If you trust this app, please ask your admin to grant you access. Learn more
Have an admin account? Sign in with that account
Return to the application without granting consent

I'll go through the Graph Explorer and report back on that part.

By the way, the app name is as you described, "Teams Chat Export"

@count1234hall
Copy link

count1234hall commented Jul 20, 2023

Here's what I see from Microsoft's Graph Explorer

Permission	Admin consent required	Status
Chat.Read	No	Consent
User.Read	No	Unconsent
offline_access	No	Consent

and some more items:

Chat.ReadBasic	No	Consent
Chat.ReadWrite	No	Consent

I'll try hitting Consent on the aforementioned permissions and see if there's an improvement.

Also, thanks for the instructions on how to log in so I can view these!

Update:
I'm not sure if this is from spamming Consent, but I am getting some success with queries like
https://graph.microsoft.com/v1.0/me/joinedTeams which actually does return valid information.
Unfortunately, I'm getting errors similar to earlier when trying to get messages:

"error": { "code": "Forbidden", "message": "Missing scope permissions on the request. API requires one of 'ChannelMessage.Read.All, Group.Read.All, Group.ReadWrite.All'. Scopes on the request 'Channel.ReadBasic.All, ChannelMessage.Edit, Chat.Create, Chat.Read, Chat.ReadBasic, Chat.ReadWrite, openid, profile, Team.Create, Team.ReadBasic.All, User.Read, User.ReadBasic.All, User.ReadWrite, email, ChannelMessage.Send'"

@evenevan
Copy link
Author

I really appreciate your involvement with this project - thank you so much :)

Based on the permissions you've shown me, I found that the traditional scope type should be valid, as none require admin permissions, and for some reason, I hadn't thought of trying it out with the PnP Management Shell application. I've given this a quick test, and it seems to work. In theory, using the PnP Management Shell (which appears to be an allowed app for your org) and the traditional scopes (which allow fine-tuned control over the permissions) should get you through every hoop.

I've pushed another change to the project, which removes the OpenID scope type. Downloading the new code and following the normal guide should hopefully work, if you decide to continue to pursue this of course.

Finally, that error in the last message you sent is somewhat interesting, as it says that it missing a scope. If you hit consent on the Chat.Read permission, that'll probably work.

@anlyx
Copy link

anlyx commented Sep 3, 2023

Hi!
thanks for your work.
I want to report you that each chat with square brackets [ ] fail to export:

image

easy to fix, just add after line 156 :
$name = $name -replace '[[]]','_'

result:
image

Bye :)

@anlyx
Copy link

anlyx commented Sep 3, 2023

Is there a way to also embed in the chat all sent and received files ?
right now in the exported html there is just the link to sharepoint.

@evenevan
Copy link
Author

evenevan commented Sep 3, 2023

Hi! thanks for your work. I want to report you that each chat with square brackets [ ] fail to export:

image

easy to fix, just add after line 156 : $name = $name -replace '[[]]','_'

result: image

Bye :)

Hey! Thanks for the fix, but I've pushed a slightly different fix for your issue that preserves the square brackets; the issue was an oversight on wildcard paths and just required changing parameters.

Is there a way to also embed in the chat all sent and received files ? right now in the exported html there is just the link to sharepoint.

I've glanced through the process of downloading SharePoint files and I have concluded that for the time being, I don't have the time to try and make it work.

If you're up for it, you could open an an issue/pull request and work on an implementation. Otherwise, I may try adding this later on once I get some time. Although far from ideal, another solution is simply having all of the files available separately (you should have a folder name "Microsoft Teams Chat Files" in your org's OneDrive that has your uploaded files, but do note this doesn't include files uploaded by others).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment