first commit
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled

This commit is contained in:
2026-03-17 16:22:57 +03:30
commit 3d5eaf9445
15349 changed files with 2847338 additions and 0 deletions
@@ -0,0 +1,18 @@
{
"node": "n8n-nodes-base.facebookGraphApi",
"nodeVersion": "1.0",
"codexVersion": "1.0",
"categories": ["Development"],
"resources": {
"credentialDocumentation": [
{
"url": "https://docs.n8n.io/integrations/builtin/credentials/facebookgraph/"
}
],
"primaryDocumentation": [
{
"url": "https://docs.n8n.io/integrations/builtin/app-nodes/n8n-nodes-base.facebookgraphapi/"
}
]
}
}
@@ -0,0 +1,478 @@
import type {
IDataObject,
IExecuteFunctions,
IHttpRequestMethods,
INodeExecutionData,
INodeType,
INodeTypeDescription,
IRequestOptions,
JsonObject,
} from 'n8n-workflow';
import { NodeApiError, NodeConnectionTypes, NodeOperationError } from 'n8n-workflow';
export class FacebookGraphApi implements INodeType {
description: INodeTypeDescription = {
displayName: 'Facebook Graph API',
name: 'facebookGraphApi',
icon: 'file:facebook.svg',
group: ['transform'],
version: 1,
description: 'Interacts with Facebook using the Graph API',
defaults: {
name: 'Facebook Graph API',
},
usableAsTool: true,
inputs: [NodeConnectionTypes.Main],
outputs: [NodeConnectionTypes.Main],
credentials: [
{
name: 'facebookGraphApi',
required: true,
},
],
properties: [
{
displayName: 'Host URL',
name: 'hostUrl',
type: 'options',
options: [
{
name: 'Default',
value: 'graph.facebook.com',
},
{
name: 'Video Uploads',
value: 'graph-video.facebook.com',
},
],
default: 'graph.facebook.com',
description:
'The Host URL of the request. Almost all requests are passed to the graph.facebook.com host URL. The single exception is video uploads, which use graph-video.facebook.com.',
required: true,
},
{
displayName: 'HTTP Request Method',
name: 'httpRequestMethod',
type: 'options',
options: [
{
name: 'GET',
value: 'GET',
},
{
name: 'POST',
value: 'POST',
},
{
name: 'DELETE',
value: 'DELETE',
},
],
default: 'GET',
description: 'The HTTP Method to be used for the request',
required: true,
},
{
displayName: 'Graph API Version',
name: 'graphApiVersion',
type: 'options',
options: [
{
name: 'Default',
value: '',
},
{
name: 'v23.0',
value: 'v23.0',
},
{
name: 'v22.0',
value: 'v22.0',
},
{
name: 'v21.0',
value: 'v21.0',
},
{
name: 'v20.0',
value: 'v20.0',
},
{
name: 'v19.0',
value: 'v19.0',
},
{
name: 'v18.0',
value: 'v18.0',
},
{
name: 'v17.0',
value: 'v17.0',
},
{
name: 'v16.0',
value: 'v16.0',
},
{
name: 'v15.0',
value: 'v15.0',
},
{
name: 'v14.0',
value: 'v14.0',
},
{
name: 'v13.0',
value: 'v13.0',
},
{
name: 'v12.0',
value: 'v12.0',
},
{
name: 'v11.0',
value: 'v11.0',
},
{
name: 'v10.0',
value: 'v10.0',
},
{
name: 'v9.0',
value: 'v9.0',
},
{
name: 'v8.0',
value: 'v8.0',
},
{
name: 'v7.0',
value: 'v7.0',
},
{
name: 'v6.0',
value: 'v6.0',
},
{
name: 'v5.0',
value: 'v5.0',
},
{
name: 'v4.0',
value: 'v4.0',
},
{
name: 'v3.3',
value: 'v3.3',
},
{
name: 'v3.2',
value: 'v3.2',
},
{
name: 'v3.1',
value: 'v3.1',
},
{
name: 'v3.0',
value: 'v3.0',
},
],
default: '',
description: 'The version of the Graph API to be used in the request',
required: true,
},
{
displayName: 'Node',
name: 'node',
type: 'string',
default: '',
description:
'The node on which to operate. A node is an individual object with a unique ID. For example, there are many User node objects, each with a unique ID representing a person on Facebook.',
placeholder: 'me',
required: true,
},
{
displayName: 'Edge',
name: 'edge',
type: 'string',
default: '',
description:
'Edge of the node on which to operate. Edges represent collections of objects which are attached to the node.',
placeholder: 'videos',
},
{
displayName: 'Ignore SSL Issues (Insecure)',
name: 'allowUnauthorizedCerts',
type: 'boolean',
default: false,
description: 'Whether to connect even if SSL certificate validation is not possible',
},
{
displayName: 'Send Binary File',
name: 'sendBinaryData',
type: 'boolean',
displayOptions: {
show: {
httpRequestMethod: ['POST', 'PUT'],
},
},
default: false,
required: true,
description: 'Whether binary data should be sent as body',
},
{
displayName: 'Input Binary Field',
name: 'binaryPropertyName',
type: 'string',
default: '',
placeholder: 'file:data',
displayOptions: {
hide: {
sendBinaryData: [false],
},
show: {
httpRequestMethod: ['POST', 'PUT'],
},
},
hint: 'The name of the input binary field containing the file to be uploaded',
description:
'For Form-Data Multipart, they can be provided in the format: <code>"sendKey1:binaryProperty1,sendKey2:binaryProperty2</code>',
},
{
displayName: 'Options',
name: 'options',
type: 'collection',
placeholder: 'Add option',
default: {},
options: [
{
displayName: 'Fields',
name: 'fields',
placeholder: 'Add Field',
type: 'fixedCollection',
typeOptions: {
multipleValues: true,
},
displayOptions: {
show: {
'/httpRequestMethod': ['GET'],
},
},
description: 'The list of fields to request in the GET request',
default: {},
options: [
{
name: 'field',
displayName: 'Field',
values: [
{
displayName: 'Name',
name: 'name',
type: 'string',
default: '',
description: 'Name of the field',
},
],
},
],
},
{
displayName: 'Query Parameters',
name: 'queryParameters',
placeholder: 'Add Parameter',
type: 'fixedCollection',
typeOptions: {
multipleValues: true,
},
description: 'The query parameters to send',
default: {},
options: [
{
name: 'parameter',
displayName: 'Parameter',
values: [
{
displayName: 'Name',
name: 'name',
type: 'string',
default: '',
description: 'Name of the parameter',
},
{
displayName: 'Value',
name: 'value',
type: 'string',
default: '',
description: 'Value of the parameter',
},
],
},
],
},
{
displayName: 'Query Parameters JSON',
name: 'queryParametersJson',
type: 'json',
default: '{}',
placeholder: '{"field_name": "field_value"}',
description: 'The query parameters to send, defined as a JSON object',
},
],
},
],
};
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
const items = this.getInputData();
let response: any;
const returnItems: INodeExecutionData[] = [];
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
const graphApiCredentials = await this.getCredentials('facebookGraphApi');
const hostUrl = this.getNodeParameter('hostUrl', itemIndex) as string;
const httpRequestMethod = this.getNodeParameter(
'httpRequestMethod',
itemIndex,
) as IHttpRequestMethods;
let graphApiVersion = this.getNodeParameter('graphApiVersion', itemIndex) as string;
const node = this.getNodeParameter('node', itemIndex) as string;
const edge = this.getNodeParameter('edge', itemIndex) as string;
const options = this.getNodeParameter('options', itemIndex, {});
if (graphApiVersion !== '') {
graphApiVersion += '/';
}
let uri = `https://${hostUrl}/${graphApiVersion}${node}`;
if (edge) {
uri = `${uri}/${edge}`;
}
const qs: IDataObject = {
access_token: graphApiCredentials.accessToken,
};
const requestOptions: IRequestOptions = {
headers: {
accept: 'application/json,text/*;q=0.99',
},
method: httpRequestMethod,
uri,
json: true,
gzip: true,
rejectUnauthorized: !this.getNodeParameter('allowUnauthorizedCerts', itemIndex, false),
};
if (options !== undefined) {
// Build fields query parameter as a comma separated list
if (options.fields !== undefined) {
const fields = options.fields as IDataObject;
if (fields.field !== undefined) {
const fieldsCsv = (fields.field as IDataObject[]).map((field) => field.name).join(',');
qs.fields = fieldsCsv;
}
}
// Add the query parameters defined in the UI
if (options.queryParameters !== undefined) {
const queryParameters = options.queryParameters as IDataObject;
if (queryParameters.parameter !== undefined) {
for (const queryParameter of queryParameters.parameter as IDataObject[]) {
qs[queryParameter.name as string] = queryParameter.value;
}
}
}
requestOptions.qs = qs;
// Add the query parameters defined as a JSON object
if (options.queryParametersJson) {
let queryParametersJsonObj = {};
try {
queryParametersJsonObj = JSON.parse(options.queryParametersJson as string);
} catch {
/* Do nothing, at least for now */
}
requestOptions.qs = {
...qs,
...queryParametersJsonObj,
};
}
}
const sendBinaryData = this.getNodeParameter('sendBinaryData', itemIndex, false) as boolean;
if (sendBinaryData) {
const binaryPropertyNameFull = this.getNodeParameter('binaryPropertyName', itemIndex);
let propertyName = 'file';
let binaryPropertyName = binaryPropertyNameFull;
if (binaryPropertyNameFull.includes(':')) {
const binaryPropertyNameParts = binaryPropertyNameFull.split(':');
propertyName = binaryPropertyNameParts[0];
binaryPropertyName = binaryPropertyNameParts[1];
}
const binaryData = this.helpers.assertBinaryData(itemIndex, binaryPropertyName);
const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(
itemIndex,
binaryPropertyName,
);
requestOptions.formData = {
[propertyName]: {
value: binaryDataBuffer,
options: {
filename: binaryData.fileName,
contentType: binaryData.mimeType,
},
},
};
}
try {
// Now that the options are all set make the actual http request
response = await this.helpers.request(requestOptions);
} catch (error) {
if (!this.continueOnFail()) {
throw new NodeApiError(this.getNode(), error as JsonObject);
}
let errorItem;
if (error.response !== undefined) {
// Since this is a Graph API node and we already know the request was
// not successful, we'll go straight to the error details.
const graphApiErrors = error.response.body?.error ?? {};
errorItem = {
statusCode: error.statusCode,
...graphApiErrors,
headers: error.response.headers,
};
} else {
// Unknown Graph API response, we'll dump everything in the response item
errorItem = error;
}
returnItems.push({ json: { ...errorItem } });
continue;
}
if (typeof response === 'string') {
if (!this.continueOnFail()) {
throw new NodeOperationError(this.getNode(), 'Response body is not valid JSON.', {
itemIndex,
});
}
returnItems.push({ json: { message: response } });
continue;
}
returnItems.push({ json: response });
}
return [returnItems];
}
}
@@ -0,0 +1,19 @@
{
"node": "n8n-nodes-base.facebookTrigger",
"nodeVersion": "1.0",
"codexVersion": "1.0",
"categories": ["Marketing"],
"resources": {
"credentialDocumentation": [
{
"url": "https://docs.n8n.io/integrations/builtin/credentials/facebookapp/"
}
],
"primaryDocumentation": [
{
"url": "https://docs.n8n.io/integrations/builtin/trigger-nodes/n8n-nodes-base.facebooktrigger/"
}
]
},
"alias": ["FB"]
}
@@ -0,0 +1,301 @@
import { snakeCase } from 'change-case';
import { createHmac } from 'crypto';
import type {
IDataObject,
IHookFunctions,
ILoadOptionsFunctions,
INodePropertyOptions,
INodeType,
INodeTypeDescription,
IWebhookFunctions,
IWebhookResponseData,
JsonObject,
} from 'n8n-workflow';
import { NodeApiError, NodeConnectionTypes, NodeOperationError } from 'n8n-workflow';
import { v4 as uuid } from 'uuid';
import { facebookApiRequest, getAllFields, getFields } from './GenericFunctions';
import type { FacebookWebhookSubscription } from './types';
export class FacebookTrigger implements INodeType {
description: INodeTypeDescription = {
displayName: 'Facebook Trigger',
name: 'facebookTrigger',
icon: 'file:facebook.svg',
group: ['trigger'],
version: 1,
subtitle: '={{$parameter["appId"] +"/"+ $parameter["object"]}}',
description: 'Starts the workflow when Facebook events occur',
defaults: {
name: 'Facebook Trigger',
},
inputs: [],
outputs: [NodeConnectionTypes.Main],
credentials: [
{
name: 'facebookGraphAppApi',
required: true,
},
],
webhooks: [
{
name: 'setup',
httpMethod: 'GET',
responseMode: 'onReceived',
path: 'webhook',
},
{
name: 'default',
httpMethod: 'POST',
responseMode: 'onReceived',
path: 'webhook',
},
],
properties: [
{
displayName: 'APP ID',
name: 'appId',
type: 'string',
required: true,
default: '',
description: 'Facebook APP ID',
},
{
displayName: 'To watch Whatsapp business account events use the Whatsapp trigger node',
name: 'whatsappBusinessAccountNotice',
type: 'notice',
default: '',
displayOptions: {
show: {
object: ['whatsappBusinessAccount'],
},
},
},
{
displayName: 'Object',
name: 'object',
type: 'options',
options: [
{
name: 'Ad Account',
value: 'adAccount',
description: 'Get updates about Ad Account',
},
{
name: 'Application',
value: 'application',
description: 'Get updates about the app',
},
{
name: 'Certificate Transparency',
value: 'certificateTransparency',
description: 'Get updates about Certificate Transparency',
},
{
name: 'Group',
value: 'group',
description: 'Get updates about activity in groups and events in groups for Workplace',
},
{
name: 'Instagram',
value: 'instagram',
description: 'Get updates about comments on your media',
},
{
name: 'Link',
value: 'link',
description: 'Get updates about links for rich previews by an external provider',
},
{
name: 'Page',
value: 'page',
description: 'Page updates',
},
{
name: 'Permissions',
value: 'permissions',
description: 'Updates regarding granting or revoking permissions',
},
{
name: 'User',
value: 'user',
description: 'User profile updates',
},
{
name: 'Whatsapp Business Account',
value: 'whatsappBusinessAccount',
description: 'Get updates about Whatsapp business account',
},
{
name: 'Workplace Security',
value: 'workplaceSecurity',
description: 'Get updates about Workplace Security',
},
],
required: true,
default: 'user',
description: 'The object to subscribe to',
},
//https://developers.facebook.com/docs/graph-api/webhooks/reference/page
{
displayName: 'Field Names or IDs',
name: 'fields',
type: 'multiOptions',
typeOptions: {
loadOptionsMethod: 'getObjectFields',
loadOptionsDependsOn: ['object'],
},
default: [],
description:
'The set of fields in this object that are subscribed to. Choose from the list, or specify IDs using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
},
{
displayName: 'Options',
name: 'options',
type: 'collection',
default: {},
placeholder: 'Add option',
options: [
{
displayName: 'Include Values',
name: 'includeValues',
type: 'boolean',
default: true,
description: 'Whether change notifications should include the new values',
},
],
},
],
};
methods = {
loadOptions: {
// Get all the available organizations to display them to user so that they can
// select them easily
async getObjectFields(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const object = this.getCurrentNodeParameter('object') as string;
return getFields(object) as INodePropertyOptions[];
},
},
};
webhookMethods = {
default: {
async checkExists(this: IHookFunctions): Promise<boolean> {
const webhookUrl = this.getNodeWebhookUrl('default') as string;
const object = this.getNodeParameter('object') as string;
const appId = this.getNodeParameter('appId') as string;
const { data } = (await facebookApiRequest.call(
this,
'GET',
`/${appId}/subscriptions`,
{},
)) as { data: FacebookWebhookSubscription[] };
const subscription = data.find((webhook) => webhook.object === object && webhook.status);
if (!subscription) {
return false;
}
if (subscription.callback_url !== webhookUrl) {
throw new NodeOperationError(
this.getNode(),
`The Facebook App ID ${appId} already has a webhook subscription. Delete it or use another App before executing the trigger. Due to Facebook API limitations, you can have just one trigger per App.`,
{ level: 'warning' },
);
}
return true;
},
async create(this: IHookFunctions): Promise<boolean> {
const webhookData = this.getWorkflowStaticData('node');
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) {
body.include_values = options.includeValues;
}
const responseData = await facebookApiRequest.call(
this,
'POST',
`/${appId}/subscriptions`,
body,
);
webhookData.verifyToken = body.verify_token;
if (responseData.success !== true) {
// Facebook did not return success, so something went wrong
throw new NodeApiError(this.getNode(), responseData as JsonObject, {
message: 'Facebook webhook creation response did not contain the expected data.',
});
}
return true;
},
async delete(this: IHookFunctions): Promise<boolean> {
const appId = this.getNodeParameter('appId') as string;
const object = this.getNodeParameter('object') as string;
try {
await facebookApiRequest.call(this, 'DELETE', `/${appId}/subscriptions`, {
object: snakeCase(object),
});
} catch (error) {
return false;
}
return true;
},
},
};
async webhook(this: IWebhookFunctions): Promise<IWebhookResponseData> {
const bodyData = this.getBodyData();
const query = this.getQueryData() as IDataObject;
const res = this.getResponseObject();
const req = this.getRequestObject();
const headerData = this.getHeaderData() as IDataObject;
const credentials = await this.getCredentials('facebookGraphAppApi');
// Check if we're getting facebook's challenge request (https://developers.facebook.com/docs/graph-api/webhooks/getting-started)
if (this.getWebhookName() === 'setup') {
if (query['hub.challenge']) {
//TODO
//compare hub.verify_token with the saved token
//const webhookData = this.getWorkflowStaticData('node');
// if (webhookData.verifyToken !== query['hub.verify_token']) {
// return {};
// }
res.status(200).send(query['hub.challenge']).end();
return {
noWebhookResponse: true,
};
}
}
// validate signature if app secret is set
if (credentials.appSecret !== '') {
const computedSignature = createHmac('sha1', credentials.appSecret as string)
.update(req.rawBody)
.digest('hex');
if (headerData['x-hub-signature'] !== `sha1=${computedSignature}`) {
return {};
}
}
return {
workflowData: [this.helpers.returnJsonArray(bodyData.entry as IDataObject[])],
};
}
}
@@ -0,0 +1,560 @@
import { capitalCase } from 'change-case';
import type {
IDataObject,
IExecuteFunctions,
IHookFunctions,
IHttpRequestMethods,
ILoadOptionsFunctions,
IRequestOptions,
IWebhookFunctions,
JsonObject,
} from 'n8n-workflow';
import { NodeApiError } from 'n8n-workflow';
export async function facebookApiRequest(
this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions | IWebhookFunctions,
method: IHttpRequestMethods,
resource: string,
body: any = {},
qs: IDataObject = {},
uri?: string,
_option: IDataObject = {},
): Promise<any> {
let credentials;
if (this.getNode().name.includes('Trigger')) {
credentials = await this.getCredentials('facebookGraphAppApi');
} else {
credentials = await this.getCredentials('facebookGraphApi');
}
qs.access_token = credentials.accessToken;
const options: IRequestOptions = {
headers: {
accept: 'application/json,text/*;q=0.99',
},
method,
qs,
body,
gzip: true,
uri: uri || `https://graph.facebook.com/v23.0${resource}`,
json: true,
};
try {
return await this.helpers.request(options);
} catch (error) {
throw new NodeApiError(this.getNode(), error as JsonObject);
}
}
export function getFields(object: string) {
const data = {
adAccount: [
{
value: 'in_process_ad_objects',
},
{
value: 'with_issues_ad_objects',
},
],
page: [
{
value: 'affiliation',
description: "Describes changes to a page's affiliation profile field",
},
{
value: 'attire',
description: "Describes changes to a page's Attire profile field",
},
{
value: 'awards',
description: "Describes changes to a page's Awards profile field",
},
{
value: 'bio',
description: "Describes changes to a page's Biography profile field",
},
{
value: 'birthday',
description: "Describes changes to a page's Birthday profile field",
},
{
value: 'category',
description: "Describes changes to a page's Birthday profile field",
},
{
value: 'company_overview',
description: "Describes changes to a page's Company Overview profile field",
},
{
value: 'culinary_team',
description: "Describes changes to a page's Culinary Team profile field",
},
{
value: 'current_location',
description: "Describes changes to a page's Current Location profile field",
},
{
value: 'description',
description: "Describes changes to a page's Story Description profile field",
},
{
value: 'email',
description: "Describes changes to a page's Email profile field",
},
{
value: 'feed',
description:
"Describes nearly all changes to a Page's feed, such as Posts, shares, likes, etc",
},
{
value: 'founded',
description:
"Describes changes to a page's Founded profile field. This is different from the Start Date field",
},
{
value: 'general_info',
description: "Describes changes to a page's General Information profile field",
},
{
value: 'general_manager',
description: "Describes changes to a page's General Information profile field",
},
{
value: 'hometown',
description: "Describes changes to a page's Hometown profile field",
},
{
value: 'hours',
description: "Describes changes to a page's Hours profile field",
},
{
value: 'leadgen',
description: "Describes changes to a page's leadgen settings",
},
{
value: 'live_videos',
description: "Describes changes to a page's live video status",
},
{
value: 'location',
description: "Describes changes to a page's Location profile field",
},
{
value: 'members',
description: "Describes changes to a page's Members profile field",
},
{
value: 'mention',
description: 'Describes new mentions of a page, including mentions in comments, posts, etc',
},
{
value: 'merchant_review',
description: "Describes changes to a page's merchant review settings",
},
{
value: 'mission',
description: "Describes changes to a page's Mission profile field",
},
{
value: 'name',
description: "Describes changes to a page's Name profile field.",
},
{
value: 'page_about_story',
},
{
value: 'page_change_proposal',
description: 'Data for page change proposal.',
},
{
value: 'page_upcoming_change',
description: 'Webhooks data for page upcoming changes',
},
{
value: 'parking',
description: "Describes changes to a page's Parking profile field",
},
{
value: 'payment_options',
description: "Describes change to a page's Payment profile field",
},
{
value: 'personal_info',
description: "Describes changes to a page's Personal Information profile field.",
},
{
value: 'personal_interests',
description: "Describes changes to a page's Personal Interests profile field.",
},
{
value: 'phone',
description: "Describes changes to a page's Phone profile field",
},
{
value: 'picture',
description: "Describes changes to a page's profile picture",
},
{
value: 'price_range',
description: "Describes changes to a page's Price Range profile field",
},
{
value: 'product_review',
description: "Describes changes to a page's product review settings",
},
{
value: 'products',
description: "Describes changes to a page's Products profile field",
},
{
value: 'public_transit',
description: "Describes changes to a page's Public Transit profile field",
},
{
value: 'ratings',
description:
"Describes changes to a page's ratings, including new ratings or a user's comments or reactions on a rating",
},
{
value: 'videos',
description: 'Describes changes to the encoding status of a video on a page',
},
{
value: 'website',
description: "Describes changes to a page's Website profile field",
},
],
application: [
{
value: 'ad_account',
},
{
value: 'ads_rules_engine',
},
{
value: 'async_requests',
},
{
value: 'async_sessions',
},
{
value: 'group_install',
},
{
value: 'oe_reseller_onboarding_request_created',
},
{
value: 'plugin_comment',
},
{
value: 'plugin_comment_reply',
},
{
value: 'plugin_comment_reply',
},
],
certificateTransparency: [
{
value: 'certificate',
},
{
value: 'phishing',
},
],
instagram: [
{
value: 'comments',
description: 'Notifies you when an Instagram User comments on a media object that you own',
},
{
value: 'messaging_handover',
},
{
value: 'mentions',
description:
'Notifies you when an Instagram User @mentions you in a comment or caption on a media object that you do not own',
},
{
value: 'messages',
},
{
value: 'messaging_seen',
},
{
value: 'standby',
},
{
value: 'story_insights',
},
],
permissions: [
{
value: 'bookmarked',
description: 'Whether the user has added or removed the app bookmark',
},
{
value: 'connected',
description: 'Whether the user is connected or disconnected from the app',
},
{
value: 'user_birthday',
},
{
value: 'user_hometown',
},
{
value: 'user_location',
},
{
value: 'user_likes',
},
{
value: 'user_managed_groups',
},
{
value: 'user_events',
},
{
value: 'user_photos',
},
{
value: 'user_videos',
},
{
value: 'user_friends',
},
{
value: 'user_posts',
},
{
value: 'user_gender',
},
{
value: 'user_link',
},
{
value: 'user_age_range',
},
{
value: 'email',
},
{
value: 'read_insights',
},
{
value: 'read_page_mailboxes',
},
{
value: 'pages_show_list',
},
{
value: 'pages_manage_cta',
},
{
value: 'business_management',
},
{
value: 'pages_messaging',
},
{
value: 'pages_messaging_phone_number',
},
{
value: 'pages_messaging_subscriptions',
},
{
value: 'read_audience_network_insights',
},
{
value: 'pages_manage_instant_articles',
},
{
value: 'publish_video',
},
{
value: 'openid',
},
{
value: 'catalog_management',
},
{
value: 'gaming_user_locale',
},
{
value: 'groups_show_list',
},
{
value: 'instagram_basic',
},
{
value: 'instagram_manage_comments',
},
{
value: 'instagram_manage_insights',
},
{
value: 'instagram_content_publish',
},
{
value: 'publish_to_groups',
},
{
value: 'groups_access_member_info',
},
{
value: 'leads_retrieval',
},
{
value: 'whatsapp_business_management',
},
{
value: 'instagram_manage_messages',
},
{
value: 'attribution_read',
},
{
value: 'page_events',
},
{
value: 'ads_management',
},
{
value: 'ads_read',
},
{
value: 'pages_read_engagement',
},
{
value: 'pages_manage_metadata',
},
{
value: 'pages_read_user_content',
},
{
value: 'pages_manage_ads',
},
{
value: 'pages_manage_posts',
},
{
value: 'pages_manage_engagement',
},
{
value: 'public_search',
},
{
value: 'social_ads',
},
],
users: [
{
value: 'about',
},
{
value: 'birthday',
},
{
value: 'books',
},
{
value: 'email',
},
{
value: 'feed',
},
{
value: 'first_name',
},
{
value: 'friends',
},
{
value: 'gender',
},
{
value: 'hometown',
},
{
value: 'last_name',
},
{
value: 'likes',
},
{
value: 'live_videos',
},
{
value: 'location',
},
{
value: 'music',
},
{
value: 'name',
},
{
value: 'photos',
},
{
value: 'pic_big_https',
},
{
value: 'pic_https',
},
{
value: 'pic_small_https',
},
{
value: 'pic_square_https',
},
{
value: 'platform',
},
{
value: 'quotes',
},
{
value: 'status',
},
{
value: 'television',
},
{
value: 'videos',
},
],
whatsappBusinessAccount: [
{
value: 'message_template_status_update',
},
{
value: 'phone_number_name_update',
},
{
value: 'phone_number_quality_update',
},
{
value: 'account_review_update',
},
{
value: 'account_update',
},
],
} as { [key: string]: any };
return [{ name: '*', value: '*' }].concat(data[object] || []).map((fieldObject: IDataObject) => ({
...fieldObject,
name: fieldObject.value !== '*' ? capitalCase(fieldObject.value as string) : fieldObject.value,
}));
}
export function getAllFields(object: string) {
return getFields(object)
.filter((field: IDataObject) => field.value !== '*')
.map((field: IDataObject) => field.value);
}
@@ -0,0 +1,152 @@
import * as utils from '../GenericFunctions';
jest.mock('n8n-workflow', () => {
const original = jest.requireActual('n8n-workflow');
return {
...original,
NodeApiError: jest.fn().mockImplementation(function (
this: { node: unknown; error: unknown },
node: unknown,
error: unknown,
): never {
const err = new Error('Mock NodeApiError');
(err as any).node = node;
(err as any).error = error;
return Promise.reject(err) as never;
}),
};
});
describe('Facebook GenericFunctions', () => {
let mockExecuteFunctions: any;
beforeEach(() => {
jest.clearAllMocks();
mockExecuteFunctions = {
getNode: jest.fn().mockReturnValue({
name: 'Facebook',
typeVersion: 1,
}),
getCredentials: jest.fn().mockImplementation(async (type) => {
if (type === 'facebookGraphApi') {
return { accessToken: 'test-access-token' };
} else if (type === 'facebookGraphAppApi') {
return { accessToken: 'test-app-access-token' };
}
}),
helpers: {
request: jest.fn(),
},
};
});
describe('facebookApiRequest', () => {
it('should use correct credentials for regular nodes', async () => {
mockExecuteFunctions.helpers.request.mockResolvedValue({ success: true });
await utils.facebookApiRequest.call(
mockExecuteFunctions,
'GET',
'/me',
{},
{ fields: 'id,name' },
);
expect(mockExecuteFunctions.getCredentials).toHaveBeenCalledWith('facebookGraphApi');
expect(mockExecuteFunctions.helpers.request).toHaveBeenCalledWith({
headers: { accept: 'application/json,text/*;q=0.99' },
method: 'GET',
qs: { access_token: 'test-access-token', fields: 'id,name' },
body: {},
gzip: true,
uri: 'https://graph.facebook.com/v23.0/me',
json: true,
});
});
it('should use app credentials for trigger nodes', async () => {
mockExecuteFunctions.getNode.mockReturnValue({ name: 'Facebook Trigger' });
mockExecuteFunctions.helpers.request.mockResolvedValue({ success: true });
await utils.facebookApiRequest.call(mockExecuteFunctions, 'GET', '/app', {}, {});
expect(mockExecuteFunctions.getCredentials).toHaveBeenCalledWith('facebookGraphAppApi');
expect(mockExecuteFunctions.helpers.request).toHaveBeenCalledWith(
expect.objectContaining({
qs: { access_token: 'test-app-access-token' },
}),
);
});
it('should allow custom URI', async () => {
mockExecuteFunctions.helpers.request.mockResolvedValue({ success: true });
const customUri = 'https://graph.facebook.com/v23.0/me/feed';
await utils.facebookApiRequest.call(
mockExecuteFunctions,
'POST',
'',
{ message: 'Hello' },
{},
customUri,
);
expect(mockExecuteFunctions.helpers.request).toHaveBeenCalledWith(
expect.objectContaining({ uri: customUri }),
);
});
});
describe('getFields', () => {
it('should return all fields for a given object with * option first', () => {
const fields = utils.getFields('page');
expect(fields.length).toBeGreaterThan(0);
expect(fields[0]).toEqual({ name: '*', value: '*' });
expect(fields.some((field) => field.name === 'Feed')).toBeTruthy();
});
it('should return only * for unknown objects', () => {
const fields = utils.getFields('unknown-object');
expect(fields).toEqual([{ name: '*', value: '*' }]);
});
it('should format field names in capital case', () => {
const fields = utils.getFields('page');
const findField = (name: string) => fields.find((field) => field.name === name);
expect(findField('Feed')).toBeDefined();
expect(findField('Email')).toBeDefined();
expect(findField('Company Overview')).toBeDefined();
});
});
describe('getAllFields', () => {
it('should return all field values without *', () => {
const allFields = utils.getAllFields('page');
expect(allFields.length).toBeGreaterThan(0);
expect(allFields.includes('*')).toBeFalsy();
expect(allFields.includes('feed')).toBeTruthy();
expect(allFields.includes('email')).toBeTruthy();
});
it('should return empty array for unknown objects', () => {
expect(utils.getAllFields('unknown-object')).toEqual([]);
});
it('should return all raw field values', () => {
const pageFields = utils.getAllFields('page');
const instagramFields = utils.getAllFields('instagram');
expect(pageFields).toContain('feed');
expect(pageFields).toContain('email');
expect(pageFields).toContain('website');
expect(instagramFields).toContain('comments');
expect(instagramFields).toContain('mentions');
});
});
});
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 60 60"><path fill="#1877f2" d="M59.5 30C59.5 13.71 46.29.5 30 .5S.5 13.71.5 30c0 14.72 10.79 26.93 24.89 29.14V38.53H17.9V30h7.49v-6.5c0-7.39 4.4-11.48 11.14-11.48 3.23 0 6.6.58 6.6.58v7.26h-3.72c-3.66 0-4.81 2.27-4.81 4.61V30h8.18l-1.31 8.53H34.6v20.61C48.71 56.93 59.5 44.72 59.5 30"/><path fill="#fff" d="M41.48 38.53 42.79 30h-8.18v-5.53c0-2.33 1.14-4.61 4.81-4.61h3.72V12.6s-3.38-.58-6.6-.58c-6.74 0-11.14 4.08-11.14 11.48V30h-7.5v8.53h7.49v20.61c1.5.24 3.04.36 4.61.36s3.11-.12 4.61-.36V38.53z"/></svg>

After

Width:  |  Height:  |  Size: 561 B

@@ -0,0 +1,29 @@
export interface FacebookEvent {
object: string;
entry: FacebookPageEventEntry[];
}
export interface FacebookPageEventEntry {
id: string;
time: number;
changes: [
{
field: 'leadgen';
value: {
ad_id: string;
form_id: string;
leadgen_id: string;
created_time: number;
page_id: string;
adgroup_id: string;
};
},
];
}
export interface FacebookWebhookSubscription {
object: string;
callback_url: string;
fields: string[];
status: boolean;
}