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
35 changes: 35 additions & 0 deletions components/gmail/actions/archive-email/archive-email.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import gmail from "../../gmail.app.mjs";
import constants from "../../common/constants.mjs";

export default {
key: "gmail-archive-email",
name: "Archive Email",
description: "Archive an email message. [See the documentation](https://developers.google.com/gmail/api/reference/rest/v1/users.messages/modify)",
version: "0.0.1",
type: "action",
props: {
gmail,
message: {
propDefinition: [
gmail,
"message",
],
},
},
async run({ $ }) {
const {
gmail,
message,
} = this;

const response = await gmail.updateLabels({
message,
removeLabelIds: [
constants.INBOX_LABEL_ID,
],
});

$.export("$summary", `Successfully archived email (ID: ${message})`);
return response;
},
Comment on lines +19 to +34
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Implementation is correct but consider adding error handling.

The implementation correctly uses the Gmail API to remove the INBOX label, effectively archiving the email.

Consider adding error handling to provide better feedback to users:

 async run({ $ }) {
   const {
     gmail,
     message,
   } = this;

-  const response = await gmail.updateLabels({
-    message,
-    removeLabelIds: [
-      constants.INBOX_LABEL_ID,
-    ],
-  });
-
-  $.export("$summary", `Successfully archived email (ID: ${message})`);
-  return response;
+  try {
+    const response = await gmail.updateLabels({
+      message,
+      removeLabelIds: [
+        constants.INBOX_LABEL_ID,
+      ],
+    });
+
+    $.export("$summary", `Successfully archived email (ID: ${message})`);
+    return response;
+  } catch (error) {
+    $.export("$summary", `Failed to archive email: ${error.message}`);
+    throw error;
+  }
 },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
async run({ $ }) {
const {
gmail,
message,
} = this;
const response = await gmail.updateLabels({
message,
removeLabelIds: [
constants.INBOX_LABEL_ID,
],
});
$.export("$summary", `Successfully archived email (ID: ${message})`);
return response;
},
async run({ $ }) {
const {
gmail,
message,
} = this;
try {
const response = await gmail.updateLabels({
message,
removeLabelIds: [
constants.INBOX_LABEL_ID,
],
});
$.export("$summary", `Successfully archived email (ID: ${message})`);
return response;
} catch (error) {
$.export("$summary", `Failed to archive email: ${error.message}`);
throw error;
}
},

};
2 changes: 2 additions & 0 deletions components/gmail/common/constants.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ const BODY_TYPES = {
};
const HISTORICAL_EVENTS = 10;
const DEFAULT_LIMIT = 100;
const INBOX_LABEL_ID = "INBOX";

export default {
USER_ID,
BODY_TYPES,
HISTORICAL_EVENTS,
DEFAULT_LIMIT,
INBOX_LABEL_ID,
};
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.2.10",
"version": "0.3.0",
"description": "Pipedream Gmail Components",
"main": "gmail.app.mjs",
"keywords": [
Expand Down
Loading