-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathshow-draft-body.ts
More file actions
41 lines (36 loc) · 1.16 KB
/
show-draft-body.ts
File metadata and controls
41 lines (36 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { connectToSuperhuman, disconnect } from "./src/superhuman-api";
async function showDraftBody(draftId: string) {
const conn = await connectToSuperhuman(9333, true);
if (!conn) return;
const result = await conn.Runtime.evaluate({
expression: `
(async () => {
try {
const ga = window.GoogleAccount;
const di = ga?.di;
const msgraph = di.get?.('msgraph');
const response = await msgraph._fetchJSONWithRetry(
'https://graph.microsoft.com/v1.0/me/messages/' + ${JSON.stringify(draftId)},
{ method: 'GET', endpoint: 'mail.getDraft' }
);
return {
contentType: response.body?.contentType,
content: response.body?.content
};
} catch (e) {
return { error: e.message };
}
})()
`,
returnByValue: true,
awaitPromise: true
});
console.log(JSON.stringify(result.result.value, null, 2));
await disconnect(conn);
}
const targetDraftId = process.argv[2];
if (targetDraftId) {
showDraftBody(targetDraftId).catch(console.error);
} else {
console.error("Usage: bun run show-draft-body.ts <draft-id>");
}