Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
@@ -0,0 +1,34 @@
import gmail from "../../gmail.app.mjs";

export default {
key: "gmail-list-thread-messages",
name: "List Thread Messages",
description: "List messages in a thread. [See the docs](https://developers.google.com/workspace/gmail/api/reference/rest/v1/users.threads/get)",
version: "0.0.1",
annotations: {
destructiveHint: false,
openWorldHint: true,
readOnlyHint: true,
},
type: "action",
props: {
gmail,
threadId: {
propDefinition: [
gmail,
"threadId",
],
},
},
async run({ $ }) {
const { messages = [] } = await this.gmail.getThread({
threadId: this.threadId,
});

const suffix = messages.length === 1
? ""
: "s";
$.export("$summary", `Successfully listed ${messages.length} message${suffix}`);
return messages;
},
};
45 changes: 43 additions & 2 deletions components/gmail/gmail.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import {
axios,
ConfigurationError,
} from "@pipedream/platform";
import { JWT } from "google-auth-library";
import { convert } from "html-to-text";
import mime from "mime/types/standard.js";
import MailComposer from "nodemailer/lib/mail-composer/index.js";
import addressparser from "nodemailer/lib/addressparser/index.js";
import MailComposer from "nodemailer/lib/mail-composer/index.js";
import constants from "./common/constants.mjs";
import { JWT } from "google-auth-library";

export default {
type: "app",
Expand Down Expand Up @@ -166,6 +166,33 @@ export default {
}
},
},
threadId: {
type: "string",
label: "Thread ID",
description: "Identifier of the thread to list messages from",
async options({ prevContext }) {
try {
const {
threads, nextPageToken,
} = await this.listThreads({
pageToken: prevContext?.nextPageToken,
});
return {
options: threads.map(({
id: value, snippet: label,
}) => ({
value,
label,
})),
context: {
nextPageToken,
},
};
} catch {
return [];
}
},
},
q: {
type: "string",
label: "Search Query",
Expand Down Expand Up @@ -421,6 +448,20 @@ export default {
});
return data;
},
async listThreads(opts = {}) {
const { data } = await this._client().users.threads.list({
userId: constants.USER_ID,
...opts,
});
return data;
},
async getThread({ threadId }) {
const { data } = await this._client().users.threads.get({
userId: constants.USER_ID,
id: threadId,
});
return data;
},
async getProfile() {
const { data } = await this._client().users.getProfile({
userId: constants.USER_ID,
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": "1.3.5",
"version": "1.4.0",
"description": "Pipedream Gmail Components",
"main": "gmail.app.mjs",
"keywords": [
Expand Down
Loading