Skip to content

Commit 2bc11be

Browse files
committed
some adjusts
1 parent 78c5717 commit 2bc11be

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

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

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { convert } from "html-to-text";
12
import gmail from "../../gmail.app.mjs";
23

34
export default {
@@ -14,10 +15,10 @@ export default {
1415
"q",
1516
],
1617
},
17-
withPayload: {
18+
withTextPayload: {
1819
type: "boolean",
19-
label: "With Payload",
20-
description: "Whether or not to return the full content of the email message. If set to `true`, the action will return the full content of the email message, including headers and body. `Setting to true may make the response size larger and slower`.",
20+
label: "With Text Payload",
21+
description: "Whether you want to convert the payload response into a single text field. **This reduces the size of the payload and makes it easier for LLM work with.**",
2122
default: false,
2223
},
2324
labels: {
@@ -55,19 +56,19 @@ export default {
5556
const messageIds = messages.map(({ id }) => id);
5657
let messagesToEmit = await this.gmail.getMessages(messageIds);
5758

58-
if (this.withPayload) {
59-
for await (const message of messagesToEmit) {
60-
for (const part of message.payload?.parts || []) {
61-
if (part.body.data) {
62-
part.body.text = Buffer.from(part.body.data, "base64").toString("utf-8");
63-
}
59+
for await (const message of messagesToEmit) {
60+
let newPayload = "";
61+
for (const part of message.payload?.parts || []) {
62+
if (part.body.data) {
63+
const payload = Buffer.from(part.body.data, "base64").toString("utf-8");
64+
this.withTextPayload
65+
? newPayload += convert(payload)
66+
: part.body.text = payload;
6467
}
6568
}
66-
} else {
67-
messagesToEmit = messagesToEmit.map((message) => {
68-
delete message.payload;
69-
return message;
70-
});
69+
if (this.withTextPayload) {
70+
message.payload = newPayload;
71+
}
7172
}
7273

7374
const suffix = messagesToEmit.length === 1

components/gmail/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"@pipedream/platform": "^3.0.3",
2020
"google-auth-library": "^8.7.0",
2121
"googleapis": "^105.0.0",
22-
"html-to-text": "^8.2.1",
22+
"html-to-text": "^9.0.5",
2323
"mime": "^3.0.0",
2424
"nodemailer": "^6.7.8",
2525
"uuid": "^10.0.0"

0 commit comments

Comments
 (0)