Skip to content

V4-Credit-MessageInterceptor

A message formatting workflow that transforms plain text outputs into WhatsApp-compatible messages with interactive buttons and templates. This workflow serves as a message interceptor that standardizes communication formats across different conversation flows.

Purpose

No business context provided yet — add a context.md to enrich this documentation.

This workflow appears to be part of a credit or financial services system, handling message formatting for various user interactions including consent flows, reminder settings, payment confirmations, and multi-language support (English/Kiswahili).

How It Works

  1. Receives Input: The workflow is triggered by another workflow with message content, output options, output type, and channel information
  2. Processes Message Format: A JavaScript code node analyzes the input to determine the appropriate message format based on the output type and available options
  3. Maps to Templates: For interactive messages, the system maps button combinations to predefined WhatsApp template IDs using a comprehensive template mapping system
  4. Formats Output: The final node structures the output with the formatted message, content SID (template ID), and any required template variables
  5. Returns Result: Outputs the processed message ready for delivery through WhatsApp or other messaging channels

Workflow Diagram

graph TD
    A[When Executed by Another Workflow] --> B[formatMessage]
    B --> C[setOutput]

    A --> |"output, outputOptions, outputType, channel"| B
    B --> |"formattedMessage, contentSid, contentVariables"| C

Trigger

Execute Workflow Trigger: This workflow is designed to be called by other workflows, not triggered directly by external events. It expects the following input parameters: - output (string): The main message content - outputOptions (array): Available response options for interactive messages - outputType (string): Type of message format (plain, interactive, form_2_1, form_3_1) - channel (string): Communication channel identifier

Nodes Used

Node Type Node Name Purpose
Execute Workflow Trigger When Executed by Another Workflow Receives input parameters from calling workflows
Code (JavaScript) formatMessage Processes message content and maps to appropriate WhatsApp templates
Set setOutput Structures the final output with formatted message and template information

External Services & Credentials Required

WhatsApp Business API Templates: This workflow references WhatsApp template IDs (SIDs) that must be pre-approved by Meta/WhatsApp. No direct API credentials are required in this workflow as it only formats messages for consumption by other workflows.

Environment Variables

No environment variables are used in this workflow. All template mappings and formatting logic are contained within the JavaScript code node.

Data Flow

Input: - output: Main message text - outputOptions: Array of button/option labels - outputType: Format type (plain, interactive, form_2_1, form_3_1) - channel: Communication channel

Output: - formattedMessage: Processed message text ready for delivery - contentSid: WhatsApp template ID (if applicable) - contentVariables: JSON string of template variables (if applicable)

Error Handling

The workflow includes basic error handling through fallback mechanisms: - If no matching template is found for interactive messages, it falls back to numbered text options - Missing or invalid input parameters default to empty strings or plain text format - Template mapping failures result in plain text message delivery

Known Limitations

  • WhatsApp template approval dependency: Some templates may be pending approval (error 63013) and fall back to numbered text
  • Limited to predefined template mappings - new button combinations require code updates
  • No validation of input parameter formats or content length limits

This workflow is designed to be called by other workflows in the system, particularly those handling: - Credit follow-up processes - User consent flows - Reminder scheduling - Payment confirmations - Multi-language interactions

Setup Instructions

  1. Import Workflow: Import the JSON into your n8n instance
  2. Verify Templates: Ensure all referenced WhatsApp template IDs exist and are approved in your WhatsApp Business account
  3. Test Integration: Create a test workflow that calls this message interceptor with sample data
  4. Configure Calling Workflows: Update other workflows to use this interceptor for message formatting
  5. Monitor Template Status: Regularly check WhatsApp template approval status and update fallback mechanisms as needed

Template Management: The template mapping in the formatMessage node may need updates when: - New WhatsApp templates are approved - Button combinations change - New languages or message types are added - Template IDs are updated by WhatsApp/Meta