Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Gmail Trigger Node): Filter by labels not working #5173

Merged
merged 1 commit into from
Jan 18, 2023
Merged
Changes from all commits
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
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