Skip to content

IAV-989/feat(agent): fix credential validation logic, split Meta controllers, extract activation helper

salaheddine zidani a demandé de fusionner feature/IAV-989 vers develop

Summary

Three changes bundled together: a critical bug fix in credential validation, a Meta integration refactor, and extraction of agent activation logic. The activation helper depends on the corrected credential methods, hence the grouping.


Changes

🐛 Fix — Credential validation logic inversion

hasAtLeastOneUserProvidedChannel() and hasUserProvidedEcommerce() were returning true for fake credentials and false for real ones. As a result, validateWorkflowCreationPrerequisites() was passing validation even when the agent had no real user integrations, silently advancing the wizard to CONFIGURATIONS.

  • Added isUserProvidedCredential() as the canonical positive check (!isFakeCredential())
  • All consumers in AgentIntegrationHelper updated accordingly

🐛 Fix — Instagram Header Auth credential format

Raw access token was passed to n8n as-is. The httpHeaderAuth type requires { name: "Authorization", value: "Bearer <token>" }. Added mapInstagramHeaderAuthCredentials() to handle this.

️ Refactor — Meta integration split

MetaIntegrationController / MetaGraphApiService split into two focused pairs:

  • FacebookMessengerController + FacebookMessengerApiService/api/customer-care/integrations/meta
  • InstagramProApiController + InstagramProApiService/api/customer-care/instagram

New MetaPageTokenValidationResult DTO for page-only token validation (no webhook fields). New FacebookMessengerPaths constants.

️ Refactor — AgentActivationHelper extracted

Activation precondition logic moved out of AgentServiceImpl into a dedicated component with validateActivationPreconditions(), buildReadinessReport(), activateN8nWorkflow(), and persistAgentAsActive().

New — Webhook URL endpoints

GET /agents/{agentUid}/webhook-urls/instagram and /messenger added. Base URLs in AgentConstants.

🧹 Cleanup

Removed System.out.println from AgentController.uploadAgentDocuments().


Testing Checklist

  • Workflow creation blocked when all credentials are fake
  • Workflow creation passes with at least one real channel + real ecommerce
  • Agent activation blocked without workflow ID / with fake channel or ecommerce
  • Instagram credential stored in n8n as Authorization: Bearer <token>
  • POST /facebook/page/validate-token works without app credentials
  • GET /instagram/validation/token/permissions correctly classifies permissions
  • Webhook URL endpoints return correct URLs

#Related Issues Closes IAV-989

Rapports de requête de fusion