From 026f3a532d30dcf79b76c9f9cff709e6af0eb9ee Mon Sep 17 00:00:00 2001 From: Marcus <56945030+maspio@users.noreply.github.com> Date: Wed, 18 Jan 2023 10:47:26 +0100 Subject: [PATCH] fix(Gmail Trigger Node): Filter by labels not working (#5173) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ⚡️added missing getLabels loadOptions --- .../nodes/Google/Gmail/GmailTrigger.node.ts | 44 ++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/packages/nodes-base/nodes/Google/Gmail/GmailTrigger.node.ts b/packages/nodes-base/nodes/Google/Gmail/GmailTrigger.node.ts index 8b3add99a0..6e364306a3 100644 --- a/packages/nodes-base/nodes/Google/Gmail/GmailTrigger.node.ts +++ b/packages/nodes-base/nodes/Google/Gmail/GmailTrigger.node.ts @@ -2,13 +2,21 @@ import { IPollFunctions } from 'n8n-core'; import { IDataObject, + ILoadOptionsFunctions, INodeExecutionData, + INodePropertyOptions, INodeType, INodeTypeDescription, LoggerProxy as Logger, } from 'n8n-workflow'; -import { googleApiRequest, parseRawEmail, prepareQuery, simplifyOutput } from './GenericFunctions'; +import { + googleApiRequest, + googleApiRequestAllItems, + parseRawEmail, + prepareQuery, + simplifyOutput, +} from './GenericFunctions'; import { DateTime } from 'luxon'; @@ -186,6 +194,40 @@ export class GmailTrigger implements INodeType { ], }; + methods = { + loadOptions: { + // Get all the labels to display them to user so that he can + // select them easily + async getLabels(this: ILoadOptionsFunctions): Promise { + const returnData: INodePropertyOptions[] = []; + + const labels = await googleApiRequestAllItems.call( + this, + 'labels', + 'GET', + '/gmail/v1/users/me/labels', + ); + + for (const label of labels) { + returnData.push({ + name: label.name, + value: label.id, + }); + } + + return returnData.sort((a, b) => { + if (a.name < b.name) { + return -1; + } + if (a.name > b.name) { + return 1; + } + return 0; + }); + }, + }, + }; + async poll(this: IPollFunctions): Promise { const webhookData = this.getWorkflowStaticData('node'); let responseData;