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

️added missing getLabels loadOptions
This commit is contained in:
Marcus 2023-01-18 10:47:26 +01:00 committed by GitHub
parent 5426690791
commit 026f3a532d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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<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;