Skip to content

V4 - messageTemplates

A deterministic template selector workflow that replaces LLM calls with keyword-based template lookup for the SIFA coaching program's messaging system. This workflow provides structured message templates for different phases of youth business coaching, from onboarding through profit tracking and credit recovery.

Purpose

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

How It Works

  1. Trigger Reception: The workflow receives instructions through an Execute Workflow Trigger, typically containing step numbers, phase identifiers, or template requests
  2. Template Database Loading: A comprehensive message template library is loaded containing structured templates for all coaching phases (onboarding, practice, profit tracking, credit recovery, weekly reports)
  3. Intelligent Template Selection: A JavaScript-based selector analyzes the input instructions using keyword matching and scoring to identify the most relevant template section
  4. Template Extraction: The system extracts the appropriate message template from the matched section, handling both exact templates (Phase 2) and generated templates (Phase 3+)
  5. Data Substitution: Common placeholders like [Name] and [firstName] are automatically substituted with actual data when available
  6. Output Formatting: The final template is formatted and returned for use by the main messaging system

Workflow Diagram

graph TD
    A[messageTemplatedb<br/>Execute Workflow Trigger] --> B[db<br/>Set Node<br/>Load Template Library]
    B --> C[Template Selector<br/>Code Node<br/>Keyword-Based Matching]
    C --> D[Edit Fields<br/>Set Node<br/>Format Output]

    style A fill:#e1f5fe
    style B fill:#f3e5f5
    style C fill:#fff3e0
    style D fill:#e8f5e8

Trigger

Execute Workflow Trigger - Activated when called by other workflows with input parameters containing: - instructions: Text containing step numbers, phase identifiers, or template requests

Nodes Used

Node Type Node Name Purpose
Execute Workflow Trigger messageTemplatedb Receives instructions from calling workflows
Set db Stores the comprehensive message template library with all coaching phases
Code (JavaScript) Template Selector Performs keyword-based template matching and selection logic
Set Edit Fields Formats and outputs the selected template

External Services & Credentials Required

None - This workflow operates entirely with internal template matching and does not require external API calls or credentials.

Environment Variables

No environment variables are required for this workflow.

Data Flow

Input: - instructions (string): Contains step numbers, phase identifiers, or template requests

Output: - output (string): The selected and formatted message template ready for use

Internal Processing: - Template library containing structured messages for all coaching phases - Keyword scoring system for template selection - Automatic placeholder substitution

Error Handling

The workflow includes built-in fallback mechanisms: - If no matching template is found, returns a fallback message indicating no match - Template extraction handles both code block formats and plain text sections - Placeholder substitution errors are silently ignored to prevent workflow failures - The error workflow cuHEGQjAfvuGwIOD is configured to handle any unexpected failures

Known Limitations

Based on the template structure, this workflow has specific operational constraints: - Phase 2 templates must be reproduced exactly (EXACT mode) - Phase 3+ templates serve as structural guides (GENERATED mode) - Template selection relies on keyword matching which may not capture complex contextual requirements - Limited to predefined template structures and cannot generate entirely new message formats

This workflow is designed to be called by other workflows in the SIFA coaching system, particularly those handling: - Daily profit tracking interactions - Credit recovery messaging - Weekly report generation - Youth onboarding processes

Setup Instructions

  1. Import the Workflow

    • Copy the workflow JSON and import it into your n8n instance
    • Ensure the workflow ID matches any calling workflows
  2. Configure Error Handling

    • Verify the error workflow cuHEGQjAfvuGwIOD exists in your instance
    • Update the error workflow ID if necessary
  3. Template Customization

    • Review the template library in the db node
    • Modify templates to match your specific coaching program requirements
    • Ensure template structure follows the EXACT/GENERATED mode rules
  4. Integration Setup

    • Configure calling workflows to pass appropriate instructions parameters
    • Test template selection with various step numbers and phase identifiers
    • Verify placeholder substitution works with your data structure
  5. Testing

    • Test with sample instructions containing step numbers (e.g., "step 2.1", "template 4A.5")
    • Verify fallback behavior when no templates match
    • Confirm output format meets the requirements of consuming workflows