Skip to content

Commit e9e716e

Browse files
committed
updates
1 parent 1193330 commit e9e716e

File tree

5 files changed

+47
-30
lines changed

5 files changed

+47
-30
lines changed

components/gmail/actions/create-draft/create-draft.mjs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import gmail from "../../gmail.app.mjs";
22
import { ConfigurationError } from "@pipedream/platform";
3+
import utils from "../../common/utils.mjs";
34

45
export default {
56
key: "gmail-create-draft",
@@ -45,16 +46,16 @@ export default {
4546
"bodyType",
4647
],
4748
},
48-
attachmentFilename: {
49+
attachmentFilenames: {
4950
propDefinition: [
5051
gmail,
51-
"attachmentFilename",
52+
"attachmentFilenames",
5253
],
5354
},
54-
attachmentUrlOrPath: {
55+
attachmentUrlsOrPaths: {
5556
propDefinition: [
5657
gmail,
57-
"attachmentUrlOrPath",
58+
"attachmentUrlsOrPaths",
5859
],
5960
},
6061
inReplyTo: {
@@ -74,9 +75,10 @@ export default {
7475
},
7576
},
7677
async run({ $ }) {
77-
if ((this.attachmentFilename && ! this.attachmentUrlOrPath)
78-
|| (!this.attachmentFilename && this.attachmentUrlOrPath)) {
79-
throw new ConfigurationError("Must specify both `Attachment Filename` and `Attachment URL or Path`");
78+
this.attachmentFilenames = utils.parseArray(this.attachmentFilenames);
79+
this.attachmentUrlsOrPaths = utils.parseArray(this.attachmentUrlsOrPaths);
80+
if (this.attachmentFilenames?.length !== this.attachmentUrlsOrPaths?.length) {
81+
throw new ConfigurationError("Must specify the same number of `Attachment Filenames` and `Attachment URLs or Paths`");
8082
}
8183
const opts = await this.gmail.getOptionsToSendEmail($, this);
8284
const response = await this.gmail.createDraft(opts);

components/gmail/actions/send-email/send-email.mjs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import gmail from "../../gmail.app.mjs";
22
import { ConfigurationError } from "@pipedream/platform";
3+
import utils from "../../common/utils.mjs";
34

45
export default {
56
key: "gmail-send-email",
@@ -63,16 +64,16 @@ export default {
6364
"bodyType",
6465
],
6566
},
66-
attachmentFilename: {
67+
attachmentFilenames: {
6768
propDefinition: [
6869
gmail,
69-
"attachmentFilename",
70+
"attachmentFilenames",
7071
],
7172
},
72-
attachmentUrlOrPath: {
73+
attachmentUrlsOrPaths: {
7374
propDefinition: [
7475
gmail,
75-
"attachmentUrlOrPath",
76+
"attachmentUrlsOrPaths",
7677
],
7778
},
7879
inReplyTo: {
@@ -89,9 +90,10 @@ export default {
8990
},
9091
},
9192
async run({ $ }) {
92-
if ((this.attachmentFilename && ! this.attachmentUrlOrPath)
93-
|| (!this.attachmentFilename && this.attachmentUrlOrPath)) {
94-
throw new ConfigurationError("Must specify both `Attachment Filename` and `Attachment URL or Path`");
93+
this.attachmentFilenames = utils.parseArray(this.attachmentFilenames);
94+
this.attachmentUrlsOrPaths = utils.parseArray(this.attachmentUrlsOrPaths);
95+
if (this.attachmentFilenames?.length !== this.attachmentUrlsOrPaths?.length) {
96+
throw new ConfigurationError("Must specify the same number of `Attachment Filenames` and `Attachment URLs or Paths`");
9597
}
9698
const opts = await this.gmail.getOptionsToSendEmail($, this);
9799
const response = await this.gmail.sendEmail(opts);

components/gmail/common/utils.mjs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function parseArray(arr) {
2+
if (!arr) {
3+
return undefined;
4+
}
5+
return typeof arr === "string"
6+
? JSON.parse(arr)
7+
: arr;
8+
}
9+
10+
export default {
11+
parseArray,
12+
};

components/gmail/gmail.app.mjs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -231,16 +231,16 @@ export default {
231231
default: "plaintext",
232232
options: Object.values(constants.BODY_TYPES),
233233
},
234-
attachmentFilename: {
235-
type: "string",
236-
label: "Attachment Filename",
237-
description: "The name of the file to attach. Must contain the file extension (e.g. `.jpeg`, `.txt`)",
234+
attachmentFilenames: {
235+
type: "string[]",
236+
label: "Attachment Filenames",
237+
description: "Array of the names of the files to attach. Must contain the file extension (e.g. `.jpeg`, `.txt`). Use in conjuction with `Attachment URLs or Paths`.",
238238
optional: true,
239239
},
240-
attachmentUrlOrPath: {
241-
type: "string",
242-
label: "Attachment URL or Path",
243-
description: "The URL of the download link for the file, or the local path (e.g. `/tmp/my-file.txt`).",
240+
attachmentUrlsOrPaths: {
241+
type: "string[]",
242+
label: "Attachment URLs or Paths",
243+
description: "Array of the URLs of the download links for the files, or the local paths (e.g. `/tmp/my-file.txt`). Use in conjuction with `Attachment Filenames`.",
244244
optional: true,
245245
},
246246
inReplyTo: {
@@ -308,13 +308,14 @@ export default {
308308
}
309309
}
310310

311-
if (props.attachmentFilename && props.attachmentUrlOrPath) {
312-
opts.attachments = [
313-
{
314-
filename: props.attachmentFilename,
315-
path: props.attachmentUrlOrPath,
316-
},
317-
];
311+
if (props.attachmentFilenames?.length && props.attachmentUrlsOrPaths?.length) {
312+
opts.attachments = [];
313+
for (let i = 0; i < props.attachmentFilenames.length; i++) {
314+
opts.attachments.push({
315+
filename: props.attachmentFilenames[i],
316+
path: props.attachmentUrlsOrPaths[i],
317+
});
318+
}
318319
}
319320

320321
if (props.bodyType === constants.BODY_TYPES.HTML) {

components/gmail/sources/new-email-received/new-email-received.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,6 @@ export default {
394394
}
395395

396396
if (this.triggerType === "webhook") {
397-
this._setLastProcessedHistoryId(this.initialHistoryId);
398397
if (event.timestamp) {
399398
// event was triggered by timer
400399
const topicName = this._getTopicName();
@@ -405,6 +404,7 @@ export default {
405404
} else {
406405
// first run, no need to renew push notifications
407406
this._setTopicName(this.topic);
407+
this._setLastProcessedHistoryId(this.initialHistoryId);
408408
return;
409409
}
410410
}

0 commit comments

Comments
 (0)