Skip to content

V4 - MessageInterceptor

A utility workflow that formats messages for different output types and channels, handling both plain text and interactive message templates with predefined button options and WhatsApp content templates.

Purpose

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

How It Works

This workflow acts as a message formatting service that other workflows can call to prepare messages for delivery:

  1. Receives Input: Accepts message content, output options, output type, and channel information from calling workflows
  2. Processes Message Format: Analyzes the output type and available options to determine the appropriate formatting approach
  3. Maps Templates: For interactive messages, maps predefined button combinations to specific WhatsApp content template IDs
  4. Formats Output: Creates the final message format, whether as plain text with numbered options or as structured template data
  5. Returns Results: Provides the formatted message along with any required template metadata

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. It accepts four input parameters: - output: The message content to be formatted - outputOptions: Array of available response options for interactive messages - outputType: The type of output format (plain, interactive, form_2_1, form_3_1) - channel: The target communication channel

Nodes Used

Node Type Node Name Purpose
Execute Workflow Trigger When Executed by Another Workflow Receives input parameters from calling workflows
Code formatMessage Processes message formatting logic and template mapping
Set setOutput Structures the final output data

External Services & Credentials Required

This workflow does not directly connect to external services. However, it generates WhatsApp content template IDs that would be used by messaging services:

  • WhatsApp Business API: The generated contentSid values reference WhatsApp message templates
  • No credentials are required for this workflow itself

Environment Variables

No environment variables are required for this workflow.

Data Flow

Input Parameters: - output (string): The main message text - outputOptions (array): Available response options for interactive messages - outputType (string): Format type - 'plain', 'interactive', 'form_2_1', or 'form_3_1' - channel (string): Target communication channel

Output Data: - formattedMessage (string): The processed message text - contentSid (string): WhatsApp template ID (if applicable) - contentVariables (string): JSON string of template variables (if applicable)

Error Handling

The workflow includes basic error handling: - Defaults output to empty string if not provided - Defaults outputType to 'plain' if not specified - Falls back to numbered list format for interactive messages without matching templates - Handles missing or invalid outputOptions arrays gracefully

Known Limitations

  • Template mapping is hardcoded for specific button combinations in English and Kiswahili
  • Limited to predefined WhatsApp content template IDs
  • No validation of input parameter types or formats
  • Template variables are limited to a single dynamic field ('1')

This workflow is designed to be called by other messaging workflows that need formatted output. No specific related workflows are identified in the current context.

Setup Instructions

  1. Import Workflow: Import the workflow JSON into your n8n instance

  2. Verify Node Configuration:

    • Ensure the Execute Workflow Trigger has the correct input parameters defined
    • Review the template mapping in the formatMessage code node
    • Confirm the setOutput node assignments match your requirements
  3. Update Template Mapping (if needed):

    • Modify the TEMPLATE_MAP object in the formatMessage node to match your WhatsApp content template IDs
    • Add or remove button combinations as needed for your use case
  4. Test the Workflow:

    • Create a test workflow that calls this MessageInterceptor
    • Test with different outputType values: 'plain', 'interactive', 'form_2_1', 'form_3_1'
    • Verify template mapping works for your button combinations
  5. Integration:

    • Use the "Execute Workflow" node in other workflows to call this MessageInterceptor
    • Pass the required parameters: output, outputOptions, outputType, and channel
    • Process the returned formattedMessage, contentSid, and contentVariables as needed

The workflow is ready to use once imported, but you may want to customize the template mappings to match your specific WhatsApp Business API setup.