Skip to content

IAV-1286/refactor(whatsapp): dead code cleanup, trigger swap logic, and Meta app uniqueness enforcement

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

Summary

This MR delivers three related improvements to the WhatsApp integration feature:

  1. Dead code cleanup across all layers (mappers, repositories, helpers, services).
  2. Automatic WhatsApp Manual trigger swap depending on the presence of the whatsappTriggerApi credential on the agent linked to the workflow.
  3. Meta app client ID uniqueness validation before creating a new WhatsApp integration.

Motivation

Trigger swap

In n8n, a workflow must have a trigger node to be executable. When a client has not yet set up a WhatsApp integration, the workflow should fall back to a manual trigger so it remains usable. Once the client creates the WhatsApp integration (providing a valid whatsappTriggerApi credential), the trigger should automatically be upgraded back to a WhatsApp trigger — which in turn registers a webhook in Meta so incoming messages on the linked phone number activate the workflow.

Meta app uniqueness

A Meta app can only register one WhatsApp webhook. If two n8n workflows both contain a WhatsApp Trigger node pointing to the same Meta app, the second workflow cannot be published or activated.


Changes

Area Change
Mappers Removed unused mapping methods
Repositories Removed deprecated query/mutation methods
Helpers Removed dead utility functions
Services Removed unused service methods; added trigger swap logic; added Meta app client ID uniqueness check
WhatsApp Integration Swap WhatsApp trigger manual trigger based on credential presence
WhatsApp Integration Block creation if Meta app client ID already exists in n8n credentials

Trigger Swap Logic (flow)

Agent linked to workflow


Does agent have whatsappTriggerApi credential?

   NO ──┼──► Replace WhatsApp Trigger → Manual Trigger in workflow

  YES ──┼──► Replace Manual Trigger → WhatsApp Trigger in workflow

Meta App Uniqueness Check (flow)

Client submits WhatsApp integration creation


Extract Meta app client ID from payload


Query iAvia Core n8n DB for existing credential with same client ID

  FOUND ┼──► Reject with error: "This Meta app is already"

NOT FOUND ──► Proceed with integration creation

Testing

  • Create an agent without WhatsApp integration → verify workflow uses manual trigger
  • Create a WhatsApp integration for that agent → verify workflow is updated to WhatsApp trigger
  • Delete the WhatsApp integration → verify workflow reverts to manual trigger
  • Attempt to create a second WhatsApp integration with an already-used Meta app client ID → verify rejection
  • Verify no regressions in existing workflows after dead code removal

Breaking Changes

None. The trigger swap is handled automatically and transparently for the end user.


Related Issues

Closes IAV-1286

Rapports de requête de fusion