@activepieces/piece-gmail 0.10.2 → 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.
Files changed (32) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +17 -1
  3. package/src/index.js.map +1 -1
  4. package/src/lib/actions/create-draft-reply-action.d.ts +10 -0
  5. package/src/lib/actions/create-draft-reply-action.js +262 -0
  6. package/src/lib/actions/create-draft-reply-action.js.map +1 -0
  7. package/src/lib/actions/get-mail-action.d.ts +1 -3
  8. package/src/lib/actions/get-mail-action.js +20 -27
  9. package/src/lib/actions/get-mail-action.js.map +1 -1
  10. package/src/lib/actions/reply-to-email-action.d.ts +9 -0
  11. package/src/lib/actions/reply-to-email-action.js +195 -0
  12. package/src/lib/actions/reply-to-email-action.js.map +1 -0
  13. package/src/lib/actions/search-email-action.d.ts +9 -2
  14. package/src/lib/actions/search-email-action.js +162 -14
  15. package/src/lib/actions/search-email-action.js.map +1 -1
  16. package/src/lib/common/data.d.ts +8 -0
  17. package/src/lib/common/data.js +37 -0
  18. package/src/lib/common/data.js.map +1 -1
  19. package/src/lib/common/props.d.ts +2 -0
  20. package/src/lib/common/props.js +153 -0
  21. package/src/lib/common/props.js.map +1 -1
  22. package/src/lib/triggers/new-attachment.d.ts +171 -0
  23. package/src/lib/triggers/new-attachment.js +128 -0
  24. package/src/lib/triggers/new-attachment.js.map +1 -0
  25. package/src/lib/triggers/new-conversation.d.ts +46 -0
  26. package/src/lib/triggers/new-conversation.js +310 -0
  27. package/src/lib/triggers/new-conversation.js.map +1 -0
  28. package/src/lib/triggers/new-email.js +1 -9
  29. package/src/lib/triggers/new-email.js.map +1 -1
  30. package/src/lib/triggers/new-label.d.ts +2 -0
  31. package/src/lib/triggers/new-label.js +79 -0
  32. package/src/lib/triggers/new-label.js.map +1 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@activepieces/piece-gmail",
3
- "version": "0.10.2",
3
+ "version": "0.11.0",
4
4
  "dependencies": {
5
5
  "@sinclair/typebox": "0.34.11",
6
6
  "ai": "^6.0.0",
package/src/index.js CHANGED
@@ -6,9 +6,15 @@ const pieces_common_1 = require("@activepieces/pieces-common");
6
6
  const pieces_framework_1 = require("@activepieces/pieces-framework");
7
7
  const shared_1 = require("@activepieces/shared");
8
8
  const send_email_action_1 = require("./lib/actions/send-email-action");
9
+ const reply_to_email_action_1 = require("./lib/actions/reply-to-email-action");
10
+ const create_draft_reply_action_1 = require("./lib/actions/create-draft-reply-action");
9
11
  const new_email_1 = require("./lib/triggers/new-email");
10
12
  const new_labeled_email_1 = require("./lib/triggers/new-labeled-email");
11
13
  const request_approval_in_email_1 = require("./lib/actions/request-approval-in-email");
14
+ const new_attachment_1 = require("./lib/triggers/new-attachment");
15
+ const new_label_1 = require("./lib/triggers/new-label");
16
+ const search_email_action_1 = require("./lib/actions/search-email-action");
17
+ const get_mail_action_1 = require("./lib/actions/get-mail-action");
12
18
  exports.gmailAuth = pieces_framework_1.PieceAuth.OAuth2({
13
19
  description: '',
14
20
  authUrl: 'https://accounts.google.com/o/oauth2/auth',
@@ -31,6 +37,10 @@ exports.gmail = (0, pieces_framework_1.createPiece)({
31
37
  actions: [
32
38
  send_email_action_1.gmailSendEmailAction,
33
39
  request_approval_in_email_1.requestApprovalInEmail,
40
+ reply_to_email_action_1.gmailReplyToEmailAction,
41
+ create_draft_reply_action_1.gmailCreateDraftReplyAction,
42
+ get_mail_action_1.gmailGetEmailAction,
43
+ search_email_action_1.gmailSearchMailAction,
34
44
  (0, pieces_common_1.createCustomApiCallAction)({
35
45
  baseUrl: () => 'https://gmail.googleapis.com/gmail/v1',
36
46
  auth: exports.gmailAuth,
@@ -55,8 +65,14 @@ exports.gmail = (0, pieces_framework_1.createPiece)({
55
65
  'abuaboud',
56
66
  'AdamSelene',
57
67
  'sanket-a11y',
68
+ 'onyedikachi-david',
69
+ ],
70
+ triggers: [
71
+ new_email_1.gmailNewEmailTrigger,
72
+ new_labeled_email_1.gmailNewLabeledEmailTrigger,
73
+ new_attachment_1.gmailNewAttachmentTrigger,
74
+ new_label_1.gmailNewLabelTrigger,
58
75
  ],
59
- triggers: [new_email_1.gmailNewEmailTrigger, new_labeled_email_1.gmailNewLabeledEmailTrigger],
60
76
  auth: exports.gmailAuth,
61
77
  });
62
78
  //# sourceMappingURL=index.js.map
package/src/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/pieces/community/gmail/src/index.ts"],"names":[],"mappings":";;;;AAAA,+DAAwE;AACxE,qEAIwC;AACxC,iDAAqD;AACrD,uEAAuE;AACvE,wDAAgE;AAChE,wEAA+E;AAC/E,uFAAiF;AAEpE,QAAA,SAAS,GAAG,4BAAS,CAAC,MAAM,CAAC;IACxC,WAAW,EAAE,EAAE;IACf,OAAO,EAAE,2CAA2C;IACpD,QAAQ,EAAE,qCAAqC;IAC/C,QAAQ,EAAE,IAAI;IACd,KAAK,EAAE;QACL,4CAA4C;QAC5C,OAAO;QACP,gDAAgD;QAChD,+CAA+C;KAChD;CACF,CAAC,CAAC;AAEU,QAAA,KAAK,GAAG,IAAA,8BAAW,EAAC;IAC/B,uBAAuB,EAAE,QAAQ;IACjC,OAAO,EAAE,+CAA+C;IACxD,UAAU,EAAE;QACV,sBAAa,CAAC,aAAa;QAC3B,sBAAa,CAAC,qBAAqB;KACpC;IACD,OAAO,EAAE;QACP,wCAAoB;QACpB,kDAAsB;QACtB,IAAA,yCAAyB,EAAC;YACxB,OAAO,EAAE,GAAG,EAAE,CAAC,uCAAuC;YACtD,IAAI,EAAE,iBAAS;YACf,WAAW,EAAE,CAAO,IAAI,EAAE,EAAE;gBAAC,OAAA,CAAC;oBAC5B,aAAa,EAAE,UAAW,IAA4B,CAAC,YAAY,EAAE;iBACtE,CAAC,CAAA;cAAA;SACH,CAAC;KACH;IACD,WAAW,EAAE,OAAO;IACpB,WAAW,EAAE,yBAAyB;IAEtC,OAAO,EAAE;QACP,UAAU;QACV,oBAAoB;QACpB,WAAW;QACX,YAAY;QACZ,YAAY;QACZ,WAAW;QACX,sBAAsB;QACtB,eAAe;QACf,UAAU;QACV,YAAY;QACZ,aAAa;KACd;IACD,QAAQ,EAAE,CAAC,gCAAoB,EAAE,+CAA2B,CAAC;IAC7D,IAAI,EAAE,iBAAS;CAChB,CAAC,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/pieces/community/gmail/src/index.ts"],"names":[],"mappings":";;;;AAAA,+DAAwE;AACxE,qEAIwC;AACxC,iDAAqD;AACrD,uEAAuE;AACvE,+EAA8E;AAC9E,uFAAsF;AACtF,wDAAgE;AAChE,wEAA+E;AAC/E,uFAAiF;AACjF,kEAA0E;AAC1E,wDAAgE;AAChE,2EAA0E;AAC1E,mEAAoE;AAEvD,QAAA,SAAS,GAAG,4BAAS,CAAC,MAAM,CAAC;IACxC,WAAW,EAAE,EAAE;IACf,OAAO,EAAE,2CAA2C;IACpD,QAAQ,EAAE,qCAAqC;IAC/C,QAAQ,EAAE,IAAI;IACd,KAAK,EAAE;QACL,4CAA4C;QAC5C,OAAO;QACP,gDAAgD;QAChD,+CAA+C;KAChD;CACF,CAAC,CAAC;AAEU,QAAA,KAAK,GAAG,IAAA,8BAAW,EAAC;IAC/B,uBAAuB,EAAE,QAAQ;IACjC,OAAO,EAAE,+CAA+C;IACxD,UAAU,EAAE;QACV,sBAAa,CAAC,aAAa;QAC3B,sBAAa,CAAC,qBAAqB;KACpC;IACD,OAAO,EAAE;QACP,wCAAoB;QACpB,kDAAsB;QACtB,+CAAuB;QACvB,uDAA2B;QAC3B,qCAAmB;QACnB,2CAAqB;QACrB,IAAA,yCAAyB,EAAC;YACxB,OAAO,EAAE,GAAG,EAAE,CAAC,uCAAuC;YACtD,IAAI,EAAE,iBAAS;YACf,WAAW,EAAE,CAAO,IAAI,EAAE,EAAE;gBAAC,OAAA,CAAC;oBAC5B,aAAa,EAAE,UAAW,IAA4B,CAAC,YAAY,EAAE;iBACtE,CAAC,CAAA;cAAA;SACH,CAAC;KACH;IACD,WAAW,EAAE,OAAO;IACpB,WAAW,EAAE,yBAAyB;IAEtC,OAAO,EAAE;QACP,UAAU;QACV,oBAAoB;QACpB,WAAW;QACX,YAAY;QACZ,YAAY;QACZ,WAAW;QACX,sBAAsB;QACtB,eAAe;QACf,UAAU;QACV,YAAY;QACZ,aAAa;QACb,mBAAmB;KACpB;IACD,QAAQ,EAAE;QACR,gCAAoB;QACpB,+CAA2B;QAC3B,0CAAyB;QACzB,gCAAoB;KACrB;IACD,IAAI,EAAE,iBAAS;CAChB,CAAC,CAAC"}
@@ -0,0 +1,10 @@
1
+ export declare const gmailCreateDraftReplyAction: import("@activepieces/pieces-framework").IAction<import("@activepieces/pieces-framework").OAuth2Property<import("@activepieces/pieces-framework").OAuth2Props>, {
2
+ message_id: import("@activepieces/pieces-framework").DropdownProperty<string, true, import("@activepieces/pieces-framework").OAuth2Property<import("@activepieces/pieces-framework").OAuth2Props>>;
3
+ reply_type: import("@activepieces/pieces-framework").StaticDropdownProperty<string, true>;
4
+ body_type: import("@activepieces/pieces-framework").StaticDropdownProperty<string, true>;
5
+ body: import("@activepieces/pieces-framework").LongTextProperty<false>;
6
+ include_original_message: import("@activepieces/pieces-framework").CheckboxProperty<true>;
7
+ sender_name: import("@activepieces/pieces-framework").ShortTextProperty<false>;
8
+ attachment: import("@activepieces/pieces-framework").FileProperty<false>;
9
+ attachment_name: import("@activepieces/pieces-framework").ShortTextProperty<false>;
10
+ }>;
@@ -0,0 +1,262 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.gmailCreateDraftReplyAction = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const pieces_framework_1 = require("@activepieces/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
+ const props_1 = require("../common/props");
12
+ exports.gmailCreateDraftReplyAction = (0, pieces_framework_1.createAction)({
13
+ auth: __1.gmailAuth,
14
+ name: 'create_draft_reply',
15
+ description: 'Creates a draft reply to an existing email.',
16
+ displayName: 'Create Draft Reply',
17
+ props: {
18
+ message_id: props_1.GmailProps.message,
19
+ reply_type: pieces_framework_1.Property.StaticDropdown({
20
+ displayName: 'Reply Type',
21
+ description: 'Choose whether to reply to sender only or to all recipients',
22
+ required: true,
23
+ defaultValue: 'reply',
24
+ options: {
25
+ disabled: false,
26
+ options: [
27
+ {
28
+ label: 'Reply (to sender only)',
29
+ value: 'reply',
30
+ },
31
+ {
32
+ label: 'Reply All (to all recipients)',
33
+ value: 'reply_all',
34
+ },
35
+ ],
36
+ },
37
+ }),
38
+ body_type: pieces_framework_1.Property.StaticDropdown({
39
+ displayName: 'Body Type',
40
+ required: true,
41
+ defaultValue: 'plain_text',
42
+ options: {
43
+ disabled: false,
44
+ options: [
45
+ {
46
+ label: 'Plain text',
47
+ value: 'plain_text',
48
+ },
49
+ {
50
+ label: 'HTML',
51
+ value: 'html',
52
+ },
53
+ ],
54
+ },
55
+ }),
56
+ body: pieces_framework_1.Property.LongText({
57
+ displayName: 'Draft Reply Body',
58
+ description: 'Your draft reply message content',
59
+ required: false,
60
+ }),
61
+ include_original_message: pieces_framework_1.Property.Checkbox({
62
+ displayName: 'Include Original Message',
63
+ description: 'Include the original message content in the draft reply',
64
+ required: true,
65
+ defaultValue: true,
66
+ }),
67
+ sender_name: pieces_framework_1.Property.ShortText({
68
+ displayName: 'Sender Name',
69
+ description: 'Optional sender name to display',
70
+ required: false,
71
+ }),
72
+ attachment: pieces_framework_1.Property.File({
73
+ displayName: 'Attachment',
74
+ description: 'Optional file to attach to your draft reply',
75
+ required: false,
76
+ }),
77
+ attachment_name: pieces_framework_1.Property.ShortText({
78
+ displayName: 'Attachment Name',
79
+ description: 'Custom name for the attachment',
80
+ required: false,
81
+ }),
82
+ },
83
+ run(context) {
84
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
85
+ var _a;
86
+ const authClient = new googleapis_common_1.OAuth2Client();
87
+ authClient.setCredentials(context.auth);
88
+ const gmail = googleapis_1.google.gmail({ version: 'v1', auth: authClient });
89
+ const originalMessage = yield gmail.users.messages.get({
90
+ userId: 'me',
91
+ id: context.propsValue.message_id,
92
+ format: 'full',
93
+ });
94
+ if (!originalMessage.data || !originalMessage.data.payload) {
95
+ throw new Error('Could not fetch original message details');
96
+ }
97
+ const headers = originalMessage.data.payload.headers || [];
98
+ const headerMap = headers.reduce((acc, header) => {
99
+ if (header.name && header.value) {
100
+ acc[header.name.toLowerCase()] = header.value;
101
+ }
102
+ return acc;
103
+ }, {});
104
+ const originalSubject = headerMap['subject'] || '';
105
+ const originalFrom = headerMap['from'] || '';
106
+ const originalTo = headerMap['to'] || '';
107
+ const originalCc = headerMap['cc'] || '';
108
+ const originalReplyTo = headerMap['reply-to'] || '';
109
+ const originalMessageId = headerMap['message-id'] || '';
110
+ const originalReferences = headerMap['references'] || '';
111
+ const originalDate = headerMap['date'] || '';
112
+ let originalMessageContent = '';
113
+ if (context.propsValue.include_original_message) {
114
+ try {
115
+ const { parseStream } = yield Promise.resolve().then(() => tslib_1.__importStar(require('../common/data')));
116
+ const originalMessageFull = yield gmail.users.messages.get({
117
+ userId: 'me',
118
+ id: context.propsValue.message_id,
119
+ format: 'raw',
120
+ });
121
+ if (originalMessageFull.data.raw) {
122
+ const rawMessage = Buffer.from(originalMessageFull.data.raw, 'base64').toString('utf-8');
123
+ const parsedMessage = yield parseStream(rawMessage);
124
+ let messageText = parsedMessage.text || '';
125
+ if (!messageText && parsedMessage.html) {
126
+ messageText = parsedMessage.html
127
+ .replace(/<[^>]*>/g, '')
128
+ .replace(/&nbsp;/g, ' ')
129
+ .replace(/&amp;/g, '&')
130
+ .replace(/&lt;/g, '<')
131
+ .replace(/&gt;/g, '>');
132
+ }
133
+ if (messageText) {
134
+ const quotedLines = messageText
135
+ .split('\n')
136
+ .map((line) => `> ${line.trim()}`);
137
+ const senderInfo = `On ${originalDate}, ${originalFrom} wrote:`;
138
+ originalMessageContent = `${senderInfo}\n${quotedLines.join('\n')}`;
139
+ }
140
+ }
141
+ }
142
+ catch (error) {
143
+ console.warn('Could not extract original message content for quoting:', error);
144
+ originalMessageContent = `On ${originalDate}, ${originalFrom} wrote:\n> [Original message content could not be parsed]`;
145
+ }
146
+ }
147
+ const toRecipients = [];
148
+ const ccRecipients = [];
149
+ if (context.propsValue.reply_type === 'reply_all') {
150
+ const senderEmail = originalReplyTo || originalFrom;
151
+ if (senderEmail) {
152
+ toRecipients.push(senderEmail);
153
+ }
154
+ const currentUserEmail = (yield googleapis_1.google.oauth2({ version: 'v2', auth: authClient }).userinfo.get()).data.email;
155
+ if (originalTo) {
156
+ const toEmails = originalTo.split(',').map((email) => email.trim());
157
+ toRecipients.push(...toEmails.filter((email) => !email.includes(currentUserEmail || '')));
158
+ }
159
+ if (originalCc) {
160
+ const ccEmails = originalCc.split(',').map((email) => email.trim());
161
+ ccRecipients.push(...ccEmails.filter((email) => !email.includes(currentUserEmail || '')));
162
+ }
163
+ }
164
+ else {
165
+ const senderEmail = originalReplyTo || originalFrom;
166
+ if (senderEmail) {
167
+ toRecipients.push(senderEmail);
168
+ }
169
+ }
170
+ let replySubject = originalSubject;
171
+ if (!replySubject.toLowerCase().startsWith('re:')) {
172
+ replySubject = `Re: ${replySubject}`;
173
+ }
174
+ let referencesHeader = originalMessageId;
175
+ if (originalReferences) {
176
+ referencesHeader = `${originalReferences} ${originalMessageId}`;
177
+ }
178
+ const senderEmail = (yield googleapis_1.google.oauth2({ version: 'v2', auth: authClient }).userinfo.get()).data.email;
179
+ let draftBody = context.propsValue.body || '';
180
+ if (context.propsValue.include_original_message && originalMessageContent) {
181
+ const separator = context.propsValue.body_type === 'html'
182
+ ? '<br><br>--- Original Message ---<br>'
183
+ : '\n\n--- Original Message ---\n';
184
+ const quotedContent = context.propsValue.body_type === 'html'
185
+ ? originalMessageContent.replace(/\n/g, '<br>')
186
+ : originalMessageContent;
187
+ draftBody = draftBody
188
+ ? `${draftBody}${separator}${quotedContent}`
189
+ : quotedContent;
190
+ }
191
+ const subjectBase64 = Buffer.from(replySubject).toString('base64');
192
+ const mailOptions = {
193
+ to: toRecipients.join(', '),
194
+ cc: ccRecipients.length > 0 ? ccRecipients.join(', ') : undefined,
195
+ subject: `=?UTF-8?B?${subjectBase64}?=`,
196
+ text: context.propsValue.body_type === 'plain_text' ? draftBody : undefined,
197
+ html: context.propsValue.body_type === 'html' ? draftBody : undefined,
198
+ attachments: [],
199
+ headers: [
200
+ {
201
+ key: 'In-Reply-To',
202
+ value: originalMessageId,
203
+ },
204
+ {
205
+ key: 'References',
206
+ value: referencesHeader,
207
+ },
208
+ ],
209
+ };
210
+ if (senderEmail) {
211
+ mailOptions.from = context.propsValue.sender_name
212
+ ? `${context.propsValue.sender_name} <${senderEmail}>`
213
+ : senderEmail;
214
+ }
215
+ if (context.propsValue.attachment) {
216
+ const lookupResult = mime_types_1.default.lookup(context.propsValue.attachment.extension || '');
217
+ const attachmentOption = [
218
+ {
219
+ filename: (_a = context.propsValue.attachment_name) !== null && _a !== void 0 ? _a : context.propsValue.attachment.filename,
220
+ content: context.propsValue.attachment.base64,
221
+ contentType: lookupResult || undefined,
222
+ encoding: 'base64',
223
+ },
224
+ ];
225
+ mailOptions.attachments = attachmentOption;
226
+ }
227
+ const mail = new mail_composer_1.default(mailOptions).compile();
228
+ mail.keepBcc = true;
229
+ const mailBody = yield mail.build();
230
+ const encodedPayload = Buffer.from(mailBody)
231
+ .toString('base64')
232
+ .replace(/\+/g, '-')
233
+ .replace(/\//g, '_');
234
+ const draft = yield gmail.users.drafts.create({
235
+ userId: 'me',
236
+ requestBody: {
237
+ message: {
238
+ threadId: originalMessage.data.threadId || undefined,
239
+ raw: encodedPayload,
240
+ },
241
+ },
242
+ });
243
+ return Object.assign(Object.assign({}, draft.data), { originalMessage: {
244
+ id: context.propsValue.message_id,
245
+ subject: originalSubject,
246
+ from: originalFrom,
247
+ to: originalTo,
248
+ date: originalDate,
249
+ threadId: originalMessage.data.threadId,
250
+ }, draftDetails: {
251
+ replyType: context.propsValue.reply_type,
252
+ recipients: {
253
+ to: toRecipients,
254
+ cc: ccRecipients,
255
+ },
256
+ subject: replySubject,
257
+ includeOriginal: context.propsValue.include_original_message,
258
+ } });
259
+ });
260
+ },
261
+ });
262
+ //# sourceMappingURL=create-draft-reply-action.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-draft-reply-action.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/community/gmail/src/lib/actions/create-draft-reply-action.ts"],"names":[],"mappings":";;;;AAAA,qEAAwE;AACxE,oEAA8B;AAC9B,yFAAwD;AAExD,8BAAmC;AACnC,2CAAoC;AACpC,yDAAiD;AACjD,2CAA6C;AAEhC,QAAA,2BAA2B,GAAG,IAAA,+BAAY,EAAC;IACtD,IAAI,EAAE,aAAS;IACf,IAAI,EAAE,oBAAoB;IAC1B,WAAW,EAAE,6CAA6C;IAC1D,WAAW,EAAE,oBAAoB;IACjC,KAAK,EAAE;QACL,UAAU,EAAE,kBAAU,CAAC,OAAO;QAC9B,UAAU,EAAE,2BAAQ,CAAC,cAAc,CAAC;YAClC,WAAW,EAAE,YAAY;YACzB,WAAW,EACT,6DAA6D;YAC/D,QAAQ,EAAE,IAAI;YACd,YAAY,EAAE,OAAO;YACrB,OAAO,EAAE;gBACP,QAAQ,EAAE,KAAK;gBACf,OAAO,EAAE;oBACP;wBACE,KAAK,EAAE,wBAAwB;wBAC/B,KAAK,EAAE,OAAO;qBACf;oBACD;wBACE,KAAK,EAAE,+BAA+B;wBACtC,KAAK,EAAE,WAAW;qBACnB;iBACF;aACF;SACF,CAAC;QACF,SAAS,EAAE,2BAAQ,CAAC,cAAc,CAAC;YACjC,WAAW,EAAE,WAAW;YACxB,QA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BACF;aACF,CAAC,CAAC;YAEH,uCACK,KAAK,CAAC,IAAI,KACb,eAAe,EAAE;oBACf,EAAE,EAAE,OAAO,CAAC,UAAU,CAAC,UAAU;oBACjC,OAAO,EAAE,eAAe;oBACxB,IAAI,EAAE,YAAY;oBAClB,EAAE,EAAE,UAAU;oBACd,IAAI,EAAE,YAAY;oBAClB,QAAQ,EAAE,eAAe,CAAC,IAAI,CAAC,QAAQ;iBACxC,EACD,YAAY,EAAE;oBACZ,SAAS,EAAE,OAAO,CAAC,UAAU,CAAC,UAAU;oBACxC,UAAU,EAAE;wBACV,EAAE,EAAE,YAAY;wBAChB,EAAE,EAAE,YAAY;qBACjB;oBACD,OAAO,EAAE,YAAY;oBACrB,eAAe,EAAE,OAAO,CAAC,UAAU,CAAC,wBAAwB;iBAC7D,IACD;QACJ,CAAC;KAAA;CACF,CAAC,CAAC"}
@@ -1,5 +1,3 @@
1
- import { GmailMessageFormat } from '../common/models';
2
- export declare const gmailGetEmail: import("@activepieces/pieces-framework").IAction<import("@activepieces/pieces-framework").OAuth2Property<import("@activepieces/pieces-framework").OAuth2Props>, {
1
+ export declare const gmailGetEmailAction: import("@activepieces/pieces-framework").IAction<import("@activepieces/pieces-framework").OAuth2Property<import("@activepieces/pieces-framework").OAuth2Props>, {
3
2
  message_id: import("@activepieces/pieces-framework").ShortTextProperty<true>;
4
- format: import("@activepieces/pieces-framework").StaticDropdownProperty<GmailMessageFormat, false> | import("@activepieces/pieces-framework").StaticDropdownProperty<GmailMessageFormat, true>;
5
3
  }>;
@@ -1,44 +1,37 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.gmailGetEmail = void 0;
3
+ exports.gmailGetEmailAction = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const pieces_framework_1 = require("@activepieces/pieces-framework");
6
- const data_1 = require("../common/data");
7
- const models_1 = require("../common/models");
8
6
  const __1 = require("../../");
9
- exports.gmailGetEmail = (0, pieces_framework_1.createAction)({
7
+ const googleapis_1 = require("googleapis");
8
+ const googleapis_common_1 = require("googleapis-common");
9
+ const data_1 = require("../common/data");
10
+ exports.gmailGetEmailAction = (0, pieces_framework_1.createAction)({
10
11
  auth: __1.gmailAuth,
11
12
  name: 'gmail_get_mail',
12
- description: 'Get an email from your Gmail account via Id',
13
+ description: 'Get an email via Id.',
13
14
  displayName: 'Get Email',
14
15
  props: {
15
16
  message_id: pieces_framework_1.Property.ShortText({
16
17
  displayName: 'Message ID',
17
- description: 'The messageId of the mail to read',
18
+ description: 'The messageId of the mail to read.',
18
19
  required: true,
19
20
  }),
20
- format: pieces_framework_1.Property.StaticDropdown({
21
- displayName: 'Format',
22
- description: 'Format of the mail',
23
- required: false,
24
- defaultValue: models_1.GmailMessageFormat.FULL,
25
- options: {
26
- disabled: false,
27
- options: [
28
- { value: models_1.GmailMessageFormat.MINIMAL, label: 'Minimal' },
29
- { value: models_1.GmailMessageFormat.FULL, label: 'Full' },
30
- { value: models_1.GmailMessageFormat.RAW, label: 'Raw' },
31
- { value: models_1.GmailMessageFormat.METADATA, label: 'Metadata' },
32
- ],
33
- },
34
- }),
35
21
  },
36
- run: (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ auth, propsValue: { format, message_id } }) {
37
- return yield data_1.GmailRequests.getMail({
38
- access_token: auth.access_token,
39
- message_id,
40
- format: format !== null && format !== void 0 ? format : models_1.GmailMessageFormat.FULL,
22
+ run(context) {
23
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
24
+ const authClient = new googleapis_common_1.OAuth2Client();
25
+ authClient.setCredentials(context.auth);
26
+ const gmail = googleapis_1.google.gmail({ version: 'v1', auth: authClient });
27
+ const rawMailResponse = yield gmail.users.messages.get({
28
+ userId: 'me',
29
+ id: context.propsValue.message_id,
30
+ format: 'raw',
31
+ });
32
+ const parsedMailResponse = yield (0, data_1.parseStream)(Buffer.from(rawMailResponse.data.raw, 'base64').toString('utf-8'));
33
+ return Object.assign(Object.assign({ id: context.propsValue.message_id }, parsedMailResponse), { attachments: yield (0, data_1.convertAttachment)(parsedMailResponse.attachments, context.files) });
41
34
  });
42
- }),
35
+ },
43
36
  });
44
37
  //# sourceMappingURL=get-mail-action.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"get-mail-action.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/community/gmail/src/lib/actions/get-mail-action.ts"],"names":[],"mappings":";;;;AAAA,qEAAwE;AACxE,yCAA+C;AAC/C,6CAAsD;AACtD,8BAAmC;AAEtB,QAAA,aAAa,GAAG,IAAA,+BAAY,EAAC;IACxC,IAAI,EAAE,aAAS;IACf,IAAI,EAAE,gBAAgB;IACtB,WAAW,EAAE,6CAA6C;IAC1D,WAAW,EAAE,WAAW;IACxB,KAAK,EAAE;QACL,UAAU,EAAE,2BAAQ,CAAC,SAAS,CAAC;YAC7B,WAAW,EAAE,YAAY;YACzB,WAAW,EAAE,mCAAmC;YAChD,QAAQ,EAAE,IAAI;SACf,CAAC;QACF,MAAM,EAAE,2BAAQ,CAAC,cAAc,CAAqB;YAClD,WAAW,EAAE,QAAQ;YACrB,WAAW,EAAE,oBAAoB;YACjC,QAAQ,EAAE,KAAK;YACf,YAAY,EAAE,2BAAkB,CAAC,IAAI;YACrC,OAAO,EAAE;gBACP,QAAQ,EAAE,KAAK;gBACf,OAAO,EAAE;oBACP,EAAE,KAAK,EAAE,2BAAkB,CAAC,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE;oBACvD,EAAE,KAAK,EAAE,2BAAkB,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE;oBACjD,EAAE,KAAK,EAAE,2BAAkB,CAAC,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE;oBAC/C,EAAE,KAAK,EAAE,2BAAkB,CAAC,QAAQ,EAAE,KAAK,EAAE,UAAU,EAAE;iBAC1D;aACF;SACF,CAAC;KACH;IACD,GAAG,EAAE,KAAqD,EAAE,oDAAhD,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,EAAE;QACtD,OAAA,MAAM,oBAAa,CAAC,OAAO,CAAC;YAC1B,YAAY,EAAE,IAAI,CAAC,YAAY;YAC/B,UAAU;YACV,MAAM,EAAE,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,2BAAkB,CAAC,IAAI;SAC1C,CAAC,CAAA;MAAA;CACL,CAAC,CAAC"}
1
+ {"version":3,"file":"get-mail-action.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/community/gmail/src/lib/actions/get-mail-action.ts"],"names":[],"mappings":";;;;AAAA,qEAAwE;AACxE,8BAAmC;AACnC,2CAAoC;AACpC,yDAAiD;AACjD,yCAAgE;AAEnD,QAAA,mBAAmB,GAAG,IAAA,+BAAY,EAAC;IAC9C,IAAI,EAAE,aAAS;IACf,IAAI,EAAE,gBAAgB;IACtB,WAAW,EAAE,sBAAsB;IACnC,WAAW,EAAE,WAAW;IACxB,KAAK,EAAE;QACL,UAAU,EAAE,2BAAQ,CAAC,SAAS,CAAC;YAC7B,WAAW,EAAE,YAAY;YACzB,WAAW,EAAE,oCAAoC;YACjD,QAAQ,EAAE,IAAI;SACf,CAAC;KACH;IACK,GAAG,CAAC,OAAO;;YACf,MAAM,UAAU,GAAG,IAAI,gCAAY,EAAE,CAAC;YACtC,UAAU,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YAExC,MAAM,KAAK,GAAG,mBAAM,CAAC,KAAK,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC;YAEhE,MAAM,eAAe,GAAG,MAAM,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC;gBACrD,MAAM,EAAE,IAAI;gBACZ,EAAE,EAAE,OAAO,CAAC,UAAU,CAAC,UAAW;gBAClC,MAAM,EAAE,KAAK;aACd,CAAC,CAAC;YAEH,MAAM,kBAAkB,GAAG,MAAM,IAAA,kBAAW,EAC1C,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,GAAa,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAChE,OAAO,CACR,CACF,CAAC;YAEF,qCACE,EAAE,EAAE,OAAO,CAAC,UAAU,CAAC,UAAU,IAC9B,kBAAkB,KACrB,WAAW,EAAE,MAAM,IAAA,wBAAiB,EAClC,kBAAkB,CAAC,WAAW,EAC9B,OAAO,CAAC,KAAK,CACd,IACD;QACJ,CAAC;KAAA;CACF,CAAC,CAAC"}
@@ -0,0 +1,9 @@
1
+ export declare const gmailReplyToEmailAction: import("@activepieces/pieces-framework").IAction<import("@activepieces/pieces-framework").OAuth2Property<import("@activepieces/pieces-framework").OAuth2Props>, {
2
+ message_id: import("@activepieces/pieces-framework").DropdownProperty<string, true, import("@activepieces/pieces-framework").OAuth2Property<import("@activepieces/pieces-framework").OAuth2Props>>;
3
+ reply_type: import("@activepieces/pieces-framework").StaticDropdownProperty<string, true>;
4
+ body_type: import("@activepieces/pieces-framework").StaticDropdownProperty<string, true>;
5
+ body: import("@activepieces/pieces-framework").LongTextProperty<true>;
6
+ sender_name: import("@activepieces/pieces-framework").ShortTextProperty<false>;
7
+ attachment: import("@activepieces/pieces-framework").FileProperty<false>;
8
+ attachment_name: import("@activepieces/pieces-framework").ShortTextProperty<false>;
9
+ }>;
@@ -0,0 +1,195 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.gmailReplyToEmailAction = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const pieces_framework_1 = require("@activepieces/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
+ const props_1 = require("../common/props");
12
+ exports.gmailReplyToEmailAction = (0, pieces_framework_1.createAction)({
13
+ auth: __1.gmailAuth,
14
+ name: 'reply_to_email',
15
+ displayName: 'Reply to Email',
16
+ description: 'Reply to an existing email.',
17
+ props: {
18
+ message_id: props_1.GmailProps.message,
19
+ reply_type: pieces_framework_1.Property.StaticDropdown({
20
+ displayName: 'Reply Type',
21
+ description: 'Choose whether to reply to sender only or to all recipients',
22
+ required: true,
23
+ defaultValue: 'reply',
24
+ options: {
25
+ disabled: false,
26
+ options: [
27
+ {
28
+ label: 'Reply (to sender only)',
29
+ value: 'reply',
30
+ },
31
+ {
32
+ label: 'Reply All (to all recipients)',
33
+ value: 'reply_all',
34
+ },
35
+ ],
36
+ },
37
+ }),
38
+ body_type: pieces_framework_1.Property.StaticDropdown({
39
+ displayName: 'Body Type',
40
+ required: true,
41
+ defaultValue: 'plain_text',
42
+ options: {
43
+ disabled: false,
44
+ options: [
45
+ {
46
+ label: 'Plain text',
47
+ value: 'plain_text',
48
+ },
49
+ {
50
+ label: 'HTML',
51
+ value: 'html',
52
+ },
53
+ ],
54
+ },
55
+ }),
56
+ body: pieces_framework_1.Property.LongText({
57
+ displayName: 'Reply Body',
58
+ description: 'Your reply message content',
59
+ required: true,
60
+ }),
61
+ sender_name: pieces_framework_1.Property.ShortText({
62
+ displayName: 'Sender Name',
63
+ description: 'Optional sender name to display',
64
+ required: false,
65
+ }),
66
+ attachment: pieces_framework_1.Property.File({
67
+ displayName: 'Attachment',
68
+ description: 'Optional file to attach to your reply',
69
+ required: false,
70
+ }),
71
+ attachment_name: pieces_framework_1.Property.ShortText({
72
+ displayName: 'Attachment Name',
73
+ description: 'Custom name for the attachment',
74
+ required: false,
75
+ }),
76
+ },
77
+ run(context) {
78
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
79
+ var _a;
80
+ const authClient = new googleapis_common_1.OAuth2Client();
81
+ authClient.setCredentials(context.auth);
82
+ const gmail = googleapis_1.google.gmail({ version: 'v1', auth: authClient });
83
+ const originalMessage = yield gmail.users.messages.get({
84
+ userId: 'me',
85
+ id: context.propsValue.message_id,
86
+ format: 'full',
87
+ });
88
+ if (!originalMessage.data || !originalMessage.data.payload) {
89
+ throw new Error('Could not fetch original message details');
90
+ }
91
+ const headers = originalMessage.data.payload.headers || [];
92
+ const headerMap = headers.reduce((acc, header) => {
93
+ if (header.name && header.value) {
94
+ acc[header.name.toLowerCase()] = header.value;
95
+ }
96
+ return acc;
97
+ }, {});
98
+ const originalSubject = headerMap['subject'] || '';
99
+ const originalFrom = headerMap['from'] || '';
100
+ const originalTo = headerMap['to'] || '';
101
+ const originalCc = headerMap['cc'] || '';
102
+ const originalReplyTo = headerMap['reply-to'] || '';
103
+ const originalMessageId = headerMap['message-id'] || '';
104
+ const originalReferences = headerMap['references'] || '';
105
+ const toRecipients = [];
106
+ const ccRecipients = [];
107
+ if (context.propsValue.reply_type === 'reply_all') {
108
+ const senderEmail = originalReplyTo || originalFrom;
109
+ if (senderEmail) {
110
+ toRecipients.push(senderEmail);
111
+ }
112
+ const currentUserEmail = (yield googleapis_1.google.oauth2({ version: 'v2', auth: authClient }).userinfo.get()).data.email;
113
+ if (originalTo) {
114
+ const toEmails = originalTo.split(',').map((email) => email.trim());
115
+ toRecipients.push(...toEmails.filter((email) => !email.includes(currentUserEmail || '')));
116
+ }
117
+ if (originalCc) {
118
+ const ccEmails = originalCc.split(',').map((email) => email.trim());
119
+ ccRecipients.push(...ccEmails.filter((email) => !email.includes(currentUserEmail || '')));
120
+ }
121
+ }
122
+ else {
123
+ const senderEmail = originalReplyTo || originalFrom;
124
+ if (senderEmail) {
125
+ toRecipients.push(senderEmail);
126
+ }
127
+ }
128
+ let replySubject = originalSubject;
129
+ if (!replySubject.toLowerCase().startsWith('re:')) {
130
+ replySubject = `Re: ${replySubject}`;
131
+ }
132
+ let referencesHeader = originalMessageId;
133
+ if (originalReferences) {
134
+ referencesHeader = `${originalReferences} ${originalMessageId}`;
135
+ }
136
+ const senderEmail = (yield googleapis_1.google.oauth2({ version: 'v2', auth: authClient }).userinfo.get()).data.email;
137
+ const subjectBase64 = Buffer.from(replySubject).toString('base64');
138
+ const mailOptions = {
139
+ to: toRecipients.join(', '),
140
+ cc: ccRecipients.length > 0 ? ccRecipients.join(', ') : undefined,
141
+ subject: `=?UTF-8?B?${subjectBase64}?=`,
142
+ text: context.propsValue.body_type === 'plain_text'
143
+ ? context.propsValue.body
144
+ : undefined,
145
+ html: context.propsValue.body_type === 'html'
146
+ ? context.propsValue.body
147
+ : undefined,
148
+ attachments: [],
149
+ headers: [
150
+ {
151
+ key: 'In-Reply-To',
152
+ value: originalMessageId,
153
+ },
154
+ {
155
+ key: 'References',
156
+ value: referencesHeader,
157
+ },
158
+ ],
159
+ };
160
+ if (senderEmail) {
161
+ mailOptions.from = context.propsValue.sender_name
162
+ ? `${context.propsValue.sender_name} <${senderEmail}>`
163
+ : senderEmail;
164
+ }
165
+ if (context.propsValue.attachment) {
166
+ const lookupResult = mime_types_1.default.lookup(context.propsValue.attachment.extension || '');
167
+ const attachmentOption = [
168
+ {
169
+ filename: (_a = context.propsValue.attachment_name) !== null && _a !== void 0 ? _a : context.propsValue.attachment.filename,
170
+ content: context.propsValue.attachment.base64,
171
+ contentType: lookupResult || undefined,
172
+ encoding: 'base64',
173
+ },
174
+ ];
175
+ mailOptions.attachments = attachmentOption;
176
+ }
177
+ const mail = new mail_composer_1.default(mailOptions).compile();
178
+ mail.keepBcc = true;
179
+ const mailBody = yield mail.build();
180
+ const encodedPayload = Buffer.from(mailBody)
181
+ .toString('base64')
182
+ .replace(/\+/g, '-')
183
+ .replace(/\//g, '_');
184
+ const response = yield gmail.users.messages.send({
185
+ userId: 'me',
186
+ requestBody: {
187
+ threadId: originalMessage.data.threadId || undefined,
188
+ raw: encodedPayload,
189
+ },
190
+ });
191
+ return response.data;
192
+ });
193
+ },
194
+ });
195
+ //# sourceMappingURL=reply-to-email-action.js.map