@scopieflows/app-gmail 0.11.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/README.md +7 -0
- package/package.json +32 -0
- package/src/i18n/ca.json +63 -0
- package/src/i18n/de.json +66 -0
- package/src/i18n/es.json +66 -0
- package/src/i18n/fr.json +66 -0
- package/src/i18n/hi.json +63 -0
- package/src/i18n/id.json +63 -0
- package/src/i18n/ja.json +66 -0
- package/src/i18n/nl.json +66 -0
- package/src/i18n/pt.json +66 -0
- package/src/i18n/ru.json +63 -0
- package/src/i18n/translation.json +66 -0
- package/src/i18n/vi.json +63 -0
- package/src/i18n/zh.json +66 -0
- package/src/index.d.ts +2 -0
- package/src/index.js +78 -0
- package/src/index.js.map +1 -0
- package/src/lib/actions/create-draft-reply-action.d.ts +10 -0
- package/src/lib/actions/create-draft-reply-action.js +262 -0
- package/src/lib/actions/create-draft-reply-action.js.map +1 -0
- package/src/lib/actions/get-mail-action.d.ts +3 -0
- package/src/lib/actions/get-mail-action.js +37 -0
- package/src/lib/actions/get-mail-action.js.map +1 -0
- package/src/lib/actions/get-thread-action.d.ts +5 -0
- package/src/lib/actions/get-thread-action.js +44 -0
- package/src/lib/actions/get-thread-action.js.map +1 -0
- package/src/lib/actions/reply-to-email-action.d.ts +9 -0
- package/src/lib/actions/reply-to-email-action.js +195 -0
- package/src/lib/actions/reply-to-email-action.js.map +1 -0
- package/src/lib/actions/request-approval-in-email.d.ts +11 -0
- package/src/lib/actions/request-approval-in-email.js +176 -0
- package/src/lib/actions/request-approval-in-email.js.map +1 -0
- package/src/lib/actions/search-email-action.d.ts +15 -0
- package/src/lib/actions/search-email-action.js +180 -0
- package/src/lib/actions/search-email-action.js.map +1 -0
- package/src/lib/actions/send-email-action.d.ts +14 -0
- package/src/lib/actions/send-email-action.js +191 -0
- package/src/lib/actions/send-email-action.js.map +1 -0
- package/src/lib/common/data.d.ts +131 -0
- package/src/lib/common/data.js +208 -0
- package/src/lib/common/data.js.map +1 -0
- package/src/lib/common/models.d.ts +85 -0
- package/src/lib/common/models.js +26 -0
- package/src/lib/common/models.js.map +1 -0
- package/src/lib/common/props.d.ts +11 -0
- package/src/lib/common/props.js +229 -0
- package/src/lib/common/props.js.map +1 -0
- package/src/lib/triggers/new-attachment.d.ts +171 -0
- package/src/lib/triggers/new-attachment.js +128 -0
- package/src/lib/triggers/new-attachment.js.map +1 -0
- package/src/lib/triggers/new-conversation.d.ts +46 -0
- package/src/lib/triggers/new-conversation.js +310 -0
- package/src/lib/triggers/new-conversation.js.map +1 -0
- package/src/lib/triggers/new-email.d.ts +27 -0
- package/src/lib/triggers/new-email.js +117 -0
- package/src/lib/triggers/new-email.js.map +1 -0
- package/src/lib/triggers/new-label.d.ts +2 -0
- package/src/lib/triggers/new-label.js +79 -0
- package/src/lib/triggers/new-label.js.map +1 -0
- package/src/lib/triggers/new-labeled-email.d.ts +62 -0
- package/src/lib/triggers/new-labeled-email.js +142 -0
- package/src/lib/triggers/new-labeled-email.js.map +1 -0
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.gmailSearchMailAction = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const pieces_framework_1 = require("@scopieflows/pieces-framework");
|
|
6
|
+
const __1 = require("../../");
|
|
7
|
+
const googleapis_1 = require("googleapis");
|
|
8
|
+
const googleapis_common_1 = require("googleapis-common");
|
|
9
|
+
const data_1 = require("../common/data");
|
|
10
|
+
const props_1 = require("../common/props");
|
|
11
|
+
exports.gmailSearchMailAction = (0, pieces_framework_1.createAction)({
|
|
12
|
+
auth: __1.gmailAuth,
|
|
13
|
+
name: 'gmail_search_mail',
|
|
14
|
+
displayName: 'Find Email',
|
|
15
|
+
description: 'Find emails using advanced search criteria.',
|
|
16
|
+
props: {
|
|
17
|
+
from: props_1.GmailProps.from,
|
|
18
|
+
to: props_1.GmailProps.to,
|
|
19
|
+
subject: props_1.GmailProps.subject,
|
|
20
|
+
content: pieces_framework_1.Property.ShortText({
|
|
21
|
+
displayName: 'Email Content',
|
|
22
|
+
description: 'Search for specific text within email body',
|
|
23
|
+
required: false,
|
|
24
|
+
}),
|
|
25
|
+
has_attachment: pieces_framework_1.Property.Checkbox({
|
|
26
|
+
displayName: 'Has Attachment',
|
|
27
|
+
description: 'Only find emails with attachments',
|
|
28
|
+
required: false,
|
|
29
|
+
defaultValue: false,
|
|
30
|
+
}),
|
|
31
|
+
attachment_name: pieces_framework_1.Property.ShortText({
|
|
32
|
+
displayName: 'Attachment Name',
|
|
33
|
+
description: 'Search for emails with specific attachment filename',
|
|
34
|
+
required: false,
|
|
35
|
+
}),
|
|
36
|
+
label: props_1.GmailProps.label,
|
|
37
|
+
category: props_1.GmailProps.category,
|
|
38
|
+
after_date: pieces_framework_1.Property.DateTime({
|
|
39
|
+
displayName: 'After Date',
|
|
40
|
+
description: 'Find emails sent after this date',
|
|
41
|
+
required: false,
|
|
42
|
+
}),
|
|
43
|
+
before_date: pieces_framework_1.Property.DateTime({
|
|
44
|
+
displayName: 'Before Date',
|
|
45
|
+
description: 'Find emails sent before this date',
|
|
46
|
+
required: false,
|
|
47
|
+
}),
|
|
48
|
+
include_spam_trash: pieces_framework_1.Property.Checkbox({
|
|
49
|
+
displayName: 'Include Spam & Trash',
|
|
50
|
+
description: 'Include emails from Spam and Trash folders in search results',
|
|
51
|
+
required: false,
|
|
52
|
+
defaultValue: false,
|
|
53
|
+
}),
|
|
54
|
+
max_results: pieces_framework_1.Property.Number({
|
|
55
|
+
displayName: 'Max Results',
|
|
56
|
+
description: 'Maximum number of emails to return (1-500)',
|
|
57
|
+
required: false,
|
|
58
|
+
defaultValue: 10,
|
|
59
|
+
}),
|
|
60
|
+
},
|
|
61
|
+
run(context) {
|
|
62
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
64
|
+
const authClient = new googleapis_common_1.OAuth2Client();
|
|
65
|
+
authClient.setCredentials(context.auth);
|
|
66
|
+
const gmail = googleapis_1.google.gmail({ version: 'v1', auth: authClient });
|
|
67
|
+
const queryParts = [];
|
|
68
|
+
if ((_a = context.propsValue.from) === null || _a === void 0 ? void 0 : _a.trim()) {
|
|
69
|
+
queryParts.push(`from:(${context.propsValue.from.trim()})`);
|
|
70
|
+
}
|
|
71
|
+
if ((_b = context.propsValue.to) === null || _b === void 0 ? void 0 : _b.trim()) {
|
|
72
|
+
queryParts.push(`to:(${context.propsValue.to.trim()})`);
|
|
73
|
+
}
|
|
74
|
+
if ((_c = context.propsValue.subject) === null || _c === void 0 ? void 0 : _c.trim()) {
|
|
75
|
+
queryParts.push(`subject:(${context.propsValue.subject.trim()})`);
|
|
76
|
+
}
|
|
77
|
+
if ((_d = context.propsValue.content) === null || _d === void 0 ? void 0 : _d.trim()) {
|
|
78
|
+
queryParts.push(`"${context.propsValue.content.trim()}"`);
|
|
79
|
+
}
|
|
80
|
+
if (context.propsValue.has_attachment) {
|
|
81
|
+
queryParts.push('has:attachment');
|
|
82
|
+
}
|
|
83
|
+
if ((_e = context.propsValue.attachment_name) === null || _e === void 0 ? void 0 : _e.trim()) {
|
|
84
|
+
queryParts.push(`filename:(${context.propsValue.attachment_name.trim()})`);
|
|
85
|
+
}
|
|
86
|
+
if (context.propsValue.label) {
|
|
87
|
+
const label = context.propsValue.label;
|
|
88
|
+
queryParts.push(`label:${label.name}`);
|
|
89
|
+
}
|
|
90
|
+
if ((_f = context.propsValue.category) === null || _f === void 0 ? void 0 : _f.trim()) {
|
|
91
|
+
queryParts.push(`category:${context.propsValue.category.trim()}`);
|
|
92
|
+
}
|
|
93
|
+
if (context.propsValue.after_date) {
|
|
94
|
+
const afterDate = new Date(context.propsValue.after_date);
|
|
95
|
+
const afterDateStr = afterDate
|
|
96
|
+
.toISOString()
|
|
97
|
+
.split('T')[0]
|
|
98
|
+
.replace(/-/g, '/');
|
|
99
|
+
queryParts.push(`after:${afterDateStr}`);
|
|
100
|
+
}
|
|
101
|
+
if (context.propsValue.before_date) {
|
|
102
|
+
const beforeDate = new Date(context.propsValue.before_date);
|
|
103
|
+
const beforeDateStr = beforeDate
|
|
104
|
+
.toISOString()
|
|
105
|
+
.split('T')[0]
|
|
106
|
+
.replace(/-/g, '/');
|
|
107
|
+
queryParts.push(`before:${beforeDateStr}`);
|
|
108
|
+
}
|
|
109
|
+
const searchQuery = queryParts.join(' ');
|
|
110
|
+
if (!searchQuery.trim()) {
|
|
111
|
+
throw new Error('Please provide at least one search criterion');
|
|
112
|
+
}
|
|
113
|
+
const maxResults = Math.min(Math.max(context.propsValue.max_results || 10, 1), 500);
|
|
114
|
+
try {
|
|
115
|
+
const searchResponse = yield gmail.users.messages.list({
|
|
116
|
+
userId: 'me',
|
|
117
|
+
q: searchQuery,
|
|
118
|
+
maxResults: maxResults,
|
|
119
|
+
includeSpamTrash: context.propsValue.include_spam_trash,
|
|
120
|
+
});
|
|
121
|
+
const messages = searchResponse.data.messages || [];
|
|
122
|
+
if (messages.length === 0) {
|
|
123
|
+
return {
|
|
124
|
+
found: false,
|
|
125
|
+
results: {
|
|
126
|
+
messages: [],
|
|
127
|
+
count: 0,
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
const detailedMessages = yield Promise.all(messages.map((message) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
132
|
+
try {
|
|
133
|
+
const rawMailResponse = yield gmail.users.messages.get({
|
|
134
|
+
userId: 'me',
|
|
135
|
+
id: message.id,
|
|
136
|
+
format: 'raw',
|
|
137
|
+
});
|
|
138
|
+
const parsedMailResponse = yield (0, data_1.parseStream)(Buffer.from(rawMailResponse.data.raw, 'base64').toString('utf-8'));
|
|
139
|
+
return Object.assign(Object.assign({ id: message.id }, parsedMailResponse), { attachments: yield (0, data_1.convertAttachment)(parsedMailResponse.attachments, context.files) });
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
console.error(`Failed to get details for message ${message.id}:`, error);
|
|
143
|
+
return {
|
|
144
|
+
id: message.id,
|
|
145
|
+
threadId: message.threadId,
|
|
146
|
+
error: 'Failed to retrieve message details',
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
})));
|
|
150
|
+
return {
|
|
151
|
+
found: true,
|
|
152
|
+
results: {
|
|
153
|
+
messages: detailedMessages,
|
|
154
|
+
count: detailedMessages.length,
|
|
155
|
+
},
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
// Enhanced error handling
|
|
160
|
+
if (error.code === 400) {
|
|
161
|
+
if ((_g = error.message) === null || _g === void 0 ? void 0 : _g.includes('Invalid query')) {
|
|
162
|
+
throw new Error(`Invalid search query: "${searchQuery}". Please check your search syntax.`);
|
|
163
|
+
}
|
|
164
|
+
throw new Error(`Invalid search request: ${error.message}`);
|
|
165
|
+
}
|
|
166
|
+
else if (error.code === 403) {
|
|
167
|
+
throw new Error('Insufficient permissions to search emails. Ensure the gmail.readonly scope is granted.');
|
|
168
|
+
}
|
|
169
|
+
else if (error.code === 429) {
|
|
170
|
+
throw new Error('Gmail API rate limit exceeded. Please try again later.');
|
|
171
|
+
}
|
|
172
|
+
else if (error.code === 500) {
|
|
173
|
+
throw new Error('Gmail API server error. Please try again later.');
|
|
174
|
+
}
|
|
175
|
+
throw new Error(`Failed to search emails: ${error.message}`);
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
},
|
|
179
|
+
});
|
|
180
|
+
//# sourceMappingURL=search-email-action.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search-email-action.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/community/gmail/src/lib/actions/search-email-action.ts"],"names":[],"mappings":";;;;AAAA,oEAAuE;AACvE,8BAAmC;AACnC,2CAAoC;AACpC,yDAAiD;AACjD,yCAAgE;AAChE,2CAA6C;AAGhC,QAAA,qBAAqB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CAAC;qBAAM,IAAI,KAAK,CAAC,IAAI,KAAK,GAAG,EAAE,CAAC;oBAC9B,MAAM,IAAI,KAAK,CACb,wFAAwF,CACzF,CAAC;gBACJ,CAAC;qBAAM,IAAI,KAAK,CAAC,IAAI,KAAK,GAAG,EAAE,CAAC;oBAC9B,MAAM,IAAI,KAAK,CACb,wDAAwD,CACzD,CAAC;gBACJ,CAAC;qBAAM,IAAI,KAAK,CAAC,IAAI,KAAK,GAAG,EAAE,CAAC;oBAC9B,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;gBACrE,CAAC;gBAED,MAAM,IAAI,KAAK,CAAC,4BAA4B,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;YAC/D,CAAC;QACH,CAAC;KAAA;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const gmailSendEmailAction: import("@scopieflows/pieces-framework").IAction<import("@scopieflows/pieces-framework").OAuth2Property<import("@scopieflows/pieces-framework").OAuth2Props>, {
|
|
2
|
+
receiver: import("@scopieflows/pieces-framework").ArrayProperty<true>;
|
|
3
|
+
cc: import("@scopieflows/pieces-framework").ArrayProperty<false>;
|
|
4
|
+
bcc: import("@scopieflows/pieces-framework").ArrayProperty<false>;
|
|
5
|
+
subject: import("@scopieflows/pieces-framework").ShortTextProperty<true>;
|
|
6
|
+
body_type: import("@scopieflows/pieces-framework").StaticDropdownProperty<string, true>;
|
|
7
|
+
body: import("@scopieflows/pieces-framework").ShortTextProperty<true>;
|
|
8
|
+
reply_to: import("@scopieflows/pieces-framework").ArrayProperty<false>;
|
|
9
|
+
sender_name: import("@scopieflows/pieces-framework").ShortTextProperty<false>;
|
|
10
|
+
from: import("@scopieflows/pieces-framework").ShortTextProperty<false>;
|
|
11
|
+
attachments: import("@scopieflows/pieces-framework").ArrayProperty<true> | import("@scopieflows/pieces-framework").ArrayProperty<false>;
|
|
12
|
+
in_reply_to: import("@scopieflows/pieces-framework").ShortTextProperty<false>;
|
|
13
|
+
draft: import("@scopieflows/pieces-framework").CheckboxProperty<true>;
|
|
14
|
+
}>;
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.gmailSendEmailAction = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const pieces_framework_1 = require("@scopieflows/pieces-framework");
|
|
6
|
+
const mime_types_1 = tslib_1.__importDefault(require("mime-types"));
|
|
7
|
+
const mail_composer_1 = tslib_1.__importDefault(require("nodemailer/lib/mail-composer"));
|
|
8
|
+
const __1 = require("../../");
|
|
9
|
+
const googleapis_1 = require("googleapis");
|
|
10
|
+
const googleapis_common_1 = require("googleapis-common");
|
|
11
|
+
exports.gmailSendEmailAction = (0, pieces_framework_1.createAction)({
|
|
12
|
+
auth: __1.gmailAuth,
|
|
13
|
+
name: 'send_email',
|
|
14
|
+
description: 'Send an email through a Gmail account',
|
|
15
|
+
displayName: 'Send Email',
|
|
16
|
+
props: {
|
|
17
|
+
receiver: pieces_framework_1.Property.Array({
|
|
18
|
+
displayName: 'Receiver Email (To)',
|
|
19
|
+
description: undefined,
|
|
20
|
+
required: true,
|
|
21
|
+
}),
|
|
22
|
+
cc: pieces_framework_1.Property.Array({
|
|
23
|
+
displayName: 'CC Email',
|
|
24
|
+
description: undefined,
|
|
25
|
+
required: false,
|
|
26
|
+
}),
|
|
27
|
+
bcc: pieces_framework_1.Property.Array({
|
|
28
|
+
displayName: 'BCC Email',
|
|
29
|
+
description: undefined,
|
|
30
|
+
required: false,
|
|
31
|
+
}),
|
|
32
|
+
subject: pieces_framework_1.Property.ShortText({
|
|
33
|
+
displayName: 'Subject',
|
|
34
|
+
description: undefined,
|
|
35
|
+
required: true,
|
|
36
|
+
}),
|
|
37
|
+
body_type: pieces_framework_1.Property.StaticDropdown({
|
|
38
|
+
displayName: 'Body Type',
|
|
39
|
+
required: true,
|
|
40
|
+
defaultValue: 'plain_text',
|
|
41
|
+
options: {
|
|
42
|
+
disabled: false,
|
|
43
|
+
options: [
|
|
44
|
+
{
|
|
45
|
+
label: 'plain text',
|
|
46
|
+
value: 'plain_text',
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
label: 'html',
|
|
50
|
+
value: 'html',
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
},
|
|
54
|
+
}),
|
|
55
|
+
body: pieces_framework_1.Property.ShortText({
|
|
56
|
+
displayName: 'Body',
|
|
57
|
+
description: 'Body for the email you want to send',
|
|
58
|
+
required: true,
|
|
59
|
+
}),
|
|
60
|
+
reply_to: pieces_framework_1.Property.Array({
|
|
61
|
+
displayName: 'Reply-To Email',
|
|
62
|
+
description: 'Email address to set as the "Reply-To" header',
|
|
63
|
+
required: false,
|
|
64
|
+
}),
|
|
65
|
+
sender_name: pieces_framework_1.Property.ShortText({
|
|
66
|
+
displayName: 'Sender Name',
|
|
67
|
+
required: false,
|
|
68
|
+
}),
|
|
69
|
+
from: pieces_framework_1.Property.ShortText({
|
|
70
|
+
displayName: 'Sender Email',
|
|
71
|
+
description: "The address must be listed in your GMail account's settings",
|
|
72
|
+
required: false,
|
|
73
|
+
}),
|
|
74
|
+
attachments: pieces_framework_1.Property.Array({
|
|
75
|
+
displayName: 'Attachments',
|
|
76
|
+
required: false,
|
|
77
|
+
properties: {
|
|
78
|
+
file: pieces_framework_1.Property.File({
|
|
79
|
+
displayName: 'File',
|
|
80
|
+
description: 'File to attach to the email you want to send.',
|
|
81
|
+
required: true,
|
|
82
|
+
}),
|
|
83
|
+
name: pieces_framework_1.Property.ShortText({
|
|
84
|
+
displayName: 'Attachment Name',
|
|
85
|
+
description: 'In case you want to change the name of the attachment.',
|
|
86
|
+
required: false,
|
|
87
|
+
}),
|
|
88
|
+
},
|
|
89
|
+
}),
|
|
90
|
+
in_reply_to: pieces_framework_1.Property.ShortText({
|
|
91
|
+
displayName: 'In reply to',
|
|
92
|
+
description: 'Reply to this Message-ID',
|
|
93
|
+
required: false,
|
|
94
|
+
}),
|
|
95
|
+
draft: pieces_framework_1.Property.Checkbox({
|
|
96
|
+
displayName: 'Create draft',
|
|
97
|
+
description: 'Create draft without sending the actual email',
|
|
98
|
+
required: true,
|
|
99
|
+
defaultValue: false,
|
|
100
|
+
}),
|
|
101
|
+
},
|
|
102
|
+
run(context) {
|
|
103
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
104
|
+
var _a, _b, _c, _d, _e;
|
|
105
|
+
const authClient = new googleapis_common_1.OAuth2Client();
|
|
106
|
+
authClient.setCredentials(context.auth);
|
|
107
|
+
const gmail = googleapis_1.google.gmail({ version: 'v1', auth: authClient });
|
|
108
|
+
const subjectBase64 = Buffer.from(context.propsValue['subject']).toString('base64');
|
|
109
|
+
const attachments = context.propsValue.attachments;
|
|
110
|
+
const replyTo = (_a = context.propsValue['reply_to']) === null || _a === void 0 ? void 0 : _a.filter((email) => email !== '');
|
|
111
|
+
const receiver = (_b = context.propsValue['receiver']) === null || _b === void 0 ? void 0 : _b.filter((email) => email !== '');
|
|
112
|
+
const cc = (_c = context.propsValue['cc']) === null || _c === void 0 ? void 0 : _c.filter((email) => email !== '');
|
|
113
|
+
const bcc = (_d = context.propsValue['bcc']) === null || _d === void 0 ? void 0 : _d.filter((email) => email !== '');
|
|
114
|
+
const mailOptions = {
|
|
115
|
+
to: receiver.join(', '), // Join all email addresses with a comma
|
|
116
|
+
cc: cc ? cc.join(', ') : undefined,
|
|
117
|
+
bcc: bcc ? bcc.join(', ') : undefined,
|
|
118
|
+
subject: `=?UTF-8?B?${subjectBase64}?=`,
|
|
119
|
+
replyTo: replyTo ? replyTo.join(', ') : '',
|
|
120
|
+
text: context.propsValue.body_type === 'plain_text'
|
|
121
|
+
? context.propsValue['body']
|
|
122
|
+
: undefined,
|
|
123
|
+
html: context.propsValue.body_type === 'html'
|
|
124
|
+
? context.propsValue['body']
|
|
125
|
+
: undefined,
|
|
126
|
+
attachments: [],
|
|
127
|
+
};
|
|
128
|
+
let threadId = undefined;
|
|
129
|
+
if (context.propsValue.in_reply_to) {
|
|
130
|
+
mailOptions.headers = [
|
|
131
|
+
{
|
|
132
|
+
key: 'References',
|
|
133
|
+
value: context.propsValue.in_reply_to,
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
key: 'In-Reply-To',
|
|
137
|
+
value: context.propsValue.in_reply_to,
|
|
138
|
+
},
|
|
139
|
+
];
|
|
140
|
+
const messages = yield gmail.users.messages.list({
|
|
141
|
+
userId: 'me',
|
|
142
|
+
q: `Rfc822msgid:${context.propsValue.in_reply_to}`,
|
|
143
|
+
});
|
|
144
|
+
threadId = (_e = messages.data.messages) === null || _e === void 0 ? void 0 : _e[0].threadId;
|
|
145
|
+
}
|
|
146
|
+
const senderEmail = context.propsValue.from ||
|
|
147
|
+
(yield googleapis_1.google.oauth2({ version: 'v2', auth: authClient }).userinfo.get())
|
|
148
|
+
.data.email;
|
|
149
|
+
if (senderEmail) {
|
|
150
|
+
mailOptions.from = context.propsValue.sender_name
|
|
151
|
+
? `${context.propsValue['sender_name']} <${senderEmail}>`
|
|
152
|
+
: senderEmail;
|
|
153
|
+
}
|
|
154
|
+
if (attachments && attachments.length > 0) {
|
|
155
|
+
const attachmentOption = attachments.map(({ file, name }) => {
|
|
156
|
+
const lookupResult = mime_types_1.default.lookup(file.extension ? file.extension : '');
|
|
157
|
+
return {
|
|
158
|
+
filename: name !== null && name !== void 0 ? name : file.filename,
|
|
159
|
+
content: file === null || file === void 0 ? void 0 : file.base64,
|
|
160
|
+
contentType: lookupResult ? lookupResult : undefined,
|
|
161
|
+
encoding: 'base64',
|
|
162
|
+
};
|
|
163
|
+
});
|
|
164
|
+
mailOptions.attachments = attachmentOption;
|
|
165
|
+
}
|
|
166
|
+
const mail = new mail_composer_1.default(mailOptions).compile();
|
|
167
|
+
mail.keepBcc = true;
|
|
168
|
+
const mailBody = yield mail.build();
|
|
169
|
+
const encodedPayload = Buffer.from(mailBody)
|
|
170
|
+
.toString('base64')
|
|
171
|
+
.replace(/\+/g, '-')
|
|
172
|
+
.replace(/\//g, '_');
|
|
173
|
+
if (context.propsValue.draft) {
|
|
174
|
+
return yield gmail.users.drafts.create({
|
|
175
|
+
userId: 'me',
|
|
176
|
+
requestBody: { message: { threadId, raw: encodedPayload } },
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
return yield gmail.users.messages.send({
|
|
181
|
+
userId: 'me',
|
|
182
|
+
requestBody: {
|
|
183
|
+
threadId,
|
|
184
|
+
raw: encodedPayload,
|
|
185
|
+
},
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
},
|
|
190
|
+
});
|
|
191
|
+
//# sourceMappingURL=send-email-action.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"send-email-action.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/community/gmail/src/lib/actions/send-email-action.ts"],"names":[],"mappings":";;;;AAAA,oEAA+E;AAC/E,oEAA8B;AAC9B,yFAAwD;AAExD,8BAAmC;AACnC,2CAAoC;AACpC,yDAAiD;AAEpC,QAAA,oBAAoB,GAAG,IAAA,+BAAY,EAAC;IAC/C,IAAI,EAAE,aAAS;IACf,IAAI,EAAE,YAAY;IAClB,WAAW,EAAE,uCAAuC;IACpD,WAAW,EAAE,YAAY;IACzB,KAAK,EAAE;QACL,QAAQ,EAAE,2BAAQ,CAAC,KAAK,CAAC;YACvB,WAAW,EAAE,qBAAqB;YAClC,WAAW,EAAE,SAAS;YACtB,QAAQ,EAAE,IAAI;SACf,CAAC;QACF,EAAE,EAAE,2BAAQ,CAAC,KAAK,CAAC;YACjB,WAAW,EAAE,UAAU;YACvB,WAAW,EAAE,SAAS;YACtB,QAAQ,EAAE,KAAK;SAChB,CAAC;QACF,GAAG,EAAE,2BAAQ,CAAC,KAAK,CAAC;YAClB,WAAW,EAAE,WAAW;YACxB,WAAW,EAAE,SAAS;YACtB,QAAQ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, GmailMessageResponse as GmailMessageList } from './models';
|
|
3
|
+
import { Attachment, ParsedMail } from 'mailparser';
|
|
4
|
+
import { FilesService } from '@scopieflows/pieces-framework';
|
|
5
|
+
interface SearchMailProps {
|
|
6
|
+
access_token: string;
|
|
7
|
+
from: string;
|
|
8
|
+
to: string;
|
|
9
|
+
subject?: string;
|
|
10
|
+
label: GmailLabel;
|
|
11
|
+
category: string;
|
|
12
|
+
after?: number;
|
|
13
|
+
before?: number;
|
|
14
|
+
max_results?: number;
|
|
15
|
+
page_token?: string;
|
|
16
|
+
}
|
|
17
|
+
interface GetMailProps {
|
|
18
|
+
access_token: string;
|
|
19
|
+
message_id?: string;
|
|
20
|
+
thread_id?: string;
|
|
21
|
+
format: GmailMessageFormat;
|
|
22
|
+
}
|
|
23
|
+
export declare const GmailRequests: {
|
|
24
|
+
getMail: ({ access_token, format, message_id }: GetMailProps) => Promise<{
|
|
25
|
+
id: string;
|
|
26
|
+
threadId: string;
|
|
27
|
+
labelIds: [string];
|
|
28
|
+
snippet: string;
|
|
29
|
+
historyId: string;
|
|
30
|
+
internalDate: number;
|
|
31
|
+
payload: {
|
|
32
|
+
partId: string;
|
|
33
|
+
mimeType: string;
|
|
34
|
+
filename: string;
|
|
35
|
+
headers: {
|
|
36
|
+
name: string;
|
|
37
|
+
value: string;
|
|
38
|
+
}[];
|
|
39
|
+
body: {
|
|
40
|
+
data: any;
|
|
41
|
+
size: number;
|
|
42
|
+
};
|
|
43
|
+
parts: {
|
|
44
|
+
parts: any[];
|
|
45
|
+
partId: string;
|
|
46
|
+
mimeType: string;
|
|
47
|
+
filename: string;
|
|
48
|
+
headers: {
|
|
49
|
+
name: string;
|
|
50
|
+
value: string;
|
|
51
|
+
}[];
|
|
52
|
+
body: {
|
|
53
|
+
size: number;
|
|
54
|
+
data: string;
|
|
55
|
+
};
|
|
56
|
+
}[];
|
|
57
|
+
};
|
|
58
|
+
sizeEstimate: number;
|
|
59
|
+
raw: string;
|
|
60
|
+
subject: string;
|
|
61
|
+
body_html: string;
|
|
62
|
+
body_plain: string;
|
|
63
|
+
}>;
|
|
64
|
+
getThread: ({ access_token, format, thread_id }: GetMailProps) => Promise<GmailThread>;
|
|
65
|
+
getLabels: (authentication: OAuth2PropertyValue) => Promise<import("@scopieflows/pieces-common").HttpResponse<{
|
|
66
|
+
labels: GmailLabel[];
|
|
67
|
+
}>>;
|
|
68
|
+
searchMail: ({ access_token, max_results, page_token: pageToken, ...mail }: SearchMailProps) => Promise<GmailMessageList | {
|
|
69
|
+
nextPageToken?: string | undefined;
|
|
70
|
+
messages: {
|
|
71
|
+
message: {
|
|
72
|
+
id: string;
|
|
73
|
+
threadId: string;
|
|
74
|
+
labelIds: [string];
|
|
75
|
+
snippet: string;
|
|
76
|
+
historyId: string;
|
|
77
|
+
internalDate: number;
|
|
78
|
+
payload: {
|
|
79
|
+
partId: string;
|
|
80
|
+
mimeType: string;
|
|
81
|
+
filename: string;
|
|
82
|
+
headers: {
|
|
83
|
+
name: string;
|
|
84
|
+
value: string;
|
|
85
|
+
}[];
|
|
86
|
+
body: {
|
|
87
|
+
data: any;
|
|
88
|
+
size: number;
|
|
89
|
+
};
|
|
90
|
+
parts: {
|
|
91
|
+
parts: any[];
|
|
92
|
+
partId: string;
|
|
93
|
+
mimeType: string;
|
|
94
|
+
filename: string;
|
|
95
|
+
headers: {
|
|
96
|
+
name: string;
|
|
97
|
+
value: string;
|
|
98
|
+
}[];
|
|
99
|
+
body: {
|
|
100
|
+
size: number;
|
|
101
|
+
data: string;
|
|
102
|
+
};
|
|
103
|
+
}[];
|
|
104
|
+
};
|
|
105
|
+
sizeEstimate: number;
|
|
106
|
+
raw: string;
|
|
107
|
+
subject: string;
|
|
108
|
+
body_html: string;
|
|
109
|
+
body_plain: string;
|
|
110
|
+
};
|
|
111
|
+
thread: GmailThread;
|
|
112
|
+
}[];
|
|
113
|
+
resultSizeEstimate: number;
|
|
114
|
+
}>;
|
|
115
|
+
getRecentMessages: (authentication: OAuth2PropertyValue, maxResults?: number) => Promise<import("@scopieflows/pieces-common").HttpResponse<GmailMessageList>>;
|
|
116
|
+
getRecentThreads: (authentication: OAuth2PropertyValue, maxResults?: number) => Promise<import("@scopieflows/pieces-common").HttpResponse<{
|
|
117
|
+
threads: {
|
|
118
|
+
id: string;
|
|
119
|
+
snippet?: string;
|
|
120
|
+
}[];
|
|
121
|
+
}>>;
|
|
122
|
+
};
|
|
123
|
+
export declare function parseStream(stream: any): Promise<ParsedMail>;
|
|
124
|
+
export declare function convertAttachment(attachments: Attachment[], files: FilesService): Promise<{
|
|
125
|
+
fileName: string;
|
|
126
|
+
mimeType: string;
|
|
127
|
+
size: number;
|
|
128
|
+
data: string;
|
|
129
|
+
}[]>;
|
|
130
|
+
export declare function getFirstFiveOrAll(array: unknown[]): unknown[];
|
|
131
|
+
export {};
|