Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

feat(facebook-leads): ui improvement (#16598)

Talal Jaberf679147d98b9
diff --git a/bun.lock b/bun.lock
index 85b67488f37..6fa489bb5d2 100644
--- a/bun.lock
+++ b/bun.lock
@@ -3084,7 +3084,7 @@
},
"packages/pieces/community/facebook-leads": {
"name": "@activepieces/piece-facebook-leads",
- "version": "0.4.1",
+ "version": "0.5.0",
"dependencies": {
"@activepieces/core-piece-types": "workspace:*",
"@activepieces/core-utils": "workspace:*",
diff --git a/packages/pieces/community/facebook-leads/package.json b/packages/pieces/community/facebook-leads/package.json
index 112ca2a763e..7b5d719e18e 100644
--- a/packages/pieces/community/facebook-leads/package.json
+++ b/packages/pieces/community/facebook-leads/package.json
@@ -1,6 +1,6 @@
{
"name": "@activepieces/piece-facebook-leads",
- "version": "0.4.1",
+ "version": "0.5.0",
"main": "./dist/src/index.js",
"types": "./dist/src/index.d.ts",
"scripts": {
diff --git a/packages/pieces/community/facebook-leads/src/i18n/de.json b/packages/pieces/community/facebook-leads/src/i18n/de.json
index 034f835fc75..ed3c72aace1 100644
--- a/packages/pieces/community/facebook-leads/src/i18n/de.json
+++ b/packages/pieces/community/facebook-leads/src/i18n/de.json
@@ -3,5 +3,10 @@
"New Lead": "Neuer Lead",
"Triggers when a new lead is created.": "Wird ausgelöst, wenn ein neuer Lead erstellt wird.",
"Page": "Seite",
- "Form": "Formular"
+ "Form": "Formular",
+ "Triggers when someone fills in one of your lead ad forms.": "Wird ausgelöst, wenn jemand eines Ihrer Lead-Anzeigenformulare ausfüllt.",
+ "The Facebook Page that runs your lead ads.": "Die Facebook-Seite, die Ihre Lead-Anzeigen schaltet.",
+ "Pick one form, or All Forms for leads from every form on the Page.": "Wählen Sie ein Formular oder „All Forms“ für Leads aus allen Formularen der Seite.",
+ "Runs once for each new lead. Test Trigger loads recent leads from the chosen form, or from the first form on the Page that has any.": "Läuft einmal pro neuem Lead. „Auslöser Testen“ lädt aktuelle Leads aus dem gewählten Formular oder aus dem ersten Formular der Seite, das welche hat.",
+ "Watch": "Überwachen"
}
\ No newline at end of file
diff --git a/packages/pieces/community/facebook-leads/src/i18n/es.json b/packages/pieces/community/facebook-leads/src/i18n/es.json
index 743052df82d..e5dc29bd1c8 100644
--- a/packages/pieces/community/facebook-leads/src/i18n/es.json
+++ b/packages/pieces/community/facebook-leads/src/i18n/es.json
@@ -3,5 +3,10 @@
"New Lead": "Nuevo plomo",
"Triggers when a new lead is created.": "Dispara cuando se crea un nuevo plomo.",
"Page": "Pgina",
- "Form": "Forma"
+ "Form": "Forma",
+ "Triggers when someone fills in one of your lead ad forms.": "Se activa cuando alguien rellena uno de tus formularios de anuncios para clientes potenciales.",
+ "The Facebook Page that runs your lead ads.": "La página de Facebook que publica tus anuncios para clientes potenciales.",
+ "Pick one form, or All Forms for leads from every form on the Page.": "Elige un formulario, o «All Forms» para recibir clientes potenciales de todos los formularios de la página.",
+ "Runs once for each new lead. Test Trigger loads recent leads from the chosen form, or from the first form on the Page that has any.": "Se ejecuta una vez por cada cliente potencial nuevo. «Probar activación» carga clientes potenciales recientes del formulario elegido, o del primer formulario de la página que tenga alguno.",
+ "Watch": "Vigilar"
}
\ No newline at end of file
diff --git a/packages/pieces/community/facebook-leads/src/i18n/fr.json b/packages/pieces/community/facebook-leads/src/i18n/fr.json
index 6707cf35584..8b54f22a953 100644
--- a/packages/pieces/community/facebook-leads/src/i18n/fr.json
+++ b/packages/pieces/community/facebook-leads/src/i18n/fr.json
@@ -3,5 +3,10 @@
"New Lead": "Nouveau prospect",
"Triggers when a new lead is created.": "Déclenche lorsqu'un nouveau prospect est créé.",
"Page": "Page",
- "Form": "Forme"
+ "Form": "Forme",
+ "Triggers when someone fills in one of your lead ad forms.": "Se déclenche lorsque quelqu'un remplit l'un de vos formulaires de publicité à formulaire.",
+ "The Facebook Page that runs your lead ads.": "La page Facebook qui diffuse vos publicités à formulaire.",
+ "Pick one form, or All Forms for leads from every form on the Page.": "Choisissez un formulaire, ou « All Forms » pour les prospects de tous les formulaires de la page.",
+ "Runs once for each new lead. Test Trigger loads recent leads from the chosen form, or from the first form on the Page that has any.": "S'exécute une fois pour chaque nouveau prospect. « Tester le déclencheur » charge les prospects récents du formulaire choisi, ou du premier formulaire de la page qui en a.",
+ "Watch": "Surveiller"
}
\ No newline at end of file
diff --git a/packages/pieces/community/facebook-leads/src/i18n/ja.json b/packages/pieces/community/facebook-leads/src/i18n/ja.json
index b56750cbd81..b206ead96b8 100644
--- a/packages/pieces/community/facebook-leads/src/i18n/ja.json
+++ b/packages/pieces/community/facebook-leads/src/i18n/ja.json
@@ -3,5 +3,10 @@
"New Lead": "新しいリード",
"Triggers when a new lead is created.": "新しいリードが作成されたときにトリガーします。",
"Page": "ページ",
- "Form": "フォーム"
+ "Form": "フォーム",
+ "Triggers when someone fills in one of your lead ad forms.": "リード広告フォームのいずれかに誰かが入力したときにトリガーします。",
+ "The Facebook Page that runs your lead ads.": "リード広告を配信しているFacebookページです。",
+ "Pick one form, or All Forms for leads from every form on the Page.": "フォームを1つ選ぶか、「All Forms」を選ぶとページのすべてのフォームからリードを受け取ります。",
+ "Runs once for each new lead. Test Trigger loads recent leads from the chosen form, or from the first form on the Page that has any.": "新しいリードごとに1回実行されます。「テストトリガー」は選択したフォーム、またはリードがあるページ上の最初のフォームから最近のリードを読み込みます。",
+ "Watch": "監視"
}
\ No newline at end of file
diff --git a/packages/pieces/community/facebook-leads/src/i18n/nl.json b/packages/pieces/community/facebook-leads/src/i18n/nl.json
index b740e21b2da..e2f95000e32 100644
--- a/packages/pieces/community/facebook-leads/src/i18n/nl.json
+++ b/packages/pieces/community/facebook-leads/src/i18n/nl.json
@@ -3,5 +3,10 @@
"New Lead": "Nieuwe Lead",
"Triggers when a new lead is created.": "Triggert wanneer een nieuwe lead wordt gemaakt.",
"Page": "Pagina",
- "Form": "Vorm"
+ "Form": "Vorm",
+ "Triggers when someone fills in one of your lead ad forms.": "Triggert wanneer iemand een van je leadadvertentieformulieren invult.",
+ "The Facebook Page that runs your lead ads.": "De Facebook-pagina die je leadadvertenties weergeeft.",
+ "Pick one form, or All Forms for leads from every form on the Page.": "Kies één formulier, of 'All Forms' voor leads van elk formulier op de pagina.",
+ "Runs once for each new lead. Test Trigger loads recent leads from the chosen form, or from the first form on the Page that has any.": "Wordt één keer uitgevoerd voor elke nieuwe lead. 'Test Trigger' laadt recente leads uit het gekozen formulier, of uit het eerste formulier op de pagina dat er heeft.",
+ "Watch": "Volgen"
}
\ No newline at end of file
diff --git a/packages/pieces/community/facebook-leads/src/i18n/pt.json b/packages/pieces/community/facebook-leads/src/i18n/pt.json
index 9ed3b949c89..cbd300f3d65 100644
--- a/packages/pieces/community/facebook-leads/src/i18n/pt.json
+++ b/packages/pieces/community/facebook-leads/src/i18n/pt.json
@@ -3,5 +3,10 @@
"New Lead": "Novo Potencial",
"Triggers when a new lead is created.": "Dispara quando um novo lead é criado.",
"Page": "Página",
- "Form": "Formulário"
+ "Form": "Formulário",
+ "Triggers when someone fills in one of your lead ad forms.": "Dispara quando alguém preenche um dos seus formulários de anúncios de cadastro.",
+ "The Facebook Page that runs your lead ads.": "A página do Facebook que veicula seus anúncios de cadastro.",
+ "Pick one form, or All Forms for leads from every form on the Page.": "Escolha um formulário, ou \"All Forms\" para leads de todos os formulários da página.",
+ "Runs once for each new lead. Test Trigger loads recent leads from the chosen form, or from the first form on the Page that has any.": "Executa uma vez para cada novo lead. \"Teste de Gatilho\" carrega leads recentes do formulário escolhido, ou do primeiro formulário da página que tiver algum.",
+ "Watch": "Monitorar"
}
\ No newline at end of file
diff --git a/packages/pieces/community/facebook-leads/src/i18n/translation.json b/packages/pieces/community/facebook-leads/src/i18n/translation.json
index 8a3223f2c43..273b0752cc6 100644
--- a/packages/pieces/community/facebook-leads/src/i18n/translation.json
+++ b/packages/pieces/community/facebook-leads/src/i18n/translation.json
@@ -71,7 +71,12 @@
"DELETE": "DELETE",
"HEAD": "HEAD",
"New Lead": "New Lead",
- "Triggers when a new lead is created.": "Triggers when a new lead is created.",
+ "Triggers when someone fills in one of your lead ad forms.": "Triggers when someone fills in one of your lead ad forms.",
"Page": "Page",
- "Form": "Form"
+ "Form": "Form",
+ "Markdown": "Markdown",
+ "The Facebook Page that runs your lead ads.": "The Facebook Page that runs your lead ads.",
+ "Pick one form, or All Forms for leads from every form on the Page.": "Pick one form, or All Forms for leads from every form on the Page.",
+ "Runs once for each new lead. Test Trigger loads recent leads from the chosen form, or from the first form on the Page that has any.": "Runs once for each new lead. Test Trigger loads recent leads from the chosen form, or from the first form on the Page that has any.",
+ "Watch": "Watch"
}
\ No newline at end of file
diff --git a/packages/pieces/community/facebook-leads/src/index.ts b/packages/pieces/community/facebook-leads/src/index.ts
index bb5f0f321ee..e47330602fe 100644
--- a/packages/pieces/community/facebook-leads/src/index.ts
+++ b/packages/pieces/community/facebook-leads/src/index.ts
@@ -22,6 +22,12 @@ export const facebookLeads = createPiece({
auth: facebookLeadsAuth,
baseUrl: () => facebookLeadsClient.baseUrl(),
authMapping: async (auth) => ({ Authorization: `Bearer ${auth.access_token}` }),
+ props: {
+ url: {
+ description: `Full URL, or a path relative to ${facebookLeadsClient.baseUrl()}`,
+ placeholder: '/me/accounts',
+ },
+ },
}),
],
triggers: [newLeadTrigger],
diff --git a/packages/pieces/community/facebook-leads/src/lib/common/props.ts b/packages/pieces/community/facebook-leads/src/lib/common/props.ts
index 7e7c0dffd72..549e215d1a0 100644
--- a/packages/pieces/community/facebook-leads/src/lib/common/props.ts
+++ b/packages/pieces/community/facebook-leads/src/lib/common/props.ts
@@ -14,10 +14,13 @@ function page<R extends boolean>({ required, displayName = 'Page', description }
refreshers: [],
options: async ({ auth }) => {
if (!auth) {
- return disabledOptions({ placeholder: 'Connect your account first.' });
+ return disabledOptions({ placeholder: 'Connect your Facebook account first.' });
}
try {
const pages = await facebookLeadsApi.listPages({ accessToken: auth.access_token });
+ if (pages.length === 0) {
+ return { disabled: false, options: [], placeholder: 'No Pages found for this account.' };
+ }
return {
disabled: false,
options: pages.map((page) => ({
@@ -26,7 +29,7 @@ function page<R extends boolean>({ required, displayName = 'Page', description }
})),
};
} catch (e) {
- return disabledOptions({ placeholder: 'Error occured while fetching pages.' });
+ return disabledOptions({ placeholder: "Couldn't load your Pages. Try reconnecting." });
}
},
});
@@ -41,22 +44,28 @@ function form<R extends boolean>({ required, displayName = 'Form', description }
refreshers: ['page'],
options: async ({ page }) => {
if (!isPageDropdownValue(page)) {
- return disabledOptions({ placeholder: 'Select page first.' });
+ return disabledOptions({ placeholder: 'Select a Page first.' });
}
try {
const forms = await facebookLeadsApi.listLeadForms({
pageId: page.id,
accessToken: page.accessToken,
+ detailed: true,
});
return {
disabled: false,
options: [
- { label: 'All Forms (Default)', value: 'all' },
- ...forms.map((form) => ({ label: form.name, value: form.id })),
+ { label: 'All Forms', value: 'all' },
+ ...forms.map((form) => ({
+ label: formLabel({ name: form.name, status: form.status }),
+ value: form.id,
+ })),
],
};
} catch (e) {
- return disabledOptions({ placeholder: 'Error occured while fetching forms.' });
+ return disabledOptions({
+ placeholder: "Couldn't load forms. Check your access to this Page's lead ads.",
+ });
}
},
});
@@ -73,6 +82,21 @@ function isPageDropdownValue(value: unknown): value is FacebookLeadsPageDropdown
);
}
+function formLabel({ name, status }: { name: string; status: string | undefined }): string {
+ if (!status || status === 'ACTIVE') {
+ return name;
+ }
+ return `${name} (${titleCase({ text: status })})`;
+}
+
+function titleCase({ text }: { text: string }): string {
+ return text
+ .toLowerCase()
+ .split('_')
+ .map((word) => word.charAt(0).toUpperCase() + word.slice(1))
+ .join(' ');
+}
+
function disabledOptions({ placeholder }: { placeholder: string }): DropdownState<never> {
return { disabled: true, options: [], placeholder };
}
diff --git a/packages/pieces/community/facebook-leads/src/lib/triggers/new-lead.ts b/packages/pieces/community/facebook-leads/src/lib/triggers/new-lead.ts
index 97f86dd31b5..43bd9b6d49a 100644
--- a/packages/pieces/community/facebook-leads/src/lib/triggers/new-lead.ts
+++ b/packages/pieces/community/facebook-leads/src/lib/triggers/new-lead.ts
@@ -1,4 +1,4 @@
-import { TriggerStrategy, createTrigger } from '@activepieces/pieces-framework';
+import { MarkdownVariant, Property, TriggerStrategy, createTrigger } from '@activepieces/pieces-framework';
import { facebookLeadsAuth } from '../auth';
import { facebookLeadsApi } from '../common/api';
@@ -6,7 +6,7 @@ import { facebookLeadsProps } from '../common/props';
import { facebookLeadsUtils } from '../common/utils';
import { facebookLeadsGetLeadOutputSchema } from '../output-schemas';
-import type { FacebookLeadsWebhookPayload } from '../common/types';
+import type { FacebookLeadsLead, FacebookLeadsWebhookPayload } from '../common/types';
export const newLeadTrigger = createTrigger({
auth: facebookLeadsAuth,
@@ -14,17 +14,52 @@ export const newLeadTrigger = createTrigger({
outputSchema: facebookLeadsGetLeadOutputSchema,
classification: 'READ',
displayName: 'New Lead',
- description: 'Triggers when a new lead is created.',
+ description: 'Triggers when someone fills in one of your lead ad forms.',
aiMetadata: {
description:
'Fires when a person submits a Facebook/Instagram Lead Ad form on the connected Page. Emits the new lead, including the submitted field answers (such as name, email, and phone) and form/page context. If a specific form is selected, only submissions to that form fire the trigger; otherwise any form on the Page does.',
},
type: TriggerStrategy.APP_WEBHOOK,
- sampleData: {},
+ sampleData: {
+ lead_id: '1234567890123456',
+ form_id: '2345678901234567',
+ platform: 'fb',
+ ad_id: '3456789012345678',
+ ad_name: 'Spring Promo Ad',
+ adset_id: '4567890123456789',
+ adset_name: 'Spring Promo Audience',
+ campaign_id: '5678901234567890',
+ campaign_name: 'Spring Promo Campaign',
+ created_time: '2026-01-15T10:30:00+0000',
+ data: {
+ full_name: 'Jane Doe',
+ email: '[email protected]',
+ phone_number: '+15555550100',
+ },
+ },
props: {
- page: facebookLeadsProps.page({ required: true }),
- form: facebookLeadsProps.form({ required: false }),
+ page: facebookLeadsProps.page({
+ required: true,
+ description: 'The Facebook Page that runs your lead ads.',
+ }),
+ form: facebookLeadsProps.form({
+ required: false,
+ description: 'Pick one form, or All Forms for leads from every form on the Page.',
+ }),
+ info: Property.MarkDown({
+ value: 'Runs once for each new lead. Test Trigger loads recent leads from the chosen form, or from the first form on the Page that has any.',
+ variant: MarkdownVariant.INFO,
+ }),
},
+ propertyGroups: [
+ {
+ key: 'source',
+ display: 'section',
+ label: 'Watch',
+ icon: 'inbox',
+ props: ['page', 'form', 'info'],
+ },
+ ],
async onEnable(context) {
const page = context.propsValue.page;
@@ -40,21 +75,13 @@ export const newLeadTrigger = createTrigger({
return;
},
async test(context) {
- let form = selectedFormId({ form: context.propsValue.form });
+ const form = selectedFormId({ form: context.propsValue.form });
const page = context.propsValue.page;
- if (form === undefined) {
- const forms = await facebookLeadsApi.getPageForms({
- pageId: page.id,
- accessToken: page.accessToken,
- });
-
- form = forms[0].id;
- }
-
- const leads = await facebookLeadsApi.listFormLeads({
- formId: form,
- accessToken: context.auth.access_token,
- });
+ const accessToken = context.auth.access_token;
+ const leads =
+ form !== undefined
+ ? await facebookLeadsApi.listFormLeads({ formId: form, accessToken })
+ : await firstFormLeads({ pageId: page.id, pageAccessToken: page.accessToken, accessToken });
return leads.map((lead) => facebookLeadsUtils.transformLeadData({ lead }));
},
@@ -85,6 +112,30 @@ function isWebhookPayload(body: unknown): body is FacebookLeadsWebhookPayload {
return typeof body === 'object' && body !== null && 'entry' in body && Array.isArray(body.entry);
}
+async function firstFormLeads({
+ pageId,
+ pageAccessToken,
+ accessToken,
+}: {
+ pageId: string;
+ pageAccessToken: string;
+ accessToken: string;
+}): Promise<FacebookLeadsLead[]> {
+ const forms = await facebookLeadsApi.listLeadForms({
+ pageId,
+ accessToken: pageAccessToken,
+ detailed: true,
+ });
+ const formsWithLeads = forms.filter((form) => form.leads_count === undefined || form.leads_count > 0);
+ for (const form of formsWithLeads) {
+ const leads = await facebookLeadsApi.listFormLeads({ formId: form.id, accessToken });
+ if (leads.length > 0) {
+ return leads;
+ }
+ }
+ return [];
+}
+
function selectedFormId({ form }: { form: string | undefined }): string | undefined {
if (form === undefined || form === null || form === '' || form === ALL_FORMS) {
return undefined;