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;