Files
wekan/models/lib/apiImport/teams.js
T
Lauri Ojansivu 01e88410cd Import and export Azure DevOps Boards, Microsoft Lists, Project, Outlook, Teams and OneNote.
Azure DevOps Boards: a query's "Export to CSV" is imported (Board Column or
State as lists, Board Lane as swimlanes, Title 1/2/3 tree levels as parent
cards, "Name <address>" people, regional dates, other columns as custom
fields), and a board exports as the CSV "Import from CSV" reads.

Microsoft Lists: a list's "Export to CSV" is imported (Status or Progress as
the lists, people, dates, tags, other columns as custom fields), and a board
exports as a CSV that "New list - From CSV" makes a list of.

Microsoft Project: the "XML Format" (MSPDI) plan is imported (summary tasks
as swimlanes, progress as lists, subtasks, resources, predecessors), read by
a small XML reader that never resolves a DTD or an entity, and a board
exports as a plan Project opens.

Outlook: .msg files are read without a library - the Compound File Binary
format (MS-CFB) and the message's properties (MS-OXMSG) - into the mail
import, threads and attachments included, alone or in a .zip with .eml
files; a board exports as .eml files Outlook opens. The reader was checked
against .msg files saved by Outlook.

Teams and OneNote: fetched from Microsoft Graph with the member's token
(chats and channels; notebooks with their pages' HTML, to-do boxes as a
checklist), or read from a file - Teams' personal export .tar, Graph chat
messages, and the files WeKan exports: Teams chats as Graph chat messages,
OneNote pages as Graph's create-page XHTML in a .zip.

All six are under the Microsoft heading of Import and Export, with tests,
negative tests, live tests for the two Graph imports, documentation and the
import instruction in every language. Low confidence translations include
ace, ak, ay, bm, bo, bua, chr, csb, cv, dz, ee, ff, fj, gn, gv, haw, ig, iu,
kl, ks, kok, kw, ht, hsb, fur, fo, ga, gd, ku, lld, nah, nap, rup, sah, sc,
scn, se, nd, nso, ss, om, rn, rw, sm, sn, qu, pap, lg, mg, mi, ny, so, mai,
sd, ps, or_IN, my, si, rm, la, lb, tig, tlh, uz-AR, ve, ve-PP, ve-CC, vo, wa,
wal, wo, zgh, to, tpi, wa-RR and ts.

Thanks to xet7 !
2026-11-21 01:33:59 +02:00

59 lines
3.5 KiB
JavaScript

// Microsoft Teams through Microsoft Graph (models/lib/apiImportServices.js):
// the member's chats and the channels of the teams they belong to, and one
// chat's or channel's messages, as the JSON models/lib/chatExportFormats.js
// parseTeamsExport reads. Plain Node; `request` is passed in.
//
// The token is a Microsoft Graph access token of a work or school account
// with Chat.Read (chats) and Team.ReadBasic.All, Channel.ReadBasic.All and
// ChannelMessage.Read.All (channels; the last one needs an administrator's
// consent). Graph does not serve personal Teams accounts - their messages
// come from the personal "Export your data" instead. The token goes only
// into the Authorization header of requests to graph.microsoft.com.
import { GRAPH, graphHeaders, graphAll } from './graph.js';
export const MAX_TEAMS_REQUESTS = 2000;
export const MAX_TEAMS_MESSAGES = 200000;
const enc = value => encodeURIComponent(String(value));
const limit = what => ({ what, max: MAX_TEAMS_REQUESTS, maxItems: MAX_TEAMS_MESSAGES });
export async function list(credentials, request) {
const headers = graphHeaders(credentials);
const state = { pages: 0 };
const out = [];
const chats = await graphAll(`${GRAPH}/me/chats`, headers, request, state, limit('Teams chats'));
for (const chat of chats.filter(c => c && typeof c.id === 'string')) {
out.push({ id: `chat:${chat.id}`, name: String(chat.topic || `${chat.chatType || 'chat'} ${chat.id.slice(0, 12)}`) });
}
let teams = [];
try { teams = await graphAll(`${GRAPH}/me/joinedTeams`, headers, request, state, limit('teams')); } catch (error) { teams = []; }
for (const team of teams.filter(t => t && typeof t.id === 'string')) {
let channels = [];
try { channels = await graphAll(`${GRAPH}/teams/${enc(team.id)}/channels`, headers, request, state, limit('channels')); } catch (error) { channels = []; }
for (const channel of channels.filter(c => c && typeof c.id === 'string')) {
out.push({ id: `channel:${team.id}:${channel.id}`, name: `${team.displayName || 'Team'} / ${channel.displayName || channel.id}` });
}
}
return out;
}
export async function fetch(credentials, id, request) {
const headers = graphHeaders(credentials);
if (typeof id !== 'string' || !id) throw new Error('Choose what to import');
const state = { pages: 0 };
const chat = /^chat:(.+)$/.exec(id);
if (chat) {
const info = await request(`${GRAPH}/chats/${enc(chat[1])}`, { method: 'GET', headers });
const messages = await graphAll(`${GRAPH}/chats/${enc(chat[1])}/messages?$top=50`, headers, request, state, limit('messages'));
return { teams: true, chats: [{ id: chat[1], topic: String((info && info.topic) || ''), chatType: String((info && info.chatType) || 'group'),
kind: 'chat', messages }] };
}
const channel = /^channel:([^:]+):(.+)$/.exec(id);
if (!channel) throw new Error('Choose what to import');
const team = await request(`${GRAPH}/teams/${enc(channel[1])}`, { method: 'GET', headers });
const info = await request(`${GRAPH}/teams/${enc(channel[1])}/channels/${enc(channel[2])}`, { method: 'GET', headers });
const messages = await graphAll(`${GRAPH}/teams/${enc(channel[1])}/channels/${enc(channel[2])}/messages?$expand=replies`,
headers, request, state, limit('messages'));
return { teams: true, chats: [{ id: channel[2], topic: String((info && info.displayName) || ''), description: String((info && info.description) || ''),
kind: 'channel', team: String((team && team.displayName) || ''), messages }] };
}