Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "gmail-add-label-to-email",
name: "Add Label to Email",
description: "Add label(s) to an email message. [See the docs](https://developers.google.com/gmail/api/reference/rest/v1/users.messages/modify)",
version: "0.0.4",
version: "0.0.5",
type: "action",
props: {
gmail,
Expand Down
19 changes: 16 additions & 3 deletions components/gmail/actions/create-draft/create-draft.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import gmail from "../../gmail.app.mjs";
import { ConfigurationError } from "@pipedream/platform";
import utils from "../../common/utils.mjs";

export default {
key: "gmail-create-draft",
name: "Create Draft",
description: "Create a draft from your Google Workspace email account. [See the documentation](https://developers.google.com/gmail/api/reference/rest/v1/users.drafts/create)",
version: "0.0.2",
version: "0.0.3",
type: "action",
props: {
gmail,
Expand Down Expand Up @@ -44,10 +46,16 @@ export default {
"bodyType",
],
},
attachments: {
attachmentFilenames: {
propDefinition: [
gmail,
"attachments",
"attachmentFilenames",
],
},
attachmentUrlsOrPaths: {
propDefinition: [
gmail,
"attachmentUrlsOrPaths",
],
},
inReplyTo: {
Expand All @@ -67,6 +75,11 @@ export default {
},
},
async run({ $ }) {
this.attachmentFilenames = utils.parseArray(this.attachmentFilenames);
this.attachmentUrlsOrPaths = utils.parseArray(this.attachmentUrlsOrPaths);
if (this.attachmentFilenames?.length !== this.attachmentUrlsOrPaths?.length) {
throw new ConfigurationError("Must specify the same number of `Attachment Filenames` and `Attachment URLs or Paths`");
}
const opts = await this.gmail.getOptionsToSendEmail($, this);
const response = await this.gmail.createDraft(opts);
$.export("$summary", "Successfully created a draft message");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default {
key: "gmail-download-attachment",
name: "Download Attachment",
description: "Download an attachment by attachmentId to the /tmp directory. [See the documentation](https://developers.google.com/gmail/api/reference/rest/v1/users.messages.attachments/get)",
version: "0.0.2",
version: "0.0.3",
type: "action",
props: {
gmail,
Expand Down
2 changes: 1 addition & 1 deletion components/gmail/actions/find-email/find-email.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "gmail-find-email",
name: "Find Email",
description: "Find an email using Google's Search Engine. [See the docs](https://developers.google.com/gmail/api/reference/rest/v1/users.messages/list)",
version: "0.0.5",
version: "0.0.6",
type: "action",
props: {
gmail,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "gmail-remove-label-from-email",
name: "Remove Label from Email",
description: "Remove label(s) from an email message. [See the docs](https://developers.google.com/gmail/api/reference/rest/v1/users.messages/modify)",
version: "0.0.1",
version: "0.0.2",
type: "action",
props: {
gmail,
Expand Down
25 changes: 22 additions & 3 deletions components/gmail/actions/send-email/send-email.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import gmail from "../../gmail.app.mjs";
import { ConfigurationError } from "@pipedream/platform";
import utils from "../../common/utils.mjs";

export default {
key: "gmail-send-email",
name: "Send Email",
description: "Send an email from your Google Workspace email account. [See the documentation](https://developers.google.com/gmail/api/reference/rest/v1/users.messages/send)",
version: "0.1.4",
version: "0.1.5",
type: "action",
props: {
gmail,
Expand Down Expand Up @@ -32,6 +34,12 @@ export default {
"fromName",
],
},
fromEmail: {
propDefinition: [
gmail,
"fromEmail",
],
},
replyTo: {
propDefinition: [
gmail,
Expand All @@ -56,10 +64,16 @@ export default {
"bodyType",
],
},
attachments: {
attachmentFilenames: {
propDefinition: [
gmail,
"attachmentFilenames",
],
},
attachmentUrlsOrPaths: {
propDefinition: [
gmail,
"attachments",
"attachmentUrlsOrPaths",
],
},
inReplyTo: {
Expand All @@ -76,6 +90,11 @@ export default {
},
},
async run({ $ }) {
this.attachmentFilenames = utils.parseArray(this.attachmentFilenames);
this.attachmentUrlsOrPaths = utils.parseArray(this.attachmentUrlsOrPaths);
if (this.attachmentFilenames?.length !== this.attachmentUrlsOrPaths?.length) {
throw new ConfigurationError("Must specify the same number of `Attachment Filenames` and `Attachment URLs or Paths`");
}
const opts = await this.gmail.getOptionsToSendEmail($, this);
const response = await this.gmail.sendEmail(opts);
$.export("$summary", `Successfully sent email to ${this.to}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default {
name: "Update Signature for Email in Organization",
description: `Update the signature for a specific email address in an organization.
A Google Cloud service account with delegated domain-wide authority is required for this action. [See the documentation](https://developers.google.com/gmail/api/reference/rest/v1/users.settings.sendAs/update)`,
version: "0.0.2",
version: "0.0.3",
type: "action",
props: {
gmail,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "gmail-update-primary-signature",
name: "Update Signature for Primary Email Address",
description: "Update the signature for the primary email address. [See the documentation](https://developers.google.com/gmail/api/reference/rest/v1/users.settings.sendAs/update)",
version: "0.0.2",
version: "0.0.3",
type: "action",
props: {
gmail,
Expand Down
12 changes: 12 additions & 0 deletions components/gmail/common/utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function parseArray(arr) {
if (!arr) {
return undefined;
}
return typeof arr === "string"
? JSON.parse(arr)
: arr;
}

export default {
parseArray,
};
49 changes: 32 additions & 17 deletions components/gmail/gmail.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,18 @@ export default {
description: "Specify the name that will be displayed in the \"From\" section of the email.",
optional: true,
},
fromEmail: {
type: "string",
label: "From Email",
description: "Specify the email address that will be displayed in the \"From\" section of the email.",
optional: true,
async options() {
const { sendAs } = await this.listSignatures();
return sendAs
.filter(({ sendAsEmail }) => sendAsEmail)
.map(({ sendAsEmail }) => sendAsEmail);
},
},
replyTo: {
type: "string",
label: "Reply To",
Expand All @@ -219,10 +231,16 @@ export default {
default: "plaintext",
options: Object.values(constants.BODY_TYPES),
},
attachments: {
type: "object",
label: "Attachments",
description: "Add any attachments you'd like to include as objects.\n- The `key` should be the filename and must contain the file extension (e.g. `.jpeg`, `.txt`).\n- The `value` should be a URL of the download link for the file, or the local path (e.g. `/tmp/my-file.txt`).",
attachmentFilenames: {
type: "string[]",
label: "Attachment Filenames",
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`.",
optional: true,
},
attachmentUrlsOrPaths: {
type: "string[]",
label: "Attachment URLs or Paths",
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`.",
optional: true,
},
inReplyTo: {
Expand Down Expand Up @@ -260,11 +278,12 @@ export default {
name: fromName,
email,
} = await this.userInfo();
const fromEmail = props.fromEmail || email;

const opts = {
from: props.fromName
? `${props.fromName} <${email}>`
: `${fromName} <${email}>`,
? `${props.fromName} <${fromEmail}>`
: `${fromName} <${fromEmail}>`,
to: props.to,
cc: props.cc,
bcc: props.bcc,
Expand All @@ -289,18 +308,14 @@ export default {
}
}

if (props.attachments) {
if (typeof props.attachments === "string") {
props.attachments = JSON.parse(props.attachments);
if (props.attachmentFilenames?.length && props.attachmentUrlsOrPaths?.length) {
opts.attachments = [];
for (let i = 0; i < props.attachmentFilenames.length; i++) {
opts.attachments.push({
filename: props.attachmentFilenames[i],
path: props.attachmentUrlsOrPaths[i],
});
}
opts.attachments = Object.entries(props.attachments)
.map(([
filename,
path,
]) => ({
filename,
path,
}));
}

if (props.bodyType === constants.BODY_TYPES.HTML) {
Expand Down
2 changes: 1 addition & 1 deletion components/gmail/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/gmail",
"version": "0.1.2",
"version": "0.1.3",
"description": "Pipedream Gmail Components",
"main": "gmail.app.mjs",
"keywords": [
Expand Down
3 changes: 3 additions & 0 deletions components/gmail/sources/common/polling-history.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ export default {
hooks: {
...common.hooks,
async deploy() {
if (this.triggerType === "webhook") {
return;
}
const historyId = await this.getHistoryId();
if (!historyId) {
return;
Expand Down
13 changes: 0 additions & 13 deletions components/gmail/sources/common/verify-client-id.mjs
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
import gmail from "../../gmail.app.mjs";

const restrictedClientId = "38931588176-fnd4m13k1mjb6djallp1m9kr7o8kslcu.apps.googleusercontent.com";

export default {
props: {
gmail: {
...gmail,
reloadProps: true,
},
appAlert: {
type: "alert",
content: "",
hidden: true,
},
},
methods: {
async checkClientId() {
return this.gmail.$auth.oauth_client_id !== restrictedClientId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default {
key: "gmail-new-attachment-received",
name: "New Attachment Received",
description: "Emit new event for each attachment in a message received. This source is capped at 100 max new messages per run.",
version: "0.0.2",
version: "0.0.3",
type: "source",
dedupe: "unique",
props: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default {
key: "gmail-new-email-matching-search",
name: "New Email Matching Search",
description: "Emit new event when an email matching the search criteria is received. This source is capped at 100 max new messages per run.",
version: "0.0.1",
version: "0.0.2",
type: "source",
dedupe: "unique",
props: {
Expand Down
Loading