Add fields parameter to Facebook Trigger (#2026)

*  Add fields parameter

*  Revert to not subscribe to anything by default to avoid breaking
change

Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
This commit is contained in:
Ricardo Espinoza
2021-07-29 09:32:01 -04:00
committed by GitHub
parent 9a7c25aacd
commit 65c40a1d1e
2 changed files with 546 additions and 8 deletions

View File

@@ -5,6 +5,8 @@ import {
import {
IDataObject,
ILoadOptionsFunctions,
INodePropertyOptions,
INodeType,
INodeTypeDescription,
IWebhookResponseData,
@@ -18,7 +20,7 @@ import {
} from 'change-case';
import {
facebookApiRequest,
facebookApiRequest, getAllFields, getFields,
} from './GenericFunctions';
import {
@@ -61,6 +63,14 @@ export class FacebookTrigger implements INodeType {
},
],
properties: [
{
displayName: 'APP ID',
name: 'appId',
type: 'string',
required: true,
default: '',
description: 'Facebook APP ID',
},
{
displayName: 'Object',
name: 'object',
@@ -126,13 +136,20 @@ export class FacebookTrigger implements INodeType {
default: 'user',
description: 'The object to subscribe to',
},
//https://developers.facebook.com/docs/graph-api/webhooks/reference/page
{
displayName: 'App ID',
name: 'appId',
type: 'string',
required: true,
default: '',
description: 'Facebook APP ID',
displayName: 'Fields',
name: 'fields',
type: 'multiOptions',
typeOptions: {
loadOptionsMethod: 'getObjectFields',
loadOptionsDependsOn: [
'object',
],
},
required: false,
default: [],
description: 'The set of fields in this object that are subscribed to',
},
{
displayName: 'Options',
@@ -153,6 +170,18 @@ export class FacebookTrigger implements INodeType {
],
};
methods = {
loadOptions: {
// Get all the available organizations to display them to user so that he can
// select them easily
async getObjectFields(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const object = this.getCurrentNodeParameter('object') as string;
return getFields(object) as INodePropertyOptions[];
},
},
};
// @ts-ignore (because of request)
webhookMethods = {
default: {
@@ -175,12 +204,14 @@ export class FacebookTrigger implements INodeType {
const webhookUrl = this.getNodeWebhookUrl('default') as string;
const object = this.getNodeParameter('object') as string;
const appId = this.getNodeParameter('appId') as string;
const fields = this.getNodeParameter('fields') as string[];
const options = this.getNodeParameter('options') as IDataObject;
const body = {
object: snakeCase(object),
callback_url: webhookUrl,
verify_token: uuid(),
fields: (fields.includes('*')) ? getAllFields(object) : fields,
} as IDataObject;
if (options.includeValues !== undefined) {