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
TypeScript ai-agentai-agent-toolsai-agentsai-agents-frameworkmcpmcp-servermcp-toolsmcpsn8n-alternativeno-code-automationworkflowworkflow-automationworkflows
feat(facebook-pages): add agent actions and move to Graph v23.0 (#15728)
Kishan Parmar0229cec35c43
diff --git a/packages/pieces/community/facebook-pages/package.json b/packages/pieces/community/facebook-pages/package.jsonindex e5f02644c08..a8ff5b7b524 100644--- a/packages/pieces/community/facebook-pages/package.json+++ b/packages/pieces/community/facebook-pages/package.json@@ -1,6 +1,6 @@{"name": "@activepieces/piece-facebook-pages",- "version": "0.2.8",+ "version": "0.3.0","main": "./dist/src/index.js","types": "./dist/src/index.d.ts","scripts": {diff --git a/packages/pieces/community/facebook-pages/src/index.ts b/packages/pieces/community/facebook-pages/src/index.tsindex 68f415972a4..206d5e28446 100644--- a/packages/pieces/community/facebook-pages/src/index.ts+++ b/packages/pieces/community/facebook-pages/src/index.ts@@ -1,47 +1,55 @@-import { PieceAuth, createPiece } from '@activepieces/pieces-framework';--import { PieceCategory } from '@activepieces/pieces-framework';+import { createPiece, PieceCategory } from '@activepieces/pieces-framework';+import { facebookPagesAuth } from './lib/auth';import { createPhotoPost } from './lib/actions/create-photo-post';import { createPost } from './lib/actions/create-post';import { createVideoPost } from './lib/actions/create-video-post';--const markdown = `-To Obtain a Client ID and Client Secret:--1. Go to https://developers.facebook.com/-2. Register for a Facebook Developer account.-3. Once login, click "Make a new app" button.-4. Select "Other" for use cases.-5. Choose "Business" as the type of app.-6. Provide application details: custom name and associated email.-7. Once your application is created, you need to add a new "product".-8. Configure a new product of type "Facebook Login Settings".-9. Default settings should be fine, you only need to provide the Redirect URL in "Valid OAuth Redirect URIs" and your domain name in "Allowed Domains for the JavaScript SDK".-10. Finally, get your application ID and application secret from your app dashboard in Settings > Basic.-`;--export const facebookPagesAuth = PieceAuth.OAuth2({- description: markdown,- authUrl: 'https://graph.facebook.com/oauth/authorize',- tokenUrl: 'https://graph.facebook.com/oauth/access_token',- required: true,- scope: [- 'pages_show_list',- 'pages_manage_posts',- 'business_management',- 'pages_read_engagement',- ],-});+import { listManagedPagesAction } from './lib/actions/ai/list-managed-pages';+import { getPageDetailsAction } from './lib/actions/ai/get-page-details';+import { createPagePostAction } from './lib/actions/ai/create-page-post';+import { createPagePhotoPostAction } from './lib/actions/ai/create-page-photo-post';+import { createPageVideoPostAction } from './lib/actions/ai/create-page-video-post';+import { createMultiPhotoPostAction } from './lib/actions/ai/create-multi-photo-post';+import { getPagePostsAction } from './lib/actions/ai/get-page-posts';+import { getPostAction } from './lib/actions/ai/get-post';+import { updatePostAction } from './lib/actions/ai/update-post';+import { deletePostAction } from './lib/actions/ai/delete-post';+import { getScheduledPostsAction } from './lib/actions/ai/get-scheduled-posts';+import { publishScheduledPostAction } from './lib/actions/ai/publish-scheduled-post';+import { reschedulePostAction } from './lib/actions/ai/reschedule-post';+import { getPagePhotosAction } from './lib/actions/ai/get-page-photos';+import { getPageVideosAction } from './lib/actions/ai/get-page-videos';+import { getPostReactionsAction } from './lib/actions/ai/get-post-reactions';export const facebookPages = createPiece({displayName: 'Facebook Pages',description: 'Manage your Facebook pages to grow your business',-- minimumSupportedRelease: '0.30.0',+ minimumSupportedRelease: '0.87.0',logoUrl: 'https://cdn.activepieces.com/pieces/facebook.png',categories: [PieceCategory.MARKETING],authors: ["kishanprmr","MoShizzle","khaledmashaly","abuaboud"],auth: facebookPagesAuth,- actions: [createPost, createPhotoPost, createVideoPost],+ actions: [+ createPost,+ createPhotoPost,+ createVideoPost,+ listManagedPagesAction,+ getPageDetailsAction,+ createPagePostAction,+ createPagePhotoPostAction,+ createPageVideoPostAction,+ createMultiPhotoPostAction,+ getPagePostsAction,+ getPostAction,+ updatePostAction,+ deletePostAction,+ getScheduledPostsAction,+ publishScheduledPostAction,+ reschedulePostAction,+ getPagePhotosAction,+ getPageVideosAction,+ getPostReactionsAction,+ ],triggers: [],});++export { facebookPagesAuth };diff --git a/packages/pieces/community/facebook-pages/src/lib/actions/ai/create-multi-photo-post.ts b/packages/pieces/community/facebook-pages/src/lib/actions/ai/create-multi-photo-post.tsnew file mode 100644index 00000000000..b3db7285ced--- /dev/null+++ b/packages/pieces/community/facebook-pages/src/lib/actions/ai/create-multi-photo-post.ts@@ -0,0 +1,65 @@+import { createAction, Property } from '@activepieces/pieces-framework';+import { HttpMethod } from '@activepieces/pieces-common';+import { facebookPagesAuth } from '../../auth';+import { facebookPagesCommon } from '../../common/common';+import { createMultiPhotoPostOutputSchema } from '../../output-schemas';++export const createMultiPhotoPostAction = createAction({+ auth: facebookPagesAuth,+ name: 'create_multi_photo_post',+ classification: 'WRITE',+ displayName: 'Create Multi-Photo Post',+ description: 'Publishes one Facebook Page post containing several photos.',+ audience: 'ai',+ aiMetadata: {+ description:+ 'Publish one feed post on a Facebook Page that contains 2 to 20 photos from public image URLs, with an optional message. Uploads each photo unpublished, then creates the post with them attached; if an upload fails no post is created, though earlier unpublished uploads can remain. Use Create Page Photo Post for a single photo. Not idempotent.',+ idempotent: false,+ },+ outputSchema: createMultiPhotoPostOutputSchema,+ props: {+ pageId: facebookPagesCommon.pageId,+ photoUrls: Property.Array({+ displayName: 'Photo URLs',+ description: 'Public image URLs that Facebook can download, 2 to 20 of them, in display order.',+ required: true,+ }),+ message: Property.LongText({+ displayName: 'Message',+ description: 'Text of the post.',+ required: false,+ }),+ },+ async run({ auth, propsValue }) {+ const photoUrls = (propsValue.photoUrls ?? [])+ .filter((url): url is string => typeof url === 'string' && url.trim().length > 0)+ .map((url) => url.trim());+ if (photoUrls.length < 2 || photoUrls.length > MAX_PHOTOS) {+ throw new Error(`Provide between 2 and ${MAX_PHOTOS} photo URLs.`);+ }+ const accessToken = await facebookPagesCommon.getPageAccessToken({ auth, pageId: propsValue.pageId });+ const pagePath = facebookPagesCommon.objectPath({ id: propsValue.pageId });+ const photos = await Promise.all(+ photoUrls.map((url) =>+ facebookPagesCommon.graphRequest<{ id: string }>({+ accessToken,+ method: HttpMethod.POST,+ path: `${pagePath}/photos`,+ body: { url, published: false },+ })+ )+ );+ const post = await facebookPagesCommon.graphRequest<{ id: string }>({+ accessToken,+ method: HttpMethod.POST,+ path: `${pagePath}/feed`,+ body: {+ message: propsValue.message,+ attached_media: photos.map((photo) => ({ media_fbid: photo.id })),+ },+ });+ return { post_id: post.id, photo_ids: photos.map((photo) => photo.id) };+ },+});++const MAX_PHOTOS = 20;diff --git a/packages/pieces/community/facebook-pages/src/lib/actions/ai/create-page-photo-post.ts b/packages/pieces/community/facebook-pages/src/lib/actions/ai/create-page-photo-post.tsnew file mode 100644index 00000000000..8aefdb055d7--- /dev/null+++ b/packages/pieces/community/facebook-pages/src/lib/actions/ai/create-page-photo-post.ts@@ -0,0 +1,42 @@+import { createAction, Property } from '@activepieces/pieces-framework';+import { HttpMethod } from '@activepieces/pieces-common';+import { facebookPagesAuth } from '../../auth';+import { facebookPagesCommon, GraphRecord } from '../../common/common';+import { createPagePhotoPostOutputSchema } from '../../output-schemas';++export const createPagePhotoPostAction = createAction({+ auth: facebookPagesAuth,+ name: 'create_page_photo_post',+ classification: 'WRITE',+ displayName: 'Create Page Photo Post',+ description: 'Publishes a photo post on a Facebook Page from an image URL.',+ audience: 'ai',+ aiMetadata: {+ description:+ 'Publish a single photo to a Facebook Page from a publicly reachable image URL, with an optional caption. Returns both the photo ID and the post_id (PageID_PostID); use post_id for Get Post, Update Post and Delete Post. Use Create Multi-Photo Post for several images in one post. Not idempotent: each call creates a new post.',+ idempotent: false,+ },+ outputSchema: createPagePhotoPostOutputSchema,+ props: {+ pageId: facebookPagesCommon.pageId,+ photoUrl: Property.ShortText({+ displayName: 'Photo URL',+ description: 'A public URL of the image that Facebook can download (JPEG, PNG, GIF, BMP or TIFF, up to 4 MB).',+ required: true,+ }),+ caption: Property.LongText({+ displayName: 'Caption',+ description: 'Text shown with the photo.',+ required: false,+ }),+ },+ async run({ auth, propsValue }) {+ return facebookPagesCommon.pageRequest<GraphRecord>({+ auth,+ pageId: propsValue.pageId,+ method: HttpMethod.POST,+ path: `${facebookPagesCommon.objectPath({ id: propsValue.pageId })}/photos`,+ body: { url: propsValue.photoUrl.trim(), caption: propsValue.caption },+ });+ },+});diff --git a/packages/pieces/community/facebook-pages/src/lib/actions/ai/create-page-post.ts b/packages/pieces/community/facebook-pages/src/lib/actions/ai/create-page-post.tsnew file mode 100644index 00000000000..bd57546fba0--- /dev/null+++ b/packages/pieces/community/facebook-pages/src/lib/actions/ai/create-page-post.ts@@ -0,0 +1,54 @@+import { createAction, Property } from '@activepieces/pieces-framework';+import { HttpMethod } from '@activepieces/pieces-common';+import { facebookPagesAuth } from '../../auth';+import { facebookPagesCommon, GraphRecord } from '../../common/common';+import { createPagePostOutputSchema } from '../../output-schemas';++export const createPagePostAction = createAction({+ auth: facebookPagesAuth,+ name: 'create_page_post',+ classification: 'WRITE',+ displayName: 'Create Page Post',+ description: 'Publishes or schedules a text or link post on a Facebook Page.',+ audience: 'ai',+ aiMetadata: {+ description:+ 'Publish a text or link post to the feed of a Facebook Page, now or at a scheduled time at least 10 minutes ahead. Returns the post ID in PageID_PostID format for Get Post, Update Post and Delete Post. Use Create Page Photo Post, Create Page Video Post or Create Multi-Photo Post for media. Not idempotent: each call creates a new post.',+ idempotent: false,+ },+ outputSchema: createPagePostOutputSchema,+ props: {+ pageId: facebookPagesCommon.pageId,+ message: Property.LongText({+ displayName: 'Message',+ description: 'The text of the post. Required unless a link is given.',+ required: false,+ }),+ link: Property.ShortText({+ displayName: 'Link',+ description: 'A URL to attach; Facebook renders it as a preview card.',+ required: false,+ }),+ scheduledPublishTime: Property.DateTime({+ displayName: 'Scheduled Publish Time',+ description: 'ISO 8601 date and time to publish the post, at least 10 minutes from now. Leave empty to publish immediately.',+ required: false,+ }),+ },+ async run({ auth, propsValue }) {+ const { message, link, scheduledPublishTime } = propsValue;+ if (!facebookPagesCommon.isProvided(message) && !facebookPagesCommon.isProvided(link)) {+ throw new Error('Provide a message, a link, or both.');+ }+ const schedule = facebookPagesCommon.isProvided(scheduledPublishTime)+ ? { published: false, scheduled_publish_time: facebookPagesCommon.toScheduledUnixTime({ value: scheduledPublishTime }) }+ : {};+ return facebookPagesCommon.pageRequest<GraphRecord>({+ auth,+ pageId: propsValue.pageId,+ method: HttpMethod.POST,+ path: `${facebookPagesCommon.objectPath({ id: propsValue.pageId })}/feed`,+ body: { message, link, ...schedule },+ });+ },+});diff --git a/packages/pieces/community/facebook-pages/src/lib/actions/ai/create-page-video-post.ts b/packages/pieces/community/facebook-pages/src/lib/actions/ai/create-page-video-post.tsnew file mode 100644index 00000000000..25e10059a3d--- /dev/null+++ b/packages/pieces/community/facebook-pages/src/lib/actions/ai/create-page-video-post.ts@@ -0,0 +1,46 @@+import { createAction, Property } from '@activepieces/pieces-framework';+import { HttpMethod } from '@activepieces/pieces-common';+import { facebookPagesAuth } from '../../auth';+import { facebookPagesCommon, GraphRecord } from '../../common/common';+import { createPageVideoPostOutputSchema } from '../../output-schemas';++export const createPageVideoPostAction = createAction({+ auth: facebookPagesAuth,+ name: 'create_page_video_post',+ classification: 'WRITE',+ displayName: 'Create Page Video Post',+ description: 'Publishes a video on a Facebook Page from a video URL.',+ audience: 'ai',+ aiMetadata: {+ description:+ 'Publish a video to a Facebook Page from a publicly reachable video URL (up to 1 GB or 20 minutes), with an optional title and description. Facebook processes the video after the call returns. Returns the video ID only, which is not a post ID; find the resulting post with Get Page Posts. Not idempotent: each call uploads a new video.',+ idempotent: false,+ },+ outputSchema: createPageVideoPostOutputSchema,+ props: {+ pageId: facebookPagesCommon.pageId,+ videoUrl: Property.ShortText({+ displayName: 'Video URL',+ description: 'A public URL of the video file that Facebook can download.',+ required: true,+ }),+ title: Property.ShortText({+ displayName: 'Title',+ required: false,+ }),+ description: Property.LongText({+ displayName: 'Description',+ description: 'Text shown with the video.',+ required: false,+ }),+ },+ async run({ auth, propsValue }) {+ return facebookPagesCommon.pageRequest<GraphRecord>({+ auth,+ pageId: propsValue.pageId,+ method: HttpMethod.POST,+ path: `${facebookPagesCommon.objectPath({ id: propsValue.pageId })}/videos`,+ body: { file_url: propsValue.videoUrl.trim(), title: propsValue.title, description: propsValue.description },+ });+ },+});diff --git a/packages/pieces/community/facebook-pages/src/lib/actions/ai/delete-post.ts b/packages/pieces/community/facebook-pages/src/lib/actions/ai/delete-post.tsnew file mode 100644index 00000000000..678028e787e--- /dev/null+++ b/packages/pieces/community/facebook-pages/src/lib/actions/ai/delete-post.ts@@ -0,0 +1,33 @@+import { createAction } from '@activepieces/pieces-framework';+import { HttpMethod } from '@activepieces/pieces-common';+import { facebookPagesAuth } from '../../auth';+import { facebookPagesCommon } from '../../common/common';+import { postResultOutputSchema } from '../../output-schemas';++export const deletePostAction = createAction({+ auth: facebookPagesAuth,+ name: 'delete_post',+ classification: 'DESTRUCTIVE',+ displayName: 'Delete Post',+ description: 'Permanently deletes a Facebook Page post.',+ audience: 'ai',+ aiMetadata: {+ description:+ 'Permanently delete one Facebook Page post by its PageID_PostID, including a scheduled post. This cannot be undone; confirm with the user first.',+ idempotent: false,+ },+ outputSchema: postResultOutputSchema,+ props: {+ pageId: facebookPagesCommon.pageId,+ postId: facebookPagesCommon.postId,+ },+ async run({ auth, propsValue }) {+ const response = await facebookPagesCommon.pageRequest<{ success: boolean }>({+ auth,+ pageId: propsValue.pageId,+ method: HttpMethod.DELETE,+ path: facebookPagesCommon.objectPath({ id: propsValue.postId }),+ });+ return { success: response.success, post_id: propsValue.postId.trim() };+ },+});diff --git a/packages/pieces/community/facebook-pages/src/lib/actions/ai/get-page-details.ts b/packages/pieces/community/facebook-pages/src/lib/actions/ai/get-page-details.tsnew file mode 100644index 00000000000..48712b7d7de--- /dev/null+++ b/packages/pieces/community/facebook-pages/src/lib/actions/ai/get-page-details.ts@@ -0,0 +1,36 @@+import { createAction } from '@activepieces/pieces-framework';+import { HttpMethod } from '@activepieces/pieces-common';+import { facebookPagesAuth } from '../../auth';+import { facebookPagesCommon, GraphRecord } from '../../common/common';+import { pageDetailsOutputSchema } from '../../output-schemas';++const PAGE_FIELDS =+ 'id,name,username,category,about,description,link,website,phone,emails,single_line_address,followers_count,verification_status,is_published,picture{url},cover{source}';++export const getPageDetailsAction = createAction({+ auth: facebookPagesAuth,+ name: 'get_page_details',+ classification: 'READ',+ displayName: 'Get Page Details',+ description: 'Gets the profile details of a Facebook Page.',+ audience: 'ai',+ aiMetadata: {+ description:+ 'Get the public profile of one Facebook Page the connected account manages: name, username, category, about, description, website, phone, emails, address, follower count, verification status, profile picture and cover photo. Use Fields to request other Graph API Page fields. Read-only.',+ idempotent: true,+ },+ outputSchema: pageDetailsOutputSchema,+ props: {+ pageId: facebookPagesCommon.pageId,+ fields: facebookPagesCommon.fields({ defaultFields: PAGE_FIELDS }),+ },+ async run({ auth, propsValue }) {+ return facebookPagesCommon.pageRequest<GraphRecord>({+ auth,+ pageId: propsValue.pageId,+ method: HttpMethod.GET,+ path: facebookPagesCommon.objectPath({ id: propsValue.pageId }),+ queryParams: { fields: facebookPagesCommon.fieldsQuery({ fields: propsValue.fields, defaultFields: PAGE_FIELDS }) },+ });+ },+});diff --git a/packages/pieces/community/facebook-pages/src/lib/actions/ai/get-page-photos.ts b/packages/pieces/community/facebook-pages/src/lib/actions/ai/get-page-photos.tsnew file mode 100644index 00000000000..99c45b543fd--- /dev/null+++ b/packages/pieces/community/facebook-pages/src/lib/actions/ai/get-page-photos.ts@@ -0,0 +1,39 @@+import { createAction } from '@activepieces/pieces-framework';+import { HttpMethod } from '@activepieces/pieces-common';+import { facebookPagesAuth } from '../../auth';+import { facebookPagesCommon, GraphList, GraphRecord } from '../../common/common';+import { pagePhotosOutputSchema } from '../../output-schemas';++export const getPagePhotosAction = createAction({+ auth: facebookPagesAuth,+ name: 'get_page_photos',+ classification: 'SEARCH',+ displayName: 'Get Page Photos',+ description: 'Lists the photos uploaded by a Facebook Page.',+ audience: 'ai',+ aiMetadata: {+ description:+ 'List the photos a Facebook Page has uploaded, newest first, with each photo ID, caption, created time, link, album and image sizes. Image URLs are temporary CDN links that expire. A photo ID is not a post ID. Paginated with After Cursor. Read-only.',+ idempotent: true,+ },+ outputSchema: pagePhotosOutputSchema,+ props: {+ pageId: facebookPagesCommon.pageId,+ limit: facebookPagesCommon.limit,+ after: facebookPagesCommon.after,+ },+ async run({ auth, propsValue }) {+ const response = await facebookPagesCommon.pageRequest<GraphList<GraphRecord>>({+ auth,+ pageId: propsValue.pageId,+ method: HttpMethod.GET,+ path: `${facebookPagesCommon.objectPath({ id: propsValue.pageId })}/photos`,+ queryParams: {+ type: 'uploaded',+ fields: 'id,name,created_time,updated_time,link,width,height,images,album{id,name}',+ ...facebookPagesCommon.cursorQuery({ limit: propsValue.limit, after: propsValue.after }),+ },+ });+ return facebookPagesCommon.toCursorPage({ response });+ },+});diff --git a/packages/pieces/community/facebook-pages/src/lib/actions/ai/get-page-posts.ts b/packages/pieces/community/facebook-pages/src/lib/actions/ai/get-page-posts.tsnew file mode 100644index 00000000000..09252b6b682--- /dev/null+++ b/packages/pieces/community/facebook-pages/src/lib/actions/ai/get-page-posts.ts@@ -0,0 +1,38 @@+import { createAction } from '@activepieces/pieces-framework';+import { HttpMethod } from '@activepieces/pieces-common';+import { facebookPagesAuth } from '../../auth';+import { facebookPagesCommon, GraphList, GraphRecord } from '../../common/common';+import { pagePostsOutputSchema } from '../../output-schemas';++export const getPagePostsAction = createAction({+ auth: facebookPagesAuth,+ name: 'get_page_posts',+ classification: 'SEARCH',+ displayName: 'Get Page Posts',+ description: 'Lists the posts published by a Facebook Page.',+ audience: 'ai',+ aiMetadata: {+ description:+ 'List the posts a Facebook Page has published, newest first, with each post ID (PageID_PostID), message, created and updated time, permalink and main picture. Does not include scheduled posts (use Get Scheduled Posts) or posts by other people that tag the Page. Paginated with After Cursor. Read-only.',+ idempotent: true,+ },+ outputSchema: pagePostsOutputSchema,+ props: {+ pageId: facebookPagesCommon.pageId,+ limit: facebookPagesCommon.limit,+ after: facebookPagesCommon.after,+ },+ async run({ auth, propsValue }) {+ const response = await facebookPagesCommon.pageRequest<GraphList<GraphRecord>>({+ auth,+ pageId: propsValue.pageId,+ method: HttpMethod.GET,+ path: `${facebookPagesCommon.objectPath({ id: propsValue.pageId })}/posts`,+ queryParams: {+ fields: 'id,message,created_time,updated_time,permalink_url,status_type,full_picture,is_published',+ ...facebookPagesCommon.cursorQuery({ limit: propsValue.limit, after: propsValue.after }),+ },+ });+ return facebookPagesCommon.toCursorPage({ response });+ },+});diff --git a/packages/pieces/community/facebook-pages/src/lib/actions/ai/get-page-videos.ts b/packages/pieces/community/facebook-pages/src/lib/actions/ai/get-page-videos.tsnew file mode 100644index 00000000000..2c0c88c1a17--- /dev/null+++ b/packages/pieces/community/facebook-pages/src/lib/actions/ai/get-page-videos.ts@@ -0,0 +1,38 @@+import { createAction } from '@activepieces/pieces-framework';+import { HttpMethod } from '@activepieces/pieces-common';+import { facebookPagesAuth } from '../../auth';+import { facebookPagesCommon, GraphList, GraphRecord } from '../../common/common';+import { pageVideosOutputSchema } from '../../output-schemas';++export const getPageVideosAction = createAction({+ auth: facebookPagesAuth,+ name: 'get_page_videos',+ classification: 'SEARCH',+ displayName: 'Get Page Videos',+ description: 'Lists the videos uploaded by a Facebook Page.',+ audience: 'ai',+ aiMetadata: {+ description:+ 'List the videos a Facebook Page has uploaded, newest first, with each video ID, title, description, created time, length in seconds, permalink and thumbnail. A video ID is not a post ID. Paginated with After Cursor. Read-only.',+ idempotent: true,+ },+ outputSchema: pageVideosOutputSchema,+ props: {+ pageId: facebookPagesCommon.pageId,+ limit: facebookPagesCommon.limit,+ after: facebookPagesCommon.after,+ },+ async run({ auth, propsValue }) {+ const response = await facebookPagesCommon.pageRequest<GraphList<GraphRecord>>({+ auth,+ pageId: propsValue.pageId,+ method: HttpMethod.GET,+ path: `${facebookPagesCommon.objectPath({ id: propsValue.pageId })}/videos`,+ queryParams: {+ fields: 'id,title,description,created_time,updated_time,length,permalink_url,picture',+ ...facebookPagesCommon.cursorQuery({ limit: propsValue.limit, after: propsValue.after }),+ },+ });+ return facebookPagesCommon.toCursorPage({ response });+ },+});diff --git a/packages/pieces/community/facebook-pages/src/lib/actions/ai/get-post-reactions.ts b/packages/pieces/community/facebook-pages/src/lib/actions/ai/get-post-reactions.tsnew file mode 100644index 00000000000..627886a0a38--- /dev/null+++ b/packages/pieces/community/facebook-pages/src/lib/actions/ai/get-post-reactions.ts@@ -0,0 +1,52 @@+import { createAction, Property } from '@activepieces/pieces-framework';+import { HttpMethod } from '@activepieces/pieces-common';+import { facebookPagesAuth } from '../../auth';+import { facebookPagesCommon } from '../../common/common';+import { postReactionsOutputSchema } from '../../output-schemas';++const REACTION_TYPES = ['LIKE', 'LOVE', 'CARE', 'HAHA', 'WOW', 'SAD', 'ANGRY'];++export const getPostReactionsAction = createAction({+ auth: facebookPagesAuth,+ name: 'get_post_reactions',+ classification: 'READ',+ displayName: 'Get Post Reactions',+ description: 'Counts the reactions on a Facebook Page post.',+ audience: 'ai',+ aiMetadata: {+ description:+ 'Count the reactions on a Facebook Page post, either all reactions or only one type such as LOVE or HAHA. Returns the total count only, not the people who reacted. Very new posts can report partial counts. Read-only.',+ idempotent: true,+ },+ outputSchema: postReactionsOutputSchema,+ props: {+ pageId: facebookPagesCommon.pageId,+ objectId: Property.ShortText({+ displayName: 'Post ID',+ description: 'A post ID in PageID_PostID format.',+ required: true,+ }),+ type: Property.StaticDropdown({+ displayName: 'Reaction Type',+ description: 'Only count this reaction type. Leave empty to count all reactions.',+ required: false,+ options: {+ options: REACTION_TYPES.map((type) => ({ label: type, value: type })),+ },+ }),+ },+ async run({ auth, propsValue }) {+ const response = await facebookPagesCommon.pageRequest<{ summary?: { total_count?: number } }>({+ auth,+ pageId: propsValue.pageId,+ method: HttpMethod.GET,+ path: `${facebookPagesCommon.objectPath({ id: propsValue.objectId })}/reactions`,+ queryParams: { summary: 'total_count', limit: '0', type: propsValue.type },+ });+ return {+ object_id: propsValue.objectId.trim(),+ type: propsValue.type ?? 'ALL',+ total_count: response.summary?.total_count ?? 0,+ };+ },+});diff --git a/packages/pieces/community/facebook-pages/src/lib/actions/ai/get-post.ts b/packages/pieces/community/facebook-pages/src/lib/actions/ai/get-post.tsnew file mode 100644index 00000000000..aca87ab6d18--- /dev/null+++ b/packages/pieces/community/facebook-pages/src/lib/actions/ai/get-post.ts@@ -0,0 +1,37 @@+import { createAction } from '@activepieces/pieces-framework';+import { HttpMethod } from '@activepieces/pieces-common';+import { facebookPagesAuth } from '../../auth';+import { facebookPagesCommon, GraphRecord } from '../../common/common';+import { postOutputSchema } from '../../output-schemas';++const POST_FIELDS =+ 'id,message,created_time,updated_time,permalink_url,status_type,full_picture,is_published,scheduled_publish_time,attachments{media_type,type,title,description,url,media}';++export const getPostAction = createAction({+ auth: facebookPagesAuth,+ name: 'get_post',+ classification: 'READ',+ displayName: 'Get Post',+ description: 'Gets one post from a Facebook Page.',+ audience: 'ai',+ aiMetadata: {+ description:+ 'Get one Facebook Page post by its PageID_PostID: message, created and updated time, permalink, main picture, publish status, scheduled time and attachments. Use Get Post Reactions for reaction counts. Use Fields to request other Graph API post fields. Read-only.',+ idempotent: true,+ },+ outputSchema: postOutputSchema,+ props: {+ pageId: facebookPagesCommon.pageId,+ postId: facebookPagesCommon.postId,+ fields: facebookPagesCommon.fields({ defaultFields: POST_FIELDS }),+ },+ async run({ auth, propsValue }) {+ return facebookPagesCommon.pageRequest<GraphRecord>({+ auth,+ pageId: propsValue.pageId,+ method: HttpMethod.GET,+ path: facebookPagesCommon.objectPath({ id: propsValue.postId }),+ queryParams: { fields: facebookPagesCommon.fieldsQuery({ fields: propsValue.fields, defaultFields: POST_FIELDS }) },+ });+ },+});diff --git a/packages/pieces/community/facebook-pages/src/lib/actions/ai/get-scheduled-posts.ts b/packages/pieces/community/facebook-pages/src/lib/actions/ai/get-scheduled-posts.tsnew file mode 100644index 00000000000..db52253a122--- /dev/null+++ b/packages/pieces/community/facebook-pages/src/lib/actions/ai/get-scheduled-posts.ts@@ -0,0 +1,38 @@+import { createAction } from '@activepieces/pieces-framework';+import { HttpMethod } from '@activepieces/pieces-common';+import { facebookPagesAuth } from '../../auth';+import { facebookPagesCommon, GraphList, GraphRecord } from '../../common/common';+import { scheduledPostsOutputSchema } from '../../output-schemas';++export const getScheduledPostsAction = createAction({+ auth: facebookPagesAuth,+ name: 'get_scheduled_posts',+ classification: 'SEARCH',+ displayName: 'Get Scheduled Posts',+ description: 'Lists the scheduled, not yet published posts of a Facebook Page.',+ audience: 'ai',+ aiMetadata: {+ description:+ 'List the posts on a Facebook Page that are scheduled but not yet published, with each post ID, message, created time and scheduled publish time. Use the IDs with Publish Scheduled Post, Reschedule Post or Delete Post. Paginated with After Cursor. Read-only.',+ idempotent: true,+ },+ outputSchema: scheduledPostsOutputSchema,+ props: {+ pageId: facebookPagesCommon.pageId,+ limit: facebookPagesCommon.limit,+ after: facebookPagesCommon.after,+ },+ async run({ auth, propsValue }) {+ const response = await facebookPagesCommon.pageRequest<GraphList<GraphRecord>>({+ auth,+ pageId: propsValue.pageId,+ method: HttpMethod.GET,+ path: `${facebookPagesCommon.objectPath({ id: propsValue.pageId })}/scheduled_posts`,+ queryParams: {+ fields: 'id,message,created_time,scheduled_publish_time,permalink_url,is_published,full_picture',+ ...facebookPagesCommon.cursorQuery({ limit: propsValue.limit, after: propsValue.after }),+ },+ });+ return facebookPagesCommon.toCursorPage({ response });+ },+});diff --git a/packages/pieces/community/facebook-pages/src/lib/actions/ai/list-managed-pages.ts b/packages/pieces/community/facebook-pages/src/lib/actions/ai/list-managed-pages.tsnew file mode 100644index 00000000000..02f5da04bc3--- /dev/null+++ b/packages/pieces/community/facebook-pages/src/lib/actions/ai/list-managed-pages.ts@@ -0,0 +1,36 @@+import { createAction } from '@activepieces/pieces-framework';+import { HttpMethod } from '@activepieces/pieces-common';+import { facebookPagesAuth } from '../../auth';+import { facebookPagesCommon, GraphList, GraphRecord } from '../../common/common';+import { listManagedPagesOutputSchema } from '../../output-schemas';++export const listManagedPagesAction = createAction({+ auth: facebookPagesAuth,+ name: 'list_managed_pages',+ classification: 'SEARCH',+ displayName: 'List Managed Pages',+ description: 'Lists the Facebook Pages the connected account manages.',+ audience: 'ai',+ aiMetadata: {+ description:+ 'List the Facebook Pages the connected account has a role on, with each Page ID, name, category, username, link and the tasks the account can perform on it. The starting point for every other Facebook Pages action, which all need a Page ID. Paginated with After Cursor. Read-only.',+ idempotent: true,+ },+ outputSchema: listManagedPagesOutputSchema,+ props: {+ limit: facebookPagesCommon.limit,+ after: facebookPagesCommon.after,+ },+ async run({ auth, propsValue }) {+ const response = await facebookPagesCommon.graphRequest<GraphList<GraphRecord>>({+ accessToken: auth.access_token,+ method: HttpMethod.GET,+ path: 'me/accounts',+ queryParams: {+ fields: 'id,name,category,username,link,tasks',+ ...facebookPagesCommon.cursorQuery({ limit: propsValue.limit, after: propsValue.after }),+ },+ });+ return facebookPagesCommon.toCursorPage({ response });+ },+});diff --git a/packages/pieces/community/facebook-pages/src/lib/actions/ai/publish-scheduled-post.ts b/packages/pieces/community/facebook-pages/src/lib/actions/ai/publish-scheduled-post.tsnew file mode 100644index 00000000000..8a1b269f0ff--- /dev/null+++ b/packages/pieces/community/facebook-pages/src/lib/actions/ai/publish-scheduled-post.ts@@ -0,0 +1,34 @@+import { createAction } from '@activepieces/pieces-framework';+import { HttpMethod } from '@activepieces/pieces-common';+import { facebookPagesAuth } from '../../auth';+import { facebookPagesCommon } from '../../common/common';+import { postResultOutputSchema } from '../../output-schemas';++export const publishScheduledPostAction = createAction({+ auth: facebookPagesAuth,+ name: 'publish_scheduled_post',+ classification: 'WRITE',+ displayName: 'Publish Scheduled Post',+ description: 'Publishes a scheduled Facebook Page post immediately.',+ audience: 'ai',+ aiMetadata: {+ description:+ 'Publish a scheduled or unpublished Facebook Page post right away instead of waiting for its scheduled time. Find scheduled posts with Get Scheduled Posts. Facebook only allows this on posts created through this same app.',+ idempotent: true,+ },+ outputSchema: postResultOutputSchema,+ props: {+ pageId: facebookPagesCommon.pageId,+ postId: facebookPagesCommon.postId,+ },+ async run({ auth, propsValue }) {+ const response = await facebookPagesCommon.pageRequest<{ success: boolean }>({+ auth,+ pageId: propsValue.pageId,+ method: HttpMethod.POST,+ path: facebookPagesCommon.objectPath({ id: propsValue.postId }),+ body: { is_published: true },+ });+ return { success: response.success, post_id: propsValue.postId.trim() };+ },+});diff --git a/packages/pieces/community/facebook-pages/src/lib/actions/ai/reschedule-post.ts b/packages/pieces/community/facebook-pages/src/lib/actions/ai/reschedule-post.tsnew file mode 100644index 00000000000..31b06bfaf75--- /dev/null+++ b/packages/pieces/community/facebook-pages/src/lib/actions/ai/reschedule-post.ts@@ -0,0 +1,44 @@+import { createAction, Property } from '@activepieces/pieces-framework';+import { HttpMethod } from '@activepieces/pieces-common';+import { facebookPagesAuth } from '../../auth';+import { facebookPagesCommon } from '../../common/common';+import { reschedulePostOutputSchema } from '../../output-schemas';++export const reschedulePostAction = createAction({+ auth: facebookPagesAuth,+ name: 'reschedule_post',+ classification: 'WRITE',+ displayName: 'Reschedule Post',+ description: 'Changes when a scheduled Facebook Page post will be published.',+ audience: 'ai',+ aiMetadata: {+ description:+ 'Move a scheduled, not yet published Facebook Page post to a new publish time at least 10 minutes ahead. Find scheduled posts with Get Scheduled Posts; use Publish Scheduled Post to publish now instead. Facebook only allows this on posts created through this same app.',+ idempotent: true,+ },+ outputSchema: reschedulePostOutputSchema,+ props: {+ pageId: facebookPagesCommon.pageId,+ postId: facebookPagesCommon.postId,+ scheduledPublishTime: Property.DateTime({+ displayName: 'Scheduled Publish Time',+ description: 'ISO 8601 date and time to publish the post, at least 10 minutes from now.',+ required: true,+ }),+ },+ async run({ auth, propsValue }) {+ const scheduledPublishTime = facebookPagesCommon.toScheduledUnixTime({ value: propsValue.scheduledPublishTime });+ const response = await facebookPagesCommon.pageRequest<{ success: boolean }>({+ auth,+ pageId: propsValue.pageId,+ method: HttpMethod.POST,+ path: facebookPagesCommon.objectPath({ id: propsValue.postId }),+ body: { scheduled_publish_time: scheduledPublishTime },+ });+ return {+ success: response.success,+ post_id: propsValue.postId.trim(),+ scheduled_publish_time: new Date(scheduledPublishTime * 1000).toISOString(),+ };+ },+});diff --git a/packages/pieces/community/facebook-pages/src/lib/actions/ai/update-post.ts b/packages/pieces/community/facebook-pages/src/lib/actions/ai/update-post.tsnew file mode 100644index 00000000000..73de53c52de--- /dev/null+++ b/packages/pieces/community/facebook-pages/src/lib/actions/ai/update-post.ts@@ -0,0 +1,39 @@+import { createAction, Property } from '@activepieces/pieces-framework';+import { HttpMethod } from '@activepieces/pieces-common';+import { facebookPagesAuth } from '../../auth';+import { facebookPagesCommon } from '../../common/common';+import { postResultOutputSchema } from '../../output-schemas';++export const updatePostAction = createAction({+ auth: facebookPagesAuth,+ name: 'update_post',+ classification: 'WRITE',+ displayName: 'Update Post',+ description: 'Changes the message of a Facebook Page post.',+ audience: 'ai',+ aiMetadata: {+ description:+ 'Replace the message text of an existing Facebook Page post. Facebook only allows this on posts created through this same app, such as with Create Page Post; posts made on facebook.com or by other tools cannot be edited here. Photos, videos and links on the post cannot be changed.',+ idempotent: true,+ },+ outputSchema: postResultOutputSchema,+ props: {+ pageId: facebookPagesCommon.pageId,+ postId: facebookPagesCommon.postId,+ message: Property.LongText({+ displayName: 'Message',+ description: 'The new text of the post.',+ required: true,+ }),+ },+ async run({ auth, propsValue }) {+ const response = await facebookPagesCommon.pageRequest<{ success: boolean }>({+ auth,+ pageId: propsValue.pageId,+ method: HttpMethod.POST,+ path: facebookPagesCommon.objectPath({ id: propsValue.postId }),+ body: { message: propsValue.message },+ });+ return { success: response.success, post_id: propsValue.postId.trim() };+ },+});diff --git a/packages/pieces/community/facebook-pages/src/lib/actions/create-photo-post.ts b/packages/pieces/community/facebook-pages/src/lib/actions/create-photo-post.tsindex 751c49fa325..75b70bccbcd 100644--- a/packages/pieces/community/facebook-pages/src/lib/actions/create-photo-post.ts+++ b/packages/pieces/community/facebook-pages/src/lib/actions/create-photo-post.ts@@ -1,17 +1,16 @@import { createAction } from '@activepieces/pieces-framework';--import { facebookPagesCommon, FacebookPageDropdown } from '../common/common';-import { facebookPagesAuth } from '../..';+import { HttpMethod } from '@activepieces/pieces-common';+import { facebookPagesAuth } from '../auth';+import { facebookPagesCommon } from '../common/common';import { createPhotoPostActionOutputSchema } from '../output-schemas';export const createPhotoPost = createAction({auth: facebookPagesAuth,-name: 'create_photo_post',classification: 'WRITE',displayName: 'Create Page Photo',description: 'Create a photo on a Facebook Page you manage',- audience: 'both',+ audience: 'human',aiMetadata: { description: 'Publishes a photo post to a Facebook Page the connected account manages by uploading an image from a publicly reachable URL, with an optional caption. Choose this when the post is an image rather than plain text or video. Requires a managed page and a photo URL that Facebook can fetch; not idempotent, as each call creates a new photo post.', idempotent: false },outputSchema: createPhotoPostActionOutputSchema,props: {@@ -19,15 +18,12 @@ export const createPhotoPost = createAction({photo: facebookPagesCommon.photo,caption: facebookPagesCommon.caption,},- async run(context) {- const page: FacebookPageDropdown = context.propsValue.page!;-- const result = await facebookPagesCommon.createPhotoPost(- page,- context.propsValue.caption,- context.propsValue.photo- );-- return result;+ async run({ propsValue }) {+ return facebookPagesCommon.graphRequest({+ accessToken: propsValue.page.accessToken,+ method: HttpMethod.POST,+ path: `${facebookPagesCommon.objectPath({ id: propsValue.page.id })}/photos`,+ body: { url: propsValue.photo, caption: propsValue.caption },+ });},});diff --git a/packages/pieces/community/facebook-pages/src/lib/actions/create-post.ts b/packages/pieces/community/facebook-pages/src/lib/actions/create-post.tsindex 6d3c36aafee..ce814a5534f 100644--- a/packages/pieces/community/facebook-pages/src/lib/actions/create-post.ts+++ b/packages/pieces/community/facebook-pages/src/lib/actions/create-post.ts@@ -1,6 +1,7 @@import { createAction } from '@activepieces/pieces-framework';-import { facebookPagesCommon, FacebookPageDropdown } from '../common/common';-import { facebookPagesAuth } from '../..';+import { HttpMethod } from '@activepieces/pieces-common';+import { facebookPagesAuth } from '../auth';+import { facebookPagesCommon } from '../common/common';import { createPostActionOutputSchema } from '../output-schemas';export const createPost = createAction({@@ -9,7 +10,7 @@ export const createPost = createAction({classification: 'WRITE',displayName: 'Create Page Post',description: 'Create a post on a Facebook Page you manage',- audience: 'both',+ audience: 'human',aiMetadata: { description: 'Publishes a text status update to the feed of a Facebook Page the connected account manages, optionally attaching a link that Facebook will render as a preview card. Choose this for plain-text or link announcements; use the photo or video post actions for media uploads. Requires selecting a managed page (which supplies the page-scoped access token) and a message; not idempotent, as each call publishes a separate post.', idempotent: false },outputSchema: createPostActionOutputSchema,props: {@@ -17,15 +18,12 @@ export const createPost = createAction({message: facebookPagesCommon.message,link: facebookPagesCommon.link,},- async run(context) {- const page: FacebookPageDropdown = context.propsValue.page!;-- const result = await facebookPagesCommon.createPost(- page,- context.propsValue.message,- context.propsValue.link- );-- return result;+ async run({ propsValue }) {+ return facebookPagesCommon.graphRequest({+ accessToken: propsValue.page.accessToken,+ method: HttpMethod.POST,+ path: `${facebookPagesCommon.objectPath({ id: propsValue.page.id })}/feed`,+ body: { message: propsValue.message, link: propsValue.link },+ });},});diff --git a/packages/pieces/community/facebook-pages/src/lib/actions/create-video-post.ts b/packages/pieces/community/facebook-pages/src/lib/actions/create-video-post.tsindex be734c15dec..3342b38e162 100644--- a/packages/pieces/community/facebook-pages/src/lib/actions/create-video-post.ts+++ b/packages/pieces/community/facebook-pages/src/lib/actions/create-video-post.ts@@ -1,6 +1,7 @@import { createAction } from '@activepieces/pieces-framework';-import { FacebookPageDropdown, facebookPagesCommon } from '../common/common';-import { facebookPagesAuth } from '../..';+import { HttpMethod } from '@activepieces/pieces-common';+import { facebookPagesAuth } from '../auth';+import { facebookPagesCommon } from '../common/common';import { createVideoPostActionOutputSchema } from '../output-schemas';export const createVideoPost = createAction({@@ -9,7 +10,7 @@ export const createVideoPost = createAction({classification: 'WRITE',displayName: 'Create Page Video',description: 'Create a video on a Facebook Page you manage',- audience: 'both',+ audience: 'human',aiMetadata: { description: 'Publishes a video post to a Facebook Page the connected account manages by uploading a video from a publicly reachable URL, with an optional title and description. Choose this for video content rather than text or photo posts. Requires a managed page and a video URL Facebook can fetch (limit 1GB or 20 minutes); not idempotent, as each call uploads a new video.', idempotent: false },outputSchema: createVideoPostActionOutputSchema,props: {@@ -18,16 +19,12 @@ export const createVideoPost = createAction({title: facebookPagesCommon.title,description: facebookPagesCommon.description,},- async run(context) {- const page: FacebookPageDropdown = context.propsValue.page!;-- const result = await facebookPagesCommon.createVideoPost(- page,- context.propsValue.title,- context.propsValue.description,- context.propsValue.video- );-- return result;+ async run({ propsValue }) {+ return facebookPagesCommon.graphRequest({+ accessToken: propsValue.page.accessToken,+ method: HttpMethod.POST,+ path: `${facebookPagesCommon.objectPath({ id: propsValue.page.id })}/videos`,+ body: { title: propsValue.title, description: propsValue.description, file_url: propsValue.video },+ });},});diff --git a/packages/pieces/community/facebook-pages/src/lib/auth.ts b/packages/pieces/community/facebook-pages/src/lib/auth.tsnew file mode 100644index 00000000000..70ecf98d177--- /dev/null+++ b/packages/pieces/community/facebook-pages/src/lib/auth.ts@@ -0,0 +1,29 @@+import { PieceAuth } from '@activepieces/pieces-framework';++const markdown = `+To Obtain a Client ID and Client Secret:++1. Go to https://developers.facebook.com/+2. Register for a Facebook Developer account.+3. Once login, click "Make a new app" button.+4. Select "Other" for use cases.+5. Choose "Business" as the type of app.+6. Provide application details: custom name and associated email.+7. Once your application is created, you need to add a new "product".+8. Configure a new product of type "Facebook Login Settings".+9. Default settings should be fine, you only need to provide the Redirect URL in "Valid OAuth Redirect URIs" and your domain name in "Allowed Domains for the JavaScript SDK".+10. Finally, get your application ID and application secret from your app dashboard in Settings > Basic.+`;++export const facebookPagesAuth = PieceAuth.OAuth2({+ description: markdown,+ authUrl: 'https://graph.facebook.com/oauth/authorize',+ tokenUrl: 'https://graph.facebook.com/oauth/access_token',+ required: true,+ scope: [+ 'pages_show_list',+ 'pages_manage_posts',+ 'business_management',+ 'pages_read_engagement',+ ],+});diff --git a/packages/pieces/community/facebook-pages/src/lib/common/common.ts b/packages/pieces/community/facebook-pages/src/lib/common/common.tsindex 89f2bdb6c9c..796a7586cbb 100644--- a/packages/pieces/community/facebook-pages/src/lib/common/common.ts+++ b/packages/pieces/community/facebook-pages/src/lib/common/common.ts@@ -1,58 +1,130 @@-import {- HttpMethod,- httpClient,- getAccessTokenOrThrow,-} from '@activepieces/pieces-common';+import { AuthenticationType, httpClient, HttpMethod } from '@activepieces/pieces-common';import { OAuth2PropertyValue, Property } from '@activepieces/pieces-framework';-import { facebookPagesAuth } from '../..';+import { facebookPagesAuth } from '../auth';++async function graphRequest<T>({ accessToken, method, path, queryParams, body }: GraphRequest): Promise<T> {+ const response = await httpClient.sendRequest<T>({+ method,+ url: `${GRAPH_API_URL}/${path}`,+ queryParams: compactQuery({ query: queryParams ?? {} }),+ body,+ authentication: { type: AuthenticationType.BEARER_TOKEN, token: accessToken },+ });+ return response.body;+}++async function pageRequest<T>({ auth, pageId, ...request }: PageRequest): Promise<T> {+ const accessToken = await getPageAccessToken({ auth, pageId });+ return graphRequest<T>({ accessToken, ...request });+}++async function getPageAccessToken({ auth, pageId }: { auth: OAuth2PropertyValue; pageId: string }): Promise<string> {+ const page = await graphRequest<{ access_token?: string }>({+ accessToken: auth.access_token,+ method: HttpMethod.GET,+ path: objectPath({ id: pageId }),+ queryParams: { fields: 'access_token' },+ });+ if (!page.access_token) {+ throw new Error(+ `No Page access token was returned for Page ${pageId}. The connected account needs a role on this Page; List Managed Pages shows the Pages it can use.`+ );+ }+ return page.access_token;+}++async function listAllPages({ accessToken }: { accessToken: string }): Promise<FacebookPage[]> {+ const pages: FacebookPage[] = [];+ let after: string | undefined;+ do {+ const response = await graphRequest<GraphList<FacebookPage>>({+ accessToken,+ method: HttpMethod.GET,+ path: 'me/accounts',+ queryParams: { fields: 'id,name,access_token', limit: '100', after },+ });+ pages.push(...(response.data ?? []));+ after = response.paging?.next ? response.paging.cursors?.after : undefined;+ } while (after);+ return pages;+}++function objectPath({ id }: { id: string }): string {+ return encodeURIComponent(id.trim());+}++function toCursorPage<T>({ response }: { response: GraphList<T> }) {+ const items = response.data ?? [];+ return {+ items,+ count: items.length,+ next_cursor: response.paging?.next ? response.paging.cursors?.after ?? null : null,+ };+}++function cursorQuery({ limit, after }: { limit?: number; after?: string }): Record<string, string | undefined> {+ return {+ limit: String(Math.min(MAX_PAGE_LIMIT, Math.max(1, Math.floor(limit ?? DEFAULT_PAGE_LIMIT)))),+ after: isProvided(after) ? after.trim() : undefined,+ };+}++function fieldsQuery({ fields, defaultFields }: { fields: unknown; defaultFields: string }): string {+ const requested = Array.isArray(fields)+ ? fields.filter((field): field is string => typeof field === 'string' && field.trim().length > 0).map((field) => field.trim())+ : [];+ return requested.length > 0 ? requested.join(',') : defaultFields;+}++function toScheduledUnixTime({ value }: { value: string }): number {+ const timestamp = Date.parse(value);+ if (Number.isNaN(timestamp)) {+ throw new Error('Scheduled Publish Time must be a valid ISO 8601 date and time.');+ }+ if (timestamp < Date.now() + MIN_SCHEDULE_LEAD_MS) {+ throw new Error('Scheduled Publish Time must be at least 10 minutes in the future.');+ }+ return Math.floor(timestamp / 1000);+}++function isProvided(value: string | undefined | null): value is string {+ return value !== undefined && value !== null && value.trim().length > 0;+}++function compactQuery({ query }: { query: Record<string, string | undefined> }): Record<string, string> {+ return Object.fromEntries(+ Object.entries(query).filter((entry): entry is [string, string] => entry[1] !== undefined && entry[1] !== '')+ );+}++const GRAPH_API_URL = 'https://graph.facebook.com/v23.0';+const DEFAULT_PAGE_LIMIT = 25;+const MAX_PAGE_LIMIT = 100;+const MIN_SCHEDULE_LEAD_MS = 10 * 60 * 1000;export const facebookPagesCommon = {- baseUrl: 'https://graph.facebook.com/v17.0',- page: Property.Dropdown<FacebookPageDropdown,true,typeof facebookPagesAuth>({+ page: Property.Dropdown<FacebookPageDropdown, true, typeof facebookPagesAuth>({auth: facebookPagesAuth,displayName: 'Page',required: true,refreshers: [],options: async ({ auth }) => {if (!auth) {- return {- disabled: true,- options: [],- placeholder: 'Connect your account',- };+ return { disabled: true, options: [], placeholder: 'Connect your account' };}-- try {- const accessToken: string = getAccessTokenOrThrow(- auth- );- const pages: any[] = (- await facebookPagesCommon.getPages(accessToken)- ).map((page: FacebookPage) => {- return {- label: page.name,- value: {- id: page.id,- accessToken: page.access_token,- },- };- });-- return {- options: pages,- placeholder: 'Choose a page',- };- } catch (e) {- console.debug(e);- return {- disabled: true,- options: [],- placeholder: 'Connect your account',- };+ const pages = await listAllPages({ accessToken: auth.access_token }).catch(() => null);+ if (pages === null) {+ return { disabled: true, options: [], placeholder: 'Could not load your Pages, reconnect your account' };}+ return {+ options: pages.map((page) => ({+ label: page.name,+ value: { id: page.id, accessToken: page.access_token },+ })),+ placeholder: 'Choose a page',+ };},}),-message: Property.LongText({displayName: 'Message',required: true,@@ -61,7 +133,6 @@ export const facebookPagesCommon = {displayName: 'Link',required: false,}),-caption: Property.LongText({displayName: 'Caption',required: false,@@ -71,7 +142,6 @@ export const facebookPagesCommon = {description: 'A URL we can access for the photo',required: true,}),-title: Property.ShortText({displayName: 'Title',required: false,@@ -85,81 +155,79 @@ export const facebookPagesCommon = {description: 'A URL we can access for the video (Limit: 1GB or 20 minutes)',required: true,}),+ pageId: Property.ShortText({+ displayName: 'Page ID',+ description: 'Numeric ID of a Facebook Page the connected account manages. Find it with List Managed Pages.',+ required: true,+ }),+ postId: Property.ShortText({+ displayName: 'Post ID',+ description:+ 'The post ID in PageID_PostID format, as returned in post_id by Create Page Photo Post, in id by Create Page Post, or by Get Page Posts. A photo or video ID is not a post ID.',+ required: true,+ }),+ limit: Property.Number({+ displayName: 'Limit',+ description: `Maximum number of items to return in this page (1 to ${MAX_PAGE_LIMIT}).`,+ required: false,+ defaultValue: DEFAULT_PAGE_LIMIT,+ min: 1,+ max: MAX_PAGE_LIMIT,+ step: 1,+ }),+ after: Property.ShortText({+ displayName: 'After Cursor',+ description: 'The next_cursor value from a previous call, to fetch the next page.',+ required: false,+ }),+ fields: ({ defaultFields }: { defaultFields: string }) =>+ Property.Array({+ displayName: 'Fields',+ description: `Graph API fields to return instead of the defaults (${defaultFields}).`,+ required: false,+ }),+ graphRequest,+ pageRequest,+ getPageAccessToken,+ objectPath,+ toCursorPage,+ cursorQuery,+ fieldsQuery,+ toScheduledUnixTime,+ isProvided,+};- getPages: async (accessToken: string) => {- const response = await httpClient.sendRequest({- method: HttpMethod.GET,- url: `${facebookPagesCommon.baseUrl}/me/accounts?access_token=${accessToken}`,- });-- return response.body.data;- },-- createPost: async (- page: FacebookPageDropdown,- message: string,- link: string | undefined- ) => {- const response = await httpClient.sendRequest({- method: HttpMethod.POST,- url: `${facebookPagesCommon.baseUrl}/${page.id}/feed`,- body: {- access_token: page.accessToken,- message: message,- link: link,- },- });- return response.body;- },- createPhotoPost: async (- page: FacebookPageDropdown,- caption: string | undefined,- photo: string- ) => {- const response = await httpClient.sendRequest({- method: HttpMethod.POST,- url: `${facebookPagesCommon.baseUrl}/${page.id}/photos`,- body: {- access_token: page.accessToken,- url: photo,- caption: caption,- },- });- return response.body;- },-- createVideoPost: async (- page: FacebookPageDropdown,- title: string | undefined,- description: string | undefined,- video: string- ) => {- const response = await httpClient.sendRequest({- method: HttpMethod.POST,- url: `${facebookPagesCommon.baseUrl}/${page.id}/videos`,- body: {- access_token: page.accessToken,- title: title,- description: description,- file_url: video,- },- });+type GraphRequest = {+ accessToken: string;+ method: HttpMethod;+ path: string;+ queryParams?: Record<string, string | undefined>;+ body?: Record<string, unknown>;+};- return response.body;- },+type PageRequest = Omit<GraphRequest, 'accessToken'> & {+ auth: OAuth2PropertyValue;+ pageId: string;};-export interface FacebookPage {+type FacebookPage = {id: string;name: string;- category: string;- category_list: string[];access_token: string;- tasks: string[];-}+};++export type GraphList<T> = {+ data?: T[];+ paging?: {+ cursors?: { before?: string; after?: string };+ next?: string;+ };+};-export interface FacebookPageDropdown {+export type GraphRecord = Record<string, unknown>;++export type FacebookPageDropdown = {id: string;accessToken: string;-}+};diff --git a/packages/pieces/community/facebook-pages/src/lib/output-schemas.ts b/packages/pieces/community/facebook-pages/src/lib/output-schemas.tsindex 6a78c3433c3..385b19c8849 100644--- a/packages/pieces/community/facebook-pages/src/lib/output-schemas.ts+++ b/packages/pieces/community/facebook-pages/src/lib/output-schemas.ts@@ -1,4 +1,4 @@-import { OutputSchema } from '@activepieces/pieces-framework';+import { OutputSchema, OutputSchemaField } from '@activepieces/pieces-framework';export const createPostActionOutputSchema: OutputSchema = {fields: [{ key: 'id', label: 'Post ID' }],@@ -14,3 +14,204 @@ export const createPhotoPostActionOutputSchema: OutputSchema = {export const createVideoPostActionOutputSchema: OutputSchema = {fields: [{ key: 'id', label: 'Video ID' }],};++const pageMetaFields: OutputSchemaField[] = [+ { key: 'count', label: 'Count', format: 'number' },+ { key: 'next_cursor', label: 'Next Cursor', description: 'Pass as After Cursor to fetch the next page. Empty on the last page.' },+];++const postResultFields: OutputSchemaField[] = [+ { key: 'success', label: 'Success', format: 'boolean' },+ { key: 'post_id', label: 'Post ID' },+];++const postFields: OutputSchemaField[] = [+ { key: 'id', label: 'Post ID' },+ { key: 'message', label: 'Message' },+ { key: 'created_time', label: 'Created Time', format: 'datetime' },+ { key: 'updated_time', label: 'Updated Time', format: 'datetime' },+ { key: 'permalink_url', label: 'Permalink', format: 'url' },+ { key: 'status_type', label: 'Post Type' },+ { key: 'full_picture', label: 'Picture', format: 'image' },+ { key: 'is_published', label: 'Published', format: 'boolean' },+];++export const listManagedPagesOutputSchema: OutputSchema = {+ fields: [+ {+ key: 'items',+ label: 'Pages',+ labelKey: 'name',+ listItems: [+ { key: 'id', label: 'Page ID' },+ { key: 'name', label: 'Name' },+ { key: 'category', label: 'Category' },+ { key: 'username', label: 'Username' },+ { key: 'link', label: 'Link', format: 'url' },+ { key: 'tasks', label: 'Tasks' },+ ],+ },+ ...pageMetaFields,+ ],+};++export const pageDetailsOutputSchema: OutputSchema = {+ fields: [+ { key: 'id', label: 'Page ID' },+ { key: 'name', label: 'Name' },+ { key: 'username', label: 'Username' },+ { key: 'category', label: 'Category' },+ { key: 'about', label: 'About' },+ { key: 'description', label: 'Description' },+ { key: 'link', label: 'Link', format: 'url' },+ { key: 'website', label: 'Website', format: 'url' },+ { key: 'phone', label: 'Phone' },+ { key: 'emails', label: 'Emails' },+ { key: 'single_line_address', label: 'Address' },+ { key: 'followers_count', label: 'Followers', format: 'number' },+ { key: 'verification_status', label: 'Verification Status' },+ { key: 'is_published', label: 'Published', format: 'boolean' },+ { key: 'picture_url', label: 'Profile Picture', value: 'picture.data.url', format: 'image' },+ { key: 'cover_url', label: 'Cover Photo', value: 'cover.source', format: 'image' },+ ],+};++export const createPagePostOutputSchema: OutputSchema = {+ fields: [{ key: 'id', label: 'Post ID' }],+};++export const createPagePhotoPostOutputSchema: OutputSchema = {+ fields: [+ { key: 'post_id', label: 'Post ID' },+ { key: 'id', label: 'Photo ID' },+ ],+};++export const createPageVideoPostOutputSchema: OutputSchema = {+ fields: [{ key: 'id', label: 'Video ID' }],+};++export const createMultiPhotoPostOutputSchema: OutputSchema = {+ fields: [+ { key: 'post_id', label: 'Post ID' },+ { key: 'photo_ids', label: 'Photo IDs' },+ ],+};++export const pagePostsOutputSchema: OutputSchema = {+ fields: [{ key: 'items', label: 'Posts', labelKey: 'message', listItems: postFields }, ...pageMetaFields],+};++export const postOutputSchema: OutputSchema = {+ fields: [+ ...postFields,+ { key: 'scheduled_publish_time', label: 'Scheduled Publish Time (Unix seconds)', format: 'number' },+ {+ key: 'attachments',+ label: 'Attachments',+ value: 'attachments.data',+ labelKey: 'title',+ listItems: [+ { key: 'type', label: 'Type' },+ { key: 'media_type', label: 'Media Type' },+ { key: 'title', label: 'Title' },+ { key: 'description', label: 'Description' },+ { key: 'url', label: 'URL', format: 'url' },+ { key: 'image', label: 'Image', value: 'media.image.src', format: 'image' },+ ],+ },+ ],+};++export const postResultOutputSchema: OutputSchema = {+ fields: postResultFields,+};++export const reschedulePostOutputSchema: OutputSchema = {+ fields: [...postResultFields, { key: 'scheduled_publish_time', label: 'Scheduled Publish Time', format: 'datetime' }],+};++export const scheduledPostsOutputSchema: OutputSchema = {+ fields: [+ {+ key: 'items',+ label: 'Scheduled Posts',+ labelKey: 'message',+ listItems: [+ { key: 'id', label: 'Post ID' },+ { key: 'message', label: 'Message' },+ { key: 'created_time', label: 'Created Time', format: 'datetime' },+ { key: 'scheduled_publish_time', label: 'Scheduled Publish Time (Unix seconds)', format: 'number' },+ { key: 'permalink_url', label: 'Permalink', format: 'url' },+ { key: 'is_published', label: 'Published', format: 'boolean' },+ ],+ },+ ...pageMetaFields,+ ],+};++export const pagePhotosOutputSchema: OutputSchema = {+ fields: [+ {+ key: 'items',+ label: 'Photos',+ labelKey: 'id',+ listItems: [+ { key: 'id', label: 'Photo ID' },+ { key: 'name', label: 'Caption' },+ { key: 'created_time', label: 'Created Time', format: 'datetime' },+ { key: 'updated_time', label: 'Updated Time', format: 'datetime' },+ { key: 'link', label: 'Link', format: 'url' },+ { key: 'width', label: 'Width', format: 'number' },+ { key: 'height', label: 'Height', format: 'number' },+ {+ key: 'images',+ label: 'Image Sizes',+ listItems: [+ { key: 'source', label: 'Image', format: 'image' },+ { key: 'width', label: 'Width', format: 'number' },+ { key: 'height', label: 'Height', format: 'number' },+ ],+ },+ {+ key: 'album',+ label: 'Album',+ children: [+ { key: 'id', label: 'Album ID' },+ { key: 'name', label: 'Album Name' },+ ],+ },+ ],+ },+ ...pageMetaFields,+ ],+};++export const pageVideosOutputSchema: OutputSchema = {+ fields: [+ {+ key: 'items',+ label: 'Videos',+ labelKey: 'title',+ listItems: [+ { key: 'id', label: 'Video ID' },+ { key: 'title', label: 'Title' },+ { key: 'description', label: 'Description' },+ { key: 'created_time', label: 'Created Time', format: 'datetime' },+ { key: 'updated_time', label: 'Updated Time', format: 'datetime' },+ { key: 'length', label: 'Length (seconds)', format: 'number' },+ { key: 'permalink_url', label: 'Permalink Path' },+ { key: 'picture', label: 'Thumbnail', format: 'image' },+ ],+ },+ ...pageMetaFields,+ ],+};++export const postReactionsOutputSchema: OutputSchema = {+ fields: [+ { key: 'object_id', label: 'Post ID' },+ { key: 'type', label: 'Reaction Type' },+ { key: 'total_count', label: 'Total Reactions', format: 'number' },+ ],+};