Git Product home page Git Product logo

teams-chat-backup's Introduction

Microsoft Teams Chat Backup

This project retrieves a full chat history (messages and uploaded files) and renders it as an HTML.

Important notice

The maintainer does no longer have the need for this tool, nor can't find the time to keep it alive. Therefore this repository is set to read-only. If anyone is willing to maintain this utility, feel free to fork this repository.

Requirements

Node.js 10 (or higher). Tested on macOS and Windows, but will most likely run on Linux too.

Setup

Like any other JS project, clone this repo and run the following command to install dependencies:

npm install

Run

To backup a chat, run:

npm run start

This will ask several questions:

Chat ID - this is the identifier of the conversation. To find it:

  1. Go to https://teams.microsoft.com
  2. Go to the chat you'd like to export.
  3. Copy chat ID from URL. It looks like 19:<uuid of one user>-<uuid of other user>@unq.gbl.spaces

Auth token (JWT) - this is needed for calling Microsoft Graph APIs.

  1. Go to https://developer.microsoft.com/en-us/graph/graph-explorer. At the left side, under Authentication, click "Sign In with Microsoft"
  2. After having logged in, on the left side (where you clicked for login), click "modify permissions". Enable Chat.Read and re-login (like it states).
  3. The URL contains the token (#access_token=<long token goes here>). Copy this value. Or make any random call in the sandbox and copy the Authorization request header either from the JS console (without Bearer in front of it) or from the "Access token" tab of the Graph Explorer page.

Target directory name - is the name to use for the export (will be created in the out directory in this project).

Output

An exported chat contains:

  • messages-#####.json: these are the pages of messages. Page 0000 is the most recent one (pages and messages within are in reverse order).
  • image-#####: these are images uploaded in the chat
  • index.html: is the full history rendered into a simple HTML template, referring to the downloaded images. This is the file you want for viewing.

To Do

  • Make an easier way of obtaining a token.
  • Add support for bot messages (for example a form).

teams-chat-backup's People

Contributors

cicadacinema avatar dependabot[bot] avatar edgraaff avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

teams-chat-backup's Issues

Adaptive Cards and bot messages

What follows is documentation of my experience rendering Microsoft's Adaptive Cards UI to HTML, for the purposes of viewing messages rendered with it in a Teams archive. I'm not a web developer and I want to pass on everything I've learnt over the past few hours to someone who is more experienced with this. Naturally, it is easy to produce various Adaptive Cards-based messages by selecting one of various "Apps" when sending a message on Teams. The most convenient one for testing is Forms, in my experience.

Adaptive Cards are platform-agnostic snippets of UI, authored in JSON, that apps and services can openly exchange. When delivered to a specific app, the JSON is transformed into native UI that automatically adapts to its surroundings. It helps design and integrate light-weight UI for all major platforms and frameworks.

Microsoft Teams uses Adaptive cards to show certain messages such as polls. When such messages are downloaded by this tool, the adaptive card itself can be found under message.attachments[0].content in a form resembling a json object. This is unfortunate because it doesn't seem like Microsoft intended for Adaptive Cards to be rendered as plain HTML. The .NET portion of the SDK contains some snippets to show how this could be done in C#, but I haven't been able to find a similar implementation for javascript. The javascript SDK requires that the code is run as a script. As stated earlier, I am unfamiliar with how this could be implemented, so perhaps it is easier than I think. It seems that this person wanted to achieve a similar goal, but was unsuccessful.

Even after manually extracting the json object from a scraped message and feeding it into the .NET snippet linked above (this can easily be done by replacing the link in the snippet with a GitHub gist where your json is stored), the html remains garbed and unusable. Again, I'm not sure why this is. I'm not going to provide any sample messages, but the errors included some misaligned elements and also completely inexplicable things like this:
image

I'm going to submit a PR soon to completely ignore messages made by bots (in its current state, the tool halts when it encounters an Adaptive Card message created by a bot in the createHtml stage - after all the messages/media have been saved successfully via the Teams API), but it would be nice if someone more familiar with web development could pick up this issue and work on it. It seems like a good solution could be to capture json objects as they come in and write to a js script as well as a html file as the final output. Therefore the json objects could be saved separately (like images) and rendered client-side. I think this could be done most easily while messages are being received from the API, because the final message log contains some carriage returns and escape characters (again, not sure where these are being introduced) among Adaptive Card objects.

The auth token (JWT) acquiring method does not work for me

Hi experts,

I do not find the "Chat.Read" permission under "modify permissions". This method does not work for me. Are there any alternatives?


Auth token (JWT) - this is needed for calling Microsoft Graph APIs.

Go to https://developer.microsoft.com/en-us/graph/graph-explorer. At the left side, under Authentication, click "Sign In with Microsoft"
After having logged in, on the left side (where you clicked for login), click "modify permissions". Enable Chat.Read and re-login (like it states).
The URL contains the token (#access_token=<long token goes here>). Copy this value. Or make any random call in the sandbox and copy the Authorization request header either from the JS console (without Bearer in front of it) or from the "Access token" tab of the Graph Explorer page.

Target directory name - is the name to use for the export (will be created in the out directory in this project).

Unable to resume after timeout

After downloading more than 1000 json files and 929 images I get the following error and the html file is not created.
Is there a way to create the index.html from what is currently downloaded? Can files also be downloaded?

downloading image-00928
downloading image-00929
Error: Request failed with status code 504
at createError (C:\teams-chat-backup-master\teams-chat-backup-master\node_modules\axios\lib\core\createError.js:16:15)
at settle (C:\teams-chat-backup-master\teams-chat-backup-master\node_modules\axios\lib\core\settle.js:17:12)
at RedirectableRequest.handleResponse (C:\teams-chat-backup-master\teams-chat-backup-master\node_modules\axios\lib\adapters\http.js:238:9)
at RedirectableRequest.emit (node:events:527:28)
at RedirectableRequest._processResponse (C:\teams-chat-backup-master\teams-chat-backup-master\node_modules\follow-redirects\index.js:346:10)
at ClientRequest.RedirectableRequest._onNativeResponse (C:\teams-chat-backup-master\teams-chat-backup-master\node_modules\follow-redirects\index.js:57:10)
at Object.onceWrapper (node:events:642:26)
at ClientRequest.emit (node:events:527:28)
at HTTPParser.parserOnIncomingClient [as onIncoming] (node:_http_client:631:27)
at HTTPParser.parserOnHeadersComplete (node:_http_common:128:17) {
config: {

TypeError: Cannot read property 'user' of null

Hi @edgraaff while trying to run this I ran into the error below. It exports all of the chat history into the json files but then stops with that error. Would it be possible to statically define that variable? Otherwise is there anything on my end I can do to fix that? The issue seems to be related to const myId = profile.data.id; but I'm not sure.

TypeError: Cannot read property 'user' of null
at Backup.createHtml (c:\Users\User\Downloads\teams-chat-backup-master\src\backup.js:180:26)
at async Backup.run (c:\Users\User\Downloads\teams-chat-backup-master\src\backup.js:36:5)

Thanks,

eth101

Error 400?

Hi. Great tool if I could make it work :-)
I get this message. Any idea?

retrieve page 00000
Error: Request failed with status code 400
at createError (C:\Users\RasmusGrusgaard\Downloads\teams-chat-backup-master\teams-chat-backup-master\node_modules\axios\lib\core\createError.js:16:15)
at settle (C:\Users\RasmusGrusgaard\Downloads\teams-chat-backup-master\teams-chat-backup-master\node_modules\axios\lib\core\settle.js:17:12)
at IncomingMessage.handleStreamEnd (C:\Users\RasmusGrusgaard\Downloads\teams-chat-backup-master\teams-chat-backup-master\node_modules\axios\lib\adapters\http.js:269:11)
at IncomingMessage.emit (node:events:525:35)
at endReadableNT (node:internal/streams/readable:1358:12)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
config: {

etc

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.