-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdebug-list-drafts.ts
More file actions
86 lines (71 loc) · 2.85 KB
/
debug-list-drafts.ts
File metadata and controls
86 lines (71 loc) · 2.85 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import { connectToSuperhuman, disconnect } from "./src/superhuman-api";
async function listDrafts() {
console.log("=== Listing All Drafts via Gmail API ===\n");
const conn = await connectToSuperhuman(9333, true);
if (!conn) {
console.error("Failed to connect");
return;
}
// Try to list drafts using the Gmail API through Superhuman
const result = await conn.Runtime.evaluate({
expression: `
(async () => {
try {
const ga = window.GoogleAccount;
if (!ga) return { error: "No GoogleAccount" };
const di = ga.di;
const accountEmail = ga.emailAddress;
// Check if this is a Microsoft account
const isMicrosoft = di.get?.('isMicrosoft');
if (isMicrosoft) {
return { error: "Microsoft account - would need different API" };
}
// Try to get drafts via Gmail API
const gmail = di.get?.('gmail');
// Attempt to fetch drafts
const draftsResponse = await gmail._getAsync?.(
'https://www.googleapis.com/gmail/v1/users/me/drafts',
{},
{ calendarAccountEmail: accountEmail, endpoint: 'gmail.drafts.list', allowCachedResponses: false }
);
if (!draftsResponse?.drafts) {
return { error: "No drafts found or API failed", response: draftsResponse };
}
// Get details for each draft
const draftsWithDetails = [];
for (const draft of draftsResponse.drafts.slice(0, 5)) { // Limit to 5 for testing
try {
const draftDetail = await gmail._getAsync?.(
'https://www.googleapis.com/gmail/v1/users/me/drafts/' + draft.id,
{},
{ calendarAccountEmail: accountEmail, endpoint: 'gmail.drafts.get', allowCachedResponses: false }
);
draftsWithDetails.push({
id: draft.id,
messageId: draftDetail?.message?.id,
threadId: draftDetail?.message?.threadId,
subject: draftDetail?.message?.payload?.headers?.find(h => h.name === 'Subject')?.value,
to: draftDetail?.message?.payload?.headers?.find(h => h.name === 'To')?.value,
snippet: draftDetail?.message?.snippet?.substring(0, 50)
});
} catch (e) {
draftsWithDetails.push({ id: draft.id, error: e.message });
}
}
return {
totalDrafts: draftsResponse.drafts.length,
draftsWithDetails
};
} catch (e) {
return { error: e.message, stack: e.stack };
}
})()
`,
returnByValue: true,
awaitPromise: true
});
console.log("Drafts from Gmail API:");
console.log(JSON.stringify(result.result.value, null, 2));
await disconnect(conn);
}
listDrafts().catch(console.error);