Skip to content

Commit

Permalink
fix(Gmail Trigger Node): Filter by labels not working (#5173)
Browse files Browse the repository at this point in the history
⚡️added missing getLabels loadOptions
  • Loading branch information
maspio authored Jan 18, 2023
1 parent 5426690 commit 026f3a5
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion packages/nodes-base/nodes/Google/Gmail/GmailTrigger.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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<INodePropertyOptions[]> {
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<INodeExecutionData[][] | null> {
const webhookData = this.getWorkflowStaticData('node');
let responseData;
Expand Down

0 comments on commit 026f3a5

Please sign in to comment.