@divyacon/piece-gmail 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.MIT-AP +24 -0
- package/README.md +8 -2
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +111 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/actions/ai-get-message-action.d.ts +7 -0
- package/dist/lib/actions/ai-get-message-action.d.ts.map +1 -0
- package/dist/lib/actions/ai-get-message-action.js +24 -0
- package/dist/lib/actions/ai-get-message-action.js.map +1 -0
- package/dist/lib/actions/ai-reply-to-thread-action.d.ts +16 -0
- package/dist/lib/actions/ai-reply-to-thread-action.d.ts.map +1 -0
- package/dist/lib/actions/ai-reply-to-thread-action.js +24 -0
- package/dist/lib/actions/ai-reply-to-thread-action.js.map +1 -0
- package/dist/lib/actions/ai-search-email-action.d.ts +21 -0
- package/dist/lib/actions/ai-search-email-action.d.ts.map +1 -0
- package/dist/lib/actions/ai-search-email-action.js +24 -0
- package/dist/lib/actions/ai-search-email-action.js.map +1 -0
- package/dist/lib/actions/ai-send-email-action.d.ts +18 -0
- package/dist/lib/actions/ai-send-email-action.d.ts.map +1 -0
- package/dist/lib/actions/ai-send-email-action.js +24 -0
- package/dist/lib/actions/ai-send-email-action.js.map +1 -0
- package/dist/lib/actions/create-draft-action.d.ts +16 -0
- package/dist/lib/actions/create-draft-action.d.ts.map +1 -0
- package/dist/lib/actions/create-draft-action.js +137 -0
- package/dist/lib/actions/create-draft-action.js.map +1 -0
- package/dist/lib/actions/create-draft-reply-action.d.ts +17 -0
- package/dist/lib/actions/create-draft-reply-action.d.ts.map +1 -0
- package/dist/lib/actions/create-draft-reply-action.js +269 -0
- package/dist/lib/actions/create-draft-reply-action.js.map +1 -0
- package/dist/lib/actions/delete-draft-action.d.ts +7 -0
- package/dist/lib/actions/delete-draft-action.d.ts.map +1 -0
- package/dist/lib/actions/delete-draft-action.js +62 -0
- package/dist/lib/actions/delete-draft-action.js.map +1 -0
- package/dist/lib/actions/forward-message-action.d.ts +12 -0
- package/dist/lib/actions/forward-message-action.d.ts.map +1 -0
- package/dist/lib/actions/forward-message-action.js +139 -0
- package/dist/lib/actions/forward-message-action.js.map +1 -0
- package/dist/lib/actions/get-attachment-action.d.ts +9 -0
- package/dist/lib/actions/get-attachment-action.d.ts.map +1 -0
- package/dist/lib/actions/get-attachment-action.js +80 -0
- package/dist/lib/actions/get-attachment-action.js.map +1 -0
- package/dist/lib/actions/get-draft-action.d.ts +7 -0
- package/dist/lib/actions/get-draft-action.d.ts.map +1 -0
- package/dist/lib/actions/get-draft-action.js +56 -0
- package/dist/lib/actions/get-draft-action.js.map +1 -0
- package/dist/lib/actions/get-label-action.d.ts +7 -0
- package/dist/lib/actions/get-label-action.d.ts.map +1 -0
- package/dist/lib/actions/get-label-action.js +55 -0
- package/dist/lib/actions/get-label-action.js.map +1 -0
- package/dist/lib/actions/get-mail-action.d.ts +7 -0
- package/dist/lib/actions/get-mail-action.d.ts.map +1 -0
- package/dist/lib/actions/get-mail-action.js +44 -0
- package/dist/lib/actions/get-mail-action.js.map +1 -0
- package/dist/lib/actions/get-profile-action.d.ts +5 -0
- package/dist/lib/actions/get-profile-action.d.ts.map +1 -0
- package/dist/lib/actions/get-profile-action.js +43 -0
- package/dist/lib/actions/get-profile-action.js.map +1 -0
- package/dist/lib/actions/get-thread-action.d.ts +9 -0
- package/dist/lib/actions/get-thread-action.d.ts.map +1 -0
- package/dist/lib/actions/get-thread-action.js +53 -0
- package/dist/lib/actions/get-thread-action.js.map +1 -0
- package/dist/lib/actions/list-drafts-action.d.ts +8 -0
- package/dist/lib/actions/list-drafts-action.d.ts.map +1 -0
- package/dist/lib/actions/list-drafts-action.js +62 -0
- package/dist/lib/actions/list-drafts-action.js.map +1 -0
- package/dist/lib/actions/list-history-action.d.ts +9 -0
- package/dist/lib/actions/list-history-action.d.ts.map +1 -0
- package/dist/lib/actions/list-history-action.js +74 -0
- package/dist/lib/actions/list-history-action.js.map +1 -0
- package/dist/lib/actions/list-labels-action.d.ts +5 -0
- package/dist/lib/actions/list-labels-action.d.ts.map +1 -0
- package/dist/lib/actions/list-labels-action.js +47 -0
- package/dist/lib/actions/list-labels-action.js.map +1 -0
- package/dist/lib/actions/list-threads-action.d.ts +10 -0
- package/dist/lib/actions/list-threads-action.d.ts.map +1 -0
- package/dist/lib/actions/list-threads-action.js +74 -0
- package/dist/lib/actions/list-threads-action.js.map +1 -0
- package/dist/lib/actions/reply-to-email-action.d.ts +16 -0
- package/dist/lib/actions/reply-to-email-action.d.ts.map +1 -0
- package/dist/lib/actions/reply-to-email-action.js +202 -0
- package/dist/lib/actions/reply-to-email-action.js.map +1 -0
- package/dist/lib/actions/request-approval-in-email.d.ts +15 -0
- package/dist/lib/actions/request-approval-in-email.d.ts.map +1 -0
- package/dist/lib/actions/request-approval-in-email.js +174 -0
- package/dist/lib/actions/request-approval-in-email.js.map +1 -0
- package/dist/lib/actions/search-email-action.d.ts +22 -0
- package/dist/lib/actions/search-email-action.d.ts.map +1 -0
- package/dist/lib/actions/search-email-action.js +179 -0
- package/dist/lib/actions/search-email-action.js.map +1 -0
- package/dist/lib/actions/send-draft-action.d.ts +7 -0
- package/dist/lib/actions/send-draft-action.d.ts.map +1 -0
- package/dist/lib/actions/send-draft-action.js +57 -0
- package/dist/lib/actions/send-draft-action.js.map +1 -0
- package/dist/lib/actions/send-email-action.d.ts +18 -0
- package/dist/lib/actions/send-email-action.d.ts.map +1 -0
- package/dist/lib/actions/send-email-action.js +196 -0
- package/dist/lib/actions/send-email-action.js.map +1 -0
- package/dist/lib/actions/stop-watch-action.d.ts +5 -0
- package/dist/lib/actions/stop-watch-action.d.ts.map +1 -0
- package/dist/lib/actions/stop-watch-action.js +41 -0
- package/dist/lib/actions/stop-watch-action.js.map +1 -0
- package/dist/lib/actions/update-draft-action.d.ts +17 -0
- package/dist/lib/actions/update-draft-action.d.ts.map +1 -0
- package/dist/lib/actions/update-draft-action.js +193 -0
- package/dist/lib/actions/update-draft-action.js.map +1 -0
- package/dist/lib/auth.d.ts +12 -0
- package/dist/lib/auth.d.ts.map +1 -0
- package/dist/lib/auth.js +108 -0
- package/dist/lib/auth.js.map +1 -0
- package/dist/lib/common/data.d.ts +132 -0
- package/dist/lib/common/data.d.ts.map +1 -0
- package/dist/lib/common/data.js +209 -0
- package/dist/lib/common/data.js.map +1 -0
- package/dist/lib/common/mime.d.ts +29 -0
- package/dist/lib/common/mime.d.ts.map +1 -0
- package/dist/lib/common/mime.js +59 -0
- package/dist/lib/common/mime.js.map +1 -0
- package/dist/lib/common/models.d.ts +86 -0
- package/dist/lib/common/models.d.ts.map +1 -0
- package/dist/lib/common/models.js +26 -0
- package/dist/lib/common/models.js.map +1 -0
- package/dist/lib/common/props.d.ts +28 -0
- package/dist/lib/common/props.d.ts.map +1 -0
- package/dist/lib/common/props.js +231 -0
- package/dist/lib/common/props.js.map +1 -0
- package/dist/lib/output-schemas.d.ts +29 -0
- package/dist/lib/output-schemas.d.ts.map +1 -0
- package/dist/lib/output-schemas.js +1029 -0
- package/dist/lib/output-schemas.js.map +1 -0
- package/dist/lib/triggers/new-attachment.d.ts +144 -0
- package/dist/lib/triggers/new-attachment.d.ts.map +1 -0
- package/dist/lib/triggers/new-attachment.js +150 -0
- package/dist/lib/triggers/new-attachment.js.map +1 -0
- package/dist/lib/triggers/new-conversation.d.ts +59 -0
- package/dist/lib/triggers/new-conversation.d.ts.map +1 -0
- package/dist/lib/triggers/new-conversation.js +308 -0
- package/dist/lib/triggers/new-conversation.js.map +1 -0
- package/dist/lib/triggers/new-email.d.ts +52 -0
- package/dist/lib/triggers/new-email.d.ts.map +1 -0
- package/dist/lib/triggers/new-email.js +135 -0
- package/dist/lib/triggers/new-email.js.map +1 -0
- package/dist/lib/triggers/new-label.d.ts +15 -0
- package/dist/lib/triggers/new-label.d.ts.map +1 -0
- package/dist/lib/triggers/new-label.js +82 -0
- package/dist/lib/triggers/new-label.js.map +1 -0
- package/dist/lib/triggers/new-labeled-email.d.ts +35 -0
- package/dist/lib/triggers/new-labeled-email.d.ts.map +1 -0
- package/dist/lib/triggers/new-labeled-email.js +147 -0
- package/dist/lib/triggers/new-labeled-email.js.map +1 -0
- package/package.json +53 -3
- package/src/index.ts +107 -0
- package/src/lib/actions/ai-get-message-action.ts +20 -0
- package/src/lib/actions/ai-reply-to-thread-action.ts +20 -0
- package/src/lib/actions/ai-search-email-action.ts +21 -0
- package/src/lib/actions/ai-send-email-action.ts +20 -0
- package/src/lib/actions/create-draft-action.ts +148 -0
- package/src/lib/actions/create-draft-reply-action.ts +314 -0
- package/src/lib/actions/delete-draft-action.ts +57 -0
- package/src/lib/actions/forward-message-action.ts +159 -0
- package/src/lib/actions/get-attachment-action.ts +83 -0
- package/src/lib/actions/get-draft-action.ts +53 -0
- package/src/lib/actions/get-label-action.ts +53 -0
- package/src/lib/actions/get-mail-action.ts +52 -0
- package/src/lib/actions/get-profile-action.ts +39 -0
- package/src/lib/actions/get-thread-action.ts +47 -0
- package/src/lib/actions/list-drafts-action.ts +72 -0
- package/src/lib/actions/list-history-action.ts +83 -0
- package/src/lib/actions/list-labels-action.ts +43 -0
- package/src/lib/actions/list-threads-action.ts +89 -0
- package/src/lib/actions/reply-to-email-action.ts +228 -0
- package/src/lib/actions/request-approval-in-email.ts +197 -0
- package/src/lib/actions/search-email-action.ts +219 -0
- package/src/lib/actions/send-draft-action.ts +54 -0
- package/src/lib/actions/send-email-action.ts +213 -0
- package/src/lib/actions/stop-watch-action.ts +37 -0
- package/src/lib/actions/update-draft-action.ts +211 -0
- package/src/lib/auth.ts +116 -0
- package/src/lib/common/data.ts +268 -0
- package/src/lib/common/mime.ts +82 -0
- package/src/lib/common/models.ts +91 -0
- package/src/lib/common/props.ts +262 -0
- package/src/lib/output-schemas.ts +1061 -0
- package/src/lib/triggers/new-attachment.ts +203 -0
- package/src/lib/triggers/new-conversation.ts +413 -0
- package/src/lib/triggers/new-email.ts +173 -0
- package/src/lib/triggers/new-label.ts +83 -0
- package/src/lib/triggers/new-labeled-email.ts +197 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { TriggerStrategy } from '@agnocon/pieces-framework';
|
|
2
|
+
export declare const gmailNewLabeledEmailTrigger: import("@agnocon/pieces-framework").ITrigger<TriggerStrategy.WEBHOOK, (import("@agnocon/pieces-framework").OAuth2Property<import("@agnocon/pieces-framework").OAuth2Props> | import("@agnocon/pieces-framework").CustomAuthProperty<{
|
|
3
|
+
serviceAccount: import("@agnocon/pieces-framework").LongTextProperty<true>;
|
|
4
|
+
userEmail: import("@agnocon/pieces-framework").ShortTextProperty<true>;
|
|
5
|
+
}>)[], {
|
|
6
|
+
label: import("@agnocon/pieces-framework").DropdownProperty<import("../common/models").GmailLabel, true, (import("@agnocon/pieces-framework").OAuth2Property<import("@agnocon/pieces-framework").OAuth2Props> | import("@agnocon/pieces-framework").CustomAuthProperty<{
|
|
7
|
+
serviceAccount: import("@agnocon/pieces-framework").LongTextProperty<true>;
|
|
8
|
+
userEmail: import("@agnocon/pieces-framework").ShortTextProperty<true>;
|
|
9
|
+
}>)[]>;
|
|
10
|
+
}> | import("@agnocon/pieces-framework").ITrigger<TriggerStrategy.POLLING, (import("@agnocon/pieces-framework").OAuth2Property<import("@agnocon/pieces-framework").OAuth2Props> | import("@agnocon/pieces-framework").CustomAuthProperty<{
|
|
11
|
+
serviceAccount: import("@agnocon/pieces-framework").LongTextProperty<true>;
|
|
12
|
+
userEmail: import("@agnocon/pieces-framework").ShortTextProperty<true>;
|
|
13
|
+
}>)[], {
|
|
14
|
+
label: import("@agnocon/pieces-framework").DropdownProperty<import("../common/models").GmailLabel, true, (import("@agnocon/pieces-framework").OAuth2Property<import("@agnocon/pieces-framework").OAuth2Props> | import("@agnocon/pieces-framework").CustomAuthProperty<{
|
|
15
|
+
serviceAccount: import("@agnocon/pieces-framework").LongTextProperty<true>;
|
|
16
|
+
userEmail: import("@agnocon/pieces-framework").ShortTextProperty<true>;
|
|
17
|
+
}>)[]>;
|
|
18
|
+
}> | import("@agnocon/pieces-framework").ITrigger<TriggerStrategy.MANUAL, (import("@agnocon/pieces-framework").OAuth2Property<import("@agnocon/pieces-framework").OAuth2Props> | import("@agnocon/pieces-framework").CustomAuthProperty<{
|
|
19
|
+
serviceAccount: import("@agnocon/pieces-framework").LongTextProperty<true>;
|
|
20
|
+
userEmail: import("@agnocon/pieces-framework").ShortTextProperty<true>;
|
|
21
|
+
}>)[], {
|
|
22
|
+
label: import("@agnocon/pieces-framework").DropdownProperty<import("../common/models").GmailLabel, true, (import("@agnocon/pieces-framework").OAuth2Property<import("@agnocon/pieces-framework").OAuth2Props> | import("@agnocon/pieces-framework").CustomAuthProperty<{
|
|
23
|
+
serviceAccount: import("@agnocon/pieces-framework").LongTextProperty<true>;
|
|
24
|
+
userEmail: import("@agnocon/pieces-framework").ShortTextProperty<true>;
|
|
25
|
+
}>)[]>;
|
|
26
|
+
}> | import("@agnocon/pieces-framework").ITrigger<TriggerStrategy.APP_WEBHOOK, (import("@agnocon/pieces-framework").OAuth2Property<import("@agnocon/pieces-framework").OAuth2Props> | import("@agnocon/pieces-framework").CustomAuthProperty<{
|
|
27
|
+
serviceAccount: import("@agnocon/pieces-framework").LongTextProperty<true>;
|
|
28
|
+
userEmail: import("@agnocon/pieces-framework").ShortTextProperty<true>;
|
|
29
|
+
}>)[], {
|
|
30
|
+
label: import("@agnocon/pieces-framework").DropdownProperty<import("../common/models").GmailLabel, true, (import("@agnocon/pieces-framework").OAuth2Property<import("@agnocon/pieces-framework").OAuth2Props> | import("@agnocon/pieces-framework").CustomAuthProperty<{
|
|
31
|
+
serviceAccount: import("@agnocon/pieces-framework").LongTextProperty<true>;
|
|
32
|
+
userEmail: import("@agnocon/pieces-framework").ShortTextProperty<true>;
|
|
33
|
+
}>)[]>;
|
|
34
|
+
}>;
|
|
35
|
+
//# sourceMappingURL=new-labeled-email.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"new-labeled-email.d.ts","sourceRoot":"","sources":["../../../src/lib/triggers/new-labeled-email.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,eAAe,EAEhB,MAAM,2BAA2B,CAAC;AAoDnC,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA4ItC,CAAC"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.gmailNewLabeledEmailTrigger = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
// Vendored from Activepieces packages/pieces/community/gmail/src/lib/triggers/new-labeled-email.ts (MIT).
|
|
6
|
+
// Generated by packages/scripts/vendor-ap.mjs - do not edit by hand.
|
|
7
|
+
const pieces_framework_1 = require("@agnocon/pieces-framework");
|
|
8
|
+
const props_1 = require("../common/props");
|
|
9
|
+
const auth_1 = require("../auth");
|
|
10
|
+
const gmail_1 = require("@googleapis/gmail");
|
|
11
|
+
const data_1 = require("../common/data");
|
|
12
|
+
const output_schemas_1 = require("../output-schemas");
|
|
13
|
+
function enrichGmailMessage(_a) {
|
|
14
|
+
return tslib_1.__awaiter(this, arguments, void 0, function* ({ gmail, messageId, files, labelInfo, }) {
|
|
15
|
+
const rawMailResponse = yield gmail.users.messages.get({
|
|
16
|
+
userId: 'me',
|
|
17
|
+
id: messageId,
|
|
18
|
+
format: 'raw',
|
|
19
|
+
});
|
|
20
|
+
const threadResponse = yield gmail.users.threads.get({
|
|
21
|
+
userId: 'me',
|
|
22
|
+
id: rawMailResponse.data.threadId,
|
|
23
|
+
});
|
|
24
|
+
const parsedMailResponse = yield (0, data_1.parseStream)(Buffer.from(rawMailResponse.data.raw, 'base64').toString('utf-8'));
|
|
25
|
+
return {
|
|
26
|
+
message: Object.assign(Object.assign({}, parsedMailResponse), { attachments: yield (0, data_1.convertAttachment)(parsedMailResponse.attachments, files) }),
|
|
27
|
+
thread: threadResponse.data,
|
|
28
|
+
labelInfo: Object.assign(Object.assign({}, labelInfo), { addedAt: Date.now() }),
|
|
29
|
+
};
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
exports.gmailNewLabeledEmailTrigger = (0, pieces_framework_1.createTrigger)({
|
|
33
|
+
auth: auth_1.gmailAuth,
|
|
34
|
+
name: 'new_labeled_email',
|
|
35
|
+
displayName: 'New Labeled Email',
|
|
36
|
+
description: 'Triggers when a label is added to an email',
|
|
37
|
+
aiMetadata: {
|
|
38
|
+
description: 'Fires when the specified label is applied to an email (either newly received with the label or labeled afterward). Each event represents one message that just gained that label, with its parsed contents and label info.',
|
|
39
|
+
},
|
|
40
|
+
props: {
|
|
41
|
+
label: props_1.GmailProps.label({
|
|
42
|
+
required: true,
|
|
43
|
+
}),
|
|
44
|
+
},
|
|
45
|
+
outputSchema: output_schemas_1.newLabeledEmailTriggerOutputSchema,
|
|
46
|
+
sampleData: {},
|
|
47
|
+
type: pieces_framework_1.TriggerStrategy.POLLING,
|
|
48
|
+
onEnable: (context) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
49
|
+
const authClient = yield (0, auth_1.createGoogleClient)(context.auth);
|
|
50
|
+
const gmail = (0, gmail_1.gmail)({ version: 'v1', auth: authClient });
|
|
51
|
+
const profile = yield gmail.users.getProfile({
|
|
52
|
+
userId: 'me',
|
|
53
|
+
});
|
|
54
|
+
yield context.store.put('lastHistoryId', profile.data.historyId);
|
|
55
|
+
}),
|
|
56
|
+
onDisable: (context) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
57
|
+
yield context.store.delete('lastHistoryId');
|
|
58
|
+
}),
|
|
59
|
+
run: (context) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
60
|
+
var _a, _b, _c, _d, _e, _f;
|
|
61
|
+
const authClient = yield (0, auth_1.createGoogleClient)(context.auth);
|
|
62
|
+
const gmail = (0, gmail_1.gmail)({ version: 'v1', auth: authClient });
|
|
63
|
+
const lastHistoryId = yield context.store.get('lastHistoryId');
|
|
64
|
+
const historyResponse = yield gmail.users.history.list({
|
|
65
|
+
userId: 'me',
|
|
66
|
+
startHistoryId: lastHistoryId,
|
|
67
|
+
labelId: context.propsValue.label.id,
|
|
68
|
+
historyTypes: ['labelAdded', 'messageAdded'],
|
|
69
|
+
});
|
|
70
|
+
const labeledMessages = new Map();
|
|
71
|
+
const results = [];
|
|
72
|
+
if (historyResponse.data.history) {
|
|
73
|
+
for (const history of historyResponse.data.history) {
|
|
74
|
+
if (history.labelsAdded) {
|
|
75
|
+
for (const labelAdded of history.labelsAdded) {
|
|
76
|
+
if (((_a = labelAdded.labelIds) === null || _a === void 0 ? void 0 : _a.includes(context.propsValue.label.id)) &&
|
|
77
|
+
((_b = labelAdded.message) === null || _b === void 0 ? void 0 : _b.id)) {
|
|
78
|
+
labeledMessages.set(labelAdded.message.id, ((_c = history.id) === null || _c === void 0 ? void 0 : _c.toString()) || '');
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
else if (history.messagesAdded) {
|
|
83
|
+
for (const messageAdded of history.messagesAdded) {
|
|
84
|
+
if (((_d = messageAdded.message) === null || _d === void 0 ? void 0 : _d.id) &&
|
|
85
|
+
((_e = messageAdded.message.labelIds) === null || _e === void 0 ? void 0 : _e.includes(context.propsValue.label.id))) {
|
|
86
|
+
labeledMessages.set(messageAdded.message.id, ((_f = history.id) === null || _f === void 0 ? void 0 : _f.toString()) || '');
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
for (const [messageId, historyId] of labeledMessages) {
|
|
93
|
+
const enrichedMessage = yield enrichGmailMessage({
|
|
94
|
+
gmail,
|
|
95
|
+
messageId,
|
|
96
|
+
files: context.files,
|
|
97
|
+
labelInfo: {
|
|
98
|
+
labelId: context.propsValue.label.id,
|
|
99
|
+
labelName: context.propsValue.label.name,
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
if (lastHistoryId !== historyId) {
|
|
103
|
+
results.push({
|
|
104
|
+
id: historyId,
|
|
105
|
+
data: enrichedMessage,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
if (historyResponse.data.historyId) {
|
|
110
|
+
yield context.store.put('lastHistoryId', historyResponse.data.historyId);
|
|
111
|
+
}
|
|
112
|
+
return results;
|
|
113
|
+
}),
|
|
114
|
+
test: (context) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
115
|
+
const authClient = yield (0, auth_1.createGoogleClient)(context.auth);
|
|
116
|
+
const gmail = (0, gmail_1.gmail)({ version: 'v1', auth: authClient });
|
|
117
|
+
const messagesResponse = yield gmail.users.messages.list({
|
|
118
|
+
userId: 'me',
|
|
119
|
+
labelIds: [context.propsValue.label.id],
|
|
120
|
+
maxResults: 5,
|
|
121
|
+
});
|
|
122
|
+
const results = [];
|
|
123
|
+
if (messagesResponse.data.messages) {
|
|
124
|
+
for (const message of messagesResponse.data.messages) {
|
|
125
|
+
const messageId = message.id;
|
|
126
|
+
if (!messageId) {
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
const enrichedMessage = yield enrichGmailMessage({
|
|
130
|
+
gmail,
|
|
131
|
+
messageId: messageId,
|
|
132
|
+
files: context.files,
|
|
133
|
+
labelInfo: {
|
|
134
|
+
labelId: context.propsValue.label.id,
|
|
135
|
+
labelName: context.propsValue.label.name,
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
results.push({
|
|
139
|
+
id: messageId,
|
|
140
|
+
data: enrichedMessage,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return results;
|
|
145
|
+
}),
|
|
146
|
+
});
|
|
147
|
+
//# sourceMappingURL=new-labeled-email.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"new-labeled-email.js","sourceRoot":"","sources":["../../../src/lib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IAAI,gBAAgB,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACnC,KAAK,MAAM,OAAO,IAAI,gBAAgB,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACrD,MAAM,SAAS,GAAG,OAAO,CAAC,EAAE,CAAC;gBAC7B,IAAI,CAAC,SAAS,EAAE,CAAC;oBACf,SAAS;gBACX,CAAC;gBACD,MAAM,eAAe,GAAG,MAAM,kBAAkB,CAAC;oBAC/C,KAAK;oBACL,SAAS,EAAE,SAAS;oBACpB,KAAK,EAAE,OAAO,CAAC,KAAK;oBACpB,SAAS,EAAE;wBACT,OAAO,EAAE,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE;wBACpC,SAAS,EAAE,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI;qBACzC;iBACF,CAAC,CAAC;gBAEH,OAAO,CAAC,IAAI,CAAC;oBACX,EAAE,EAAE,SAAS;oBACb,IAAI,EAAE,eAAe;iBACtB,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC,CAAA;CACF,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,56 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@divyacon/piece-gmail",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "DivyaCon Gmail connector",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"require": "./dist/index.js",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"src",
|
|
17
|
+
"LICENSE.MIT-AP"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsc -p tsconfig.json",
|
|
21
|
+
"vendor": "node ../scripts/vendor-ap.mjs piece-gmail"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@agnocon/core-utils": "0.2.0",
|
|
25
|
+
"@agnocon/piece-types": "0.3.1",
|
|
26
|
+
"@agnocon/pieces-common": "0.12.8",
|
|
27
|
+
"@agnocon/pieces-framework": "0.36.0",
|
|
28
|
+
"tslib": "2.6.2",
|
|
29
|
+
"@googleapis/gmail": "17.0.0",
|
|
30
|
+
"@googleapis/oauth2": "5.0.1",
|
|
31
|
+
"dayjs": "1.11.9",
|
|
32
|
+
"google-auth-library": "10.5.0",
|
|
33
|
+
"mailparser": "3.9.3",
|
|
34
|
+
"mime-types": "2.1.35",
|
|
35
|
+
"nodemailer": "8.0.5"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@types/node": "20.17.6",
|
|
39
|
+
"typescript": "5.5.4",
|
|
40
|
+
"@types/mime-types": "2.1.1",
|
|
41
|
+
"@types/mailparser": "3.4.6",
|
|
42
|
+
"@types/nodemailer": "7.0.11"
|
|
43
|
+
},
|
|
44
|
+
"license": "MIT",
|
|
45
|
+
"agnocon": {
|
|
46
|
+
"originVersion": "0.12.10"
|
|
47
|
+
},
|
|
48
|
+
"publishConfig": {
|
|
49
|
+
"access": "public",
|
|
50
|
+
"tag": "latest"
|
|
51
|
+
},
|
|
52
|
+
"keywords": [
|
|
53
|
+
"agnocon",
|
|
54
|
+
"connector"
|
|
55
|
+
]
|
|
6
56
|
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { createCustomApiCallAction } from '@agnocon/pieces-common';
|
|
2
|
+
import { createPiece } from '@agnocon/pieces-framework';
|
|
3
|
+
import { PieceCategory } from '@agnocon/pieces-framework';
|
|
4
|
+
import { gmailSendEmailAction } from './lib/actions/send-email-action';
|
|
5
|
+
import { gmailReplyToEmailAction } from './lib/actions/reply-to-email-action';
|
|
6
|
+
import { gmailCreateDraftReplyAction } from './lib/actions/create-draft-reply-action';
|
|
7
|
+
import { gmailNewEmailTrigger } from './lib/triggers/new-email';
|
|
8
|
+
import { gmailNewLabeledEmailTrigger } from './lib/triggers/new-labeled-email';
|
|
9
|
+
import { requestApprovalInEmail } from './lib/actions/request-approval-in-email';
|
|
10
|
+
import { gmailNewAttachmentTrigger } from './lib/triggers/new-attachment';
|
|
11
|
+
import { gmailNewLabelTrigger } from './lib/triggers/new-label';
|
|
12
|
+
import { gmailSearchMailAction } from './lib/actions/search-email-action';
|
|
13
|
+
import { gmailGetEmailAction } from './lib/actions/get-mail-action';
|
|
14
|
+
import { gmailAuth, getAccessToken, GmailAuthValue } from './lib/auth';
|
|
15
|
+
import { gmailAiSendEmailAction } from './lib/actions/ai-send-email-action';
|
|
16
|
+
import { gmailAiReplyToThreadAction } from './lib/actions/ai-reply-to-thread-action';
|
|
17
|
+
import { gmailAiGetMessageAction } from './lib/actions/ai-get-message-action';
|
|
18
|
+
import { gmailAiSearchEmailAction } from './lib/actions/ai-search-email-action';
|
|
19
|
+
import { gmailGetThread } from './lib/actions/get-thread-action';
|
|
20
|
+
import { gmailCreateDraftAction } from './lib/actions/create-draft-action';
|
|
21
|
+
import { gmailUpdateDraftAction } from './lib/actions/update-draft-action';
|
|
22
|
+
import { gmailSendDraftAction } from './lib/actions/send-draft-action';
|
|
23
|
+
import { gmailGetDraftAction } from './lib/actions/get-draft-action';
|
|
24
|
+
import { gmailListDraftsAction } from './lib/actions/list-drafts-action';
|
|
25
|
+
import { gmailDeleteDraftAction } from './lib/actions/delete-draft-action';
|
|
26
|
+
import { gmailListThreadsAction } from './lib/actions/list-threads-action';
|
|
27
|
+
import { gmailGetAttachmentAction } from './lib/actions/get-attachment-action';
|
|
28
|
+
import { gmailForwardMessageAction } from './lib/actions/forward-message-action';
|
|
29
|
+
import { gmailListLabelsAction } from './lib/actions/list-labels-action';
|
|
30
|
+
import { gmailGetLabelAction } from './lib/actions/get-label-action';
|
|
31
|
+
import { gmailGetProfileAction } from './lib/actions/get-profile-action';
|
|
32
|
+
import { gmailListHistoryAction } from './lib/actions/list-history-action';
|
|
33
|
+
import { gmailStopWatchAction } from './lib/actions/stop-watch-action';
|
|
34
|
+
|
|
35
|
+
export {
|
|
36
|
+
gmailAuth,
|
|
37
|
+
getAccessToken,
|
|
38
|
+
GmailAuthValue,
|
|
39
|
+
createGoogleClient,
|
|
40
|
+
} from './lib/auth';
|
|
41
|
+
|
|
42
|
+
export const gmail = createPiece({
|
|
43
|
+
minimumSupportedRelease: '0.87.0',
|
|
44
|
+
logoUrl: 'https://cdn.activepieces.com/pieces/gmail.png',
|
|
45
|
+
categories: [
|
|
46
|
+
PieceCategory.COMMUNICATION,
|
|
47
|
+
PieceCategory.BUSINESS_INTELLIGENCE,
|
|
48
|
+
],
|
|
49
|
+
actions: [
|
|
50
|
+
gmailSendEmailAction,
|
|
51
|
+
requestApprovalInEmail,
|
|
52
|
+
gmailReplyToEmailAction,
|
|
53
|
+
gmailCreateDraftReplyAction,
|
|
54
|
+
gmailGetEmailAction,
|
|
55
|
+
gmailSearchMailAction,
|
|
56
|
+
gmailAiSendEmailAction,
|
|
57
|
+
gmailAiReplyToThreadAction,
|
|
58
|
+
gmailAiGetMessageAction,
|
|
59
|
+
gmailAiSearchEmailAction,
|
|
60
|
+
gmailGetThread,
|
|
61
|
+
gmailCreateDraftAction,
|
|
62
|
+
gmailUpdateDraftAction,
|
|
63
|
+
gmailSendDraftAction,
|
|
64
|
+
gmailGetDraftAction,
|
|
65
|
+
gmailListDraftsAction,
|
|
66
|
+
gmailDeleteDraftAction,
|
|
67
|
+
gmailListThreadsAction,
|
|
68
|
+
gmailGetAttachmentAction,
|
|
69
|
+
gmailForwardMessageAction,
|
|
70
|
+
gmailListLabelsAction,
|
|
71
|
+
gmailGetLabelAction,
|
|
72
|
+
gmailGetProfileAction,
|
|
73
|
+
gmailListHistoryAction,
|
|
74
|
+
gmailStopWatchAction,
|
|
75
|
+
createCustomApiCallAction({
|
|
76
|
+
baseUrl: () => 'https://gmail.googleapis.com/gmail/v1',
|
|
77
|
+
auth: gmailAuth,
|
|
78
|
+
authMapping: async (auth) => ({
|
|
79
|
+
Authorization: `Bearer ${await getAccessToken(auth as GmailAuthValue)}`,
|
|
80
|
+
}),
|
|
81
|
+
}),
|
|
82
|
+
],
|
|
83
|
+
displayName: 'Gmail',
|
|
84
|
+
description: 'Email service by Google',
|
|
85
|
+
|
|
86
|
+
authors: [
|
|
87
|
+
'kanarelo',
|
|
88
|
+
'abdullahranginwala',
|
|
89
|
+
'BastienMe',
|
|
90
|
+
'Salem-Alaa',
|
|
91
|
+
'kishanprmr',
|
|
92
|
+
'MoShizzle',
|
|
93
|
+
'AbdulTheActivePiecer',
|
|
94
|
+
'khaledmashaly',
|
|
95
|
+
'abuaboud',
|
|
96
|
+
'AdamSelene',
|
|
97
|
+
'sanket-a11y',
|
|
98
|
+
'onyedikachi-david',
|
|
99
|
+
],
|
|
100
|
+
triggers: [
|
|
101
|
+
gmailNewEmailTrigger,
|
|
102
|
+
gmailNewLabeledEmailTrigger,
|
|
103
|
+
gmailNewAttachmentTrigger,
|
|
104
|
+
gmailNewLabelTrigger,
|
|
105
|
+
],
|
|
106
|
+
auth: gmailAuth,
|
|
107
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { createAction } from '@agnocon/pieces-framework';
|
|
2
|
+
import { gmailAuth } from '../auth';
|
|
3
|
+
import { gmailGetEmailAction } from './get-mail-action';
|
|
4
|
+
import { gmailAiGetMessageActionOutputSchema } from '../output-schemas';
|
|
5
|
+
|
|
6
|
+
export const gmailAiGetMessageAction = createAction({
|
|
7
|
+
auth: gmailAuth,
|
|
8
|
+
name: 'gmail_get_message',
|
|
9
|
+
displayName: 'Get Message',
|
|
10
|
+
description: 'Get a single email message by its ID.',
|
|
11
|
+
audience: 'ai',
|
|
12
|
+
aiMetadata: {
|
|
13
|
+
description:
|
|
14
|
+
'Fetches a single email by its Gmail message ID and returns its parsed contents, including headers, body, and decoded attachments (each attachment is returned with its downloaded content directly, so a separate Get Attachment call is normally unnecessary). Use this to read the full details of a specific known message; obtain the message ID from Search Email. Idempotent: a read-only lookup that does not modify the mailbox.',
|
|
15
|
+
idempotent: true,
|
|
16
|
+
},
|
|
17
|
+
outputSchema: gmailAiGetMessageActionOutputSchema,
|
|
18
|
+
props: gmailGetEmailAction.props,
|
|
19
|
+
run: gmailGetEmailAction.run,
|
|
20
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { createAction } from '@agnocon/pieces-framework';
|
|
2
|
+
import { gmailAuth } from '../auth';
|
|
3
|
+
import { gmailReplyToEmailAction } from './reply-to-email-action';
|
|
4
|
+
import { gmailAiReplyToThreadActionOutputSchema } from '../output-schemas';
|
|
5
|
+
|
|
6
|
+
export const gmailAiReplyToThreadAction = createAction({
|
|
7
|
+
auth: gmailAuth,
|
|
8
|
+
name: 'gmail_reply_to_thread',
|
|
9
|
+
displayName: 'Reply to Thread',
|
|
10
|
+
description: 'Reply to an existing email thread.',
|
|
11
|
+
audience: 'ai',
|
|
12
|
+
aiMetadata: {
|
|
13
|
+
description:
|
|
14
|
+
'Sends a reply to an existing email, preserving the thread and subject and addressing the original sender (reply) or all participants (reply all). Use this to respond within a known conversation; requires the Gmail message ID of the email being answered (obtain it from Search Email or Get Thread). Not idempotent: each call sends a new reply into the thread.',
|
|
15
|
+
idempotent: false,
|
|
16
|
+
},
|
|
17
|
+
outputSchema: gmailAiReplyToThreadActionOutputSchema,
|
|
18
|
+
props: gmailReplyToEmailAction.props,
|
|
19
|
+
run: gmailReplyToEmailAction.run,
|
|
20
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { createAction } from '@agnocon/pieces-framework';
|
|
2
|
+
import { gmailAuth } from '../auth';
|
|
3
|
+
import { gmailSearchMailAction } from './search-email-action';
|
|
4
|
+
import { gmailAiSearchEmailActionOutputSchema } from '../output-schemas';
|
|
5
|
+
|
|
6
|
+
export const gmailAiSearchEmailAction = createAction({
|
|
7
|
+
auth: gmailAuth,
|
|
8
|
+
name: 'gmail_search_email',
|
|
9
|
+
displayName: 'Search Email',
|
|
10
|
+
description:
|
|
11
|
+
'Search emails using advanced criteria. If no filters are provided, the latest emails are returned.',
|
|
12
|
+
audience: 'ai',
|
|
13
|
+
aiMetadata: {
|
|
14
|
+
description:
|
|
15
|
+
'Searches the mailbox for emails matching combinable filters (sender, recipient, subject, body text, label, category, date range, attachment presence/name) and returns the matched messages with parsed contents and their message IDs. Use this as the primary resolver to locate messages or discover their message IDs before reading or replying to them; with no filters it returns the most recent emails. Bound results with Max Results (1-500, default 10). Idempotent: a read-only search that does not modify the mailbox.',
|
|
16
|
+
idempotent: true,
|
|
17
|
+
},
|
|
18
|
+
outputSchema: gmailAiSearchEmailActionOutputSchema,
|
|
19
|
+
props: gmailSearchMailAction.props,
|
|
20
|
+
run: gmailSearchMailAction.run,
|
|
21
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { createAction } from '@agnocon/pieces-framework';
|
|
2
|
+
import { gmailAuth } from '../auth';
|
|
3
|
+
import { gmailSendEmailAction } from './send-email-action';
|
|
4
|
+
import { gmailAiSendEmailActionOutputSchema } from '../output-schemas';
|
|
5
|
+
|
|
6
|
+
export const gmailAiSendEmailAction = createAction({
|
|
7
|
+
auth: gmailAuth,
|
|
8
|
+
name: 'gmail_send_email',
|
|
9
|
+
displayName: 'Send Email',
|
|
10
|
+
description: 'Send an email through a Gmail account',
|
|
11
|
+
audience: 'ai',
|
|
12
|
+
aiMetadata: {
|
|
13
|
+
description:
|
|
14
|
+
'Composes and sends a new email from the connected Gmail account to one or more recipients, with optional CC/BCC, attachments, and a plain-text or HTML body. Use this to originate a fresh message; to answer an existing conversation prefer Reply to Thread, and to save an unsent message use Create Draft. Not idempotent: each call sends a separate message.',
|
|
15
|
+
idempotent: false,
|
|
16
|
+
},
|
|
17
|
+
outputSchema: gmailAiSendEmailActionOutputSchema,
|
|
18
|
+
props: gmailSendEmailAction.props,
|
|
19
|
+
run: gmailSendEmailAction.run,
|
|
20
|
+
});
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { ApFile, createAction, Property } from '@agnocon/pieces-framework';
|
|
2
|
+
import { gmailAuth, createGoogleClient, getUserEmail } from '../auth';
|
|
3
|
+
import { gmail as googleGmail } from '@googleapis/gmail';
|
|
4
|
+
import { GmailMime } from '../common/mime';
|
|
5
|
+
import { gmailCreateDraftActionOutputSchema } from '../output-schemas';
|
|
6
|
+
|
|
7
|
+
export const gmailCreateDraftAction = createAction({
|
|
8
|
+
auth: gmailAuth,
|
|
9
|
+
name: 'gmail_create_draft',
|
|
10
|
+
displayName: 'Create Draft',
|
|
11
|
+
description:
|
|
12
|
+
'Create a new draft email (optionally inside an existing thread).',
|
|
13
|
+
audience: 'ai',
|
|
14
|
+
aiMetadata: {
|
|
15
|
+
description:
|
|
16
|
+
'Creates an unsent draft email with the given recipients, subject, body, and optional attachments, optionally placing it inside an existing thread. Use this when a message should be saved for later review or sending rather than sent immediately; send it afterwards with Send Draft. To attach the draft to a conversation, pass a thread ID from Search Email or Get Thread. Not idempotent: each call creates a separate draft.',
|
|
17
|
+
idempotent: false,
|
|
18
|
+
},
|
|
19
|
+
props: {
|
|
20
|
+
receiver: Property.Array({
|
|
21
|
+
displayName: 'Receiver Email (To)',
|
|
22
|
+
required: false,
|
|
23
|
+
}),
|
|
24
|
+
cc: Property.Array({
|
|
25
|
+
displayName: 'CC Email',
|
|
26
|
+
required: false,
|
|
27
|
+
}),
|
|
28
|
+
bcc: Property.Array({
|
|
29
|
+
displayName: 'BCC Email',
|
|
30
|
+
required: false,
|
|
31
|
+
}),
|
|
32
|
+
subject: Property.ShortText({
|
|
33
|
+
displayName: 'Subject',
|
|
34
|
+
required: true,
|
|
35
|
+
}),
|
|
36
|
+
body_type: Property.StaticDropdown({
|
|
37
|
+
displayName: 'Body Type',
|
|
38
|
+
required: true,
|
|
39
|
+
defaultValue: 'plain_text',
|
|
40
|
+
options: {
|
|
41
|
+
disabled: false,
|
|
42
|
+
options: [
|
|
43
|
+
{ label: 'plain text', value: 'plain_text' },
|
|
44
|
+
{ label: 'html', value: 'html' },
|
|
45
|
+
],
|
|
46
|
+
},
|
|
47
|
+
}),
|
|
48
|
+
body: Property.LongText({
|
|
49
|
+
displayName: 'Body',
|
|
50
|
+
description: 'Body for the draft email.',
|
|
51
|
+
required: true,
|
|
52
|
+
}),
|
|
53
|
+
sender_name: Property.ShortText({
|
|
54
|
+
displayName: 'Sender Name',
|
|
55
|
+
required: false,
|
|
56
|
+
}),
|
|
57
|
+
from: Property.ShortText({
|
|
58
|
+
displayName: 'Sender Email',
|
|
59
|
+
description:
|
|
60
|
+
"The address must be listed in your Gmail account's settings.",
|
|
61
|
+
required: false,
|
|
62
|
+
}),
|
|
63
|
+
thread_id: Property.ShortText({
|
|
64
|
+
displayName: 'Thread ID',
|
|
65
|
+
description:
|
|
66
|
+
'Optional thread ID to attach this draft to an existing conversation (obtain from Search Email or Get Thread).',
|
|
67
|
+
required: false,
|
|
68
|
+
}),
|
|
69
|
+
attachments: Property.Array({
|
|
70
|
+
displayName: 'Attachments',
|
|
71
|
+
required: false,
|
|
72
|
+
properties: {
|
|
73
|
+
file: Property.File({
|
|
74
|
+
displayName: 'File',
|
|
75
|
+
description: 'File to attach to the draft.',
|
|
76
|
+
required: true,
|
|
77
|
+
}),
|
|
78
|
+
name: Property.ShortText({
|
|
79
|
+
displayName: 'Attachment Name',
|
|
80
|
+
description: 'Optional name to override the attachment filename.',
|
|
81
|
+
required: false,
|
|
82
|
+
}),
|
|
83
|
+
},
|
|
84
|
+
}),
|
|
85
|
+
},
|
|
86
|
+
outputSchema: gmailCreateDraftActionOutputSchema,
|
|
87
|
+
async run(context) {
|
|
88
|
+
const authClient = await createGoogleClient(context.auth);
|
|
89
|
+
const gmail = googleGmail({ version: 'v1', auth: authClient });
|
|
90
|
+
|
|
91
|
+
try {
|
|
92
|
+
const receiver = (
|
|
93
|
+
context.propsValue.receiver as string[] | undefined
|
|
94
|
+
)?.filter((email) => email !== '');
|
|
95
|
+
const cc = (context.propsValue.cc as string[] | undefined)?.filter(
|
|
96
|
+
(email) => email !== ''
|
|
97
|
+
);
|
|
98
|
+
const bcc = (context.propsValue.bcc as string[] | undefined)?.filter(
|
|
99
|
+
(email) => email !== ''
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
const senderEmail =
|
|
103
|
+
context.propsValue.from ||
|
|
104
|
+
(await getUserEmail(context.auth, authClient));
|
|
105
|
+
const from = senderEmail
|
|
106
|
+
? context.propsValue.sender_name
|
|
107
|
+
? `${context.propsValue.sender_name} <${senderEmail}>`
|
|
108
|
+
: senderEmail
|
|
109
|
+
: undefined;
|
|
110
|
+
|
|
111
|
+
const raw = await GmailMime.buildRawMessage({
|
|
112
|
+
to: receiver,
|
|
113
|
+
cc,
|
|
114
|
+
bcc,
|
|
115
|
+
from,
|
|
116
|
+
subject: context.propsValue.subject,
|
|
117
|
+
bodyType: context.propsValue.body_type as 'plain_text' | 'html',
|
|
118
|
+
body: context.propsValue.body,
|
|
119
|
+
attachments: context.propsValue.attachments as
|
|
120
|
+
| { file: ApFile; name?: string }[]
|
|
121
|
+
| undefined,
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
const response = await gmail.users.drafts.create({
|
|
125
|
+
userId: 'me',
|
|
126
|
+
requestBody: {
|
|
127
|
+
message: {
|
|
128
|
+
raw,
|
|
129
|
+
threadId: context.propsValue.thread_id || undefined,
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
return response.data;
|
|
135
|
+
} catch (error: any) {
|
|
136
|
+
if (error.code === 403) {
|
|
137
|
+
throw new Error(
|
|
138
|
+
'Insufficient permissions to create a draft. Ensure the gmail.compose scope is granted.'
|
|
139
|
+
);
|
|
140
|
+
} else if (error.code === 429) {
|
|
141
|
+
throw new Error(
|
|
142
|
+
'Gmail API rate limit exceeded. Please try again later.'
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
throw new Error(`Failed to create draft: ${error.message}`);
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
});
|