Skip to content

V4 - MessageInterceptor

A utility workflow that formats messages for different output types, particularly converting interactive messages with options into numbered lists for better user experience across messaging platforms.

Purpose

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

This workflow serves as a message formatting service that can be called by other workflows to standardize how messages are presented to users. It's particularly useful for converting interactive messages with multiple choice options into a more readable numbered format.

How It Works

  1. Receives Input: The workflow is triggered by another workflow with message data including the main output text, optional choices, output type, and target channel
  2. Formats Message: A JavaScript function processes the input and formats it based on the output type - for interactive messages, it adds numbered options below the main text
  3. Returns Result: The formatted message is prepared and returned to the calling workflow

Workflow Diagram

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

Trigger

Execute Workflow Trigger: This workflow is designed to be called by other workflows, not triggered by external events. It accepts four input parameters: - output - The main message text - outputOptions - Array of choice options for interactive messages - outputType - Type of output (plain or interactive) - channel - Target messaging channel (e.g., WhatsApp)

Nodes Used

Node Type Node Name Purpose
Execute Workflow Trigger When Executed by Another Workflow Receives input parameters from calling workflows
Code formatMessage Processes and formats the message based on type and options
Set setOutput Prepares the final formatted message for return

External Services & Credentials Required

This workflow is self-contained and doesn't require any external services or credentials.

Environment Variables

No environment variables are required for this workflow.

Data Flow

Input Parameters: - output (string) - Main message content - outputOptions (array) - List of interactive options - outputType (string) - "plain" or "interactive" - channel (string) - Target messaging platform

Processing: - For plain messages: Returns the output as-is - For interactive messages: Appends numbered options (1. Option1, 2. Option2, etc.)

Output: - formattedMessage (string) - The processed message ready for delivery

Example Input:

1
2
3
4
5
6
{
  "output": "Choose your preferred option:",
  "outputOptions": ["Yes", "No", "Maybe"],
  "outputType": "interactive",
  "channel": "WhatsApp"
}

Example Output:

1
2
3
{
  "formattedMessage": "Choose your preferred option:\n\n1. Yes\n2. No\n3. Maybe"
}

Error Handling

The workflow includes basic error handling: - Defaults output to empty string if not provided - Defaults outputType to "plain" if not specified - Safely handles cases where outputOptions is not an array or is empty

Known Limitations

  • Only supports two output types: "plain" and "interactive"
  • Numbering format is fixed (1., 2., 3., etc.) and not customizable
  • No validation of input parameter types or formats
  • Channel parameter is accepted but not currently used in formatting logic

This workflow is designed to be called by other workflows that need message formatting capabilities. Look for workflows that handle user interactions or messaging automation.

Setup Instructions

  1. Import the Workflow:

    • Copy the workflow JSON
    • In n8n, go to Workflows > Import from JSON
    • Paste the JSON and save
  2. Activate the Workflow:

    • Ensure the workflow is set to "Active"
    • No additional configuration is needed
  3. Call from Other Workflows:

    • Use the "Execute Workflow" node in your main workflows
    • Set the workflow to "V4 - MessageInterceptor"
    • Pass the required parameters: output, outputOptions, outputType, and channel
    • The formatted message will be available in the response
  4. Testing:

    • Use the pinned test data to verify the workflow works correctly
    • Test both plain and interactive message types
    • Verify the numbered formatting appears correctly for interactive messages