Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { IIntegrationDocument } from '@/inbox/@types/integrations';
import { IContext } from '~/connectionResolvers';
import { facebookStatus } from '@/integrations/facebook/messageBroker';
import { graphRequest } from '@/integrations/facebook/utils';
import { IFacebookPageResponse } from '@/integrations/facebook/@types/integrations';

export const integrationStatus = async (
serviceName: string,
subdomain: string,
Expand Down Expand Up @@ -131,4 +134,60 @@ export default {
}
return serviceName;
},

async facebookPage(
integration: IIntegrationDocument,
_args,
{ models }: IContext,
) {
const serviceName = integration.kind.includes('facebook')
? 'facebook'
: integration.kind;

if (serviceName !== 'facebook') {
return null;
}

try {
const facebookIntegration = await models.FacebookIntegrations.findOne({
erxesApiId: integration._id,
});

if (
!facebookIntegration ||
!Array.isArray(facebookIntegration.facebookPageIds)
) {
console.warn('No facebookIntegration or no facebookPageIds found');
return null;
}

const results: ({ pageId: string } & IFacebookPageResponse)[] = [];

for (const pageId of facebookIntegration.facebookPageIds) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider parallelizing the independent Facebook page requests (e.g. with Promise.all) for potential performance improvements.

const token = facebookIntegration.facebookPageTokensMap?.[pageId];

if (!token) {
console.warn(`Token not found for pageId: ${pageId}`);
continue;
}

try {
const response = (await graphRequest.get(
`/${pageId}?fields=id,name`,
token,
)) as IFacebookPageResponse;

if (response) {
results.push({ pageId, ...response });
}
} catch (err) {
console.error(`Failed to fetch page ${pageId}:`, err);
}
}

return results.length > 0 ? results : null;
} catch (error) {
throw error;
}
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const types = `
webhookData: JSON

brand: Brand

facebookPage: JSON
channels: [Channel]


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,8 @@ export interface IFacebookIntegrationDocument
Document {
_id: string;
}

export interface IFacebookPageResponse {
id: string;
name: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const EM_INTEGRATION_DETAIL_QUERY = gql`
languageCode
channels {
_id
name
}
messengerData
callData {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ export const FacebookIntegrationEditForm = ({
};

if (loading) return <Spinner className="p-20" />;

return (
<>
<Dialog.Header className="flex-row items-center justify-between space-y-0 px-4 py-3">
Expand All @@ -109,6 +108,25 @@ export const FacebookIntegrationEditForm = ({
})}
>
<div className="p-6 pb-8 space-y-6">
<Form.Field
name="facebookPage"
render={({ field }) => {
const facebookPageName = field.value?.[0] ?? null;
return (
<Form.Item>
<Form.Label>Page Name</Form.Label>
<Form.Control>
<Input
name={field.name}
value={facebookPageName?.name || ''}
disabled
readOnly
/>
</Form.Control>
</Form.Item>
);
}}
/>
<Form.Field
name="name"
render={({ field }) => (
Expand All @@ -134,18 +152,20 @@ export const FacebookIntegrationEditForm = ({
)}
/>
<Form.Field
name="channelIds"
render={({ field }) => (
<Form.Item>
<Form.Label>Channels</Form.Label>
<SelectChannel.FormItem
value={field.value}
onValueChange={field.onChange}
mode="multiple"
/>
<Form.Message />
</Form.Item>
)}
name="channels"
render={({ field }) => {
return (
<Form.Item>
<Form.Label>Channels</Form.Label>
<SelectChannel.FormItem
value={field.value}
onValueChange={field.onChange}
mode="multiple"
/>
<Form.Message />
</Form.Item>
);
}}
/>
Comment on lines +155 to 169
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

🧩 Analysis chain

channels field rename: verify mutation variables and schema expect channels (not channelIds).

Ensure editIntegration/integrationsEdit mutations, Zod schema, and server resolvers accept channels. If backend still expects channelIds, submission will fail.


🏁 Script executed:

#!/bin/bash
# Verify remaining channelIds usages and the expected mutation variables.
rg -nP -C3 '\bchannelIds\b'
rg -nP -C3 '(integrations?Edit|editIntegration)\s*\(' --type=ts --type=tsx --type=js --type=jsx
# Inspect the FB schema to confirm shape of `channels`
fd -a 'FbMessengerSchema' | xargs -I{} sh -c 'echo "==> {}"; sed -n "1,200p" "{}" | sed -n "1,200p"'

Length of output: 54491


Revert to using channelIds (or update backend) — backend still expects channelIds

Form field was renamed to name="channels" but frontend Zod schemas, GraphQL mutations, and backend resolvers/schemas still use channelIds; this will break submissions. Revert the Form.Field to name="channelIds" or update/map all layers to accept "channels" -> "channelIds".

Files to fix or align:

  • frontend/plugins/frontline_ui/src/modules/integrations/facebook/components/FacebookIntegrationDetail.tsx (current change)
  • frontend/plugins/frontline_ui/src/modules/integrations/facebook/constants/FbMessengerSchema.ts
  • frontend/plugins/frontline_ui/src/modules/integrations/facebook/components/FacebookIntegrationSetup.tsx
  • frontend/plugins/frontline_ui/src/modules/integrations/graphql/mutations/AddIntegration.ts
  • frontend/plugins/frontline_ui/src/modules/integrations/graphql/mutations/EditIntegration.ts
  • backend/plugins/frontline_api/src/modules/inbox/graphql/schemas/integration.ts
  • backend/plugins/frontline_api/src/modules/inbox/graphql/resolvers/mutations/integrations.ts
🤖 Prompt for AI Agents
In
frontend/plugins/frontline_ui/src/modules/integrations/facebook/components/FacebookIntegrationDetail.tsx
lines ~155-169, the Form.Field was renamed to name="channels" but the rest of
the stack (Zod schemas, GraphQL mutations, backend resolvers/schemas) still
expect channelIds; revert this Form.Field back to name="channelIds" so
submissions match existing contracts, or alternatively add a mapping step before
submit that copies form.values.channels to form.values.channelIds. Also update
the related files listed (FbMessengerSchema.ts, FacebookIntegrationSetup.tsx,
AddIntegration.ts, EditIntegration.ts, and the backend integration schema and
resolver files) to keep the field name consistent across frontend Zod types,
GraphQL input types, and backend resolver payloads if you opt to rename instead
of reverting.

</div>
<Separator />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ export const GET_INTEGRATION_DETAIL = gql`
isConnected
channels {
_id
name
}
departmentIds
details
facebookPage
callData {
secondPageHeader
secondPageDescription
Expand Down