Message Template Testing Workflow¶
This workflow provides a deterministic template selection system for generating contextually appropriate messages. It replaces LLM-based template selection with keyword-based matching to ensure consistent, reliable message generation from a comprehensive template library.
Purpose¶
No business context provided yet — add a context.md to enrich this documentation.
How It Works¶
- Input Reception: The workflow receives instructions through an Execute Workflow Trigger that accepts a single parameter called "instructions"
- Template Database Loading: A comprehensive message template library is loaded into memory, containing structured templates organized by phases, steps, and message types
- Intelligent Template Selection: A JavaScript-based selector analyzes the input instructions using keyword matching and scoring algorithms to identify the most appropriate template section
- Template Extraction: The system extracts the relevant template content from the matched section, prioritizing code blocks (```-wrapped content) over general section text
- Placeholder Substitution: Common placeholders like
[Name]and[firstName]are automatically replaced with actual data when available - Output Formatting: The final template is formatted and returned as the workflow output
Workflow Diagram¶
graph TD
A[messageTemplatedb<br/>Execute Workflow Trigger] --> B[db<br/>Set Template Library]
B --> C[Template Selector<br/>JavaScript Code]
C --> D[Edit Fields<br/>Format Output]
A -.->|instructions| B
B -.->|messagTemplates| C
C -.->|selected template| D
D -.->|formatted output| E[End]
Trigger¶
Execute Workflow Trigger - This workflow is designed to be called by other workflows. It accepts one input parameter:
- instructions - Text containing context, step numbers, or keywords that help identify the appropriate message template
Nodes Used¶
| Node Type | Node Name | Purpose |
|---|---|---|
| Execute Workflow Trigger | messageTemplatedb | Receives input instructions from calling workflows |
| Set | db | Stores the comprehensive message template library in memory |
| Code (JavaScript) | Template Selector | Analyzes instructions and selects the best matching template using keyword scoring |
| Set | Edit Fields | Formats the final output for return to the calling workflow |
External Services & Credentials Required¶
This workflow is entirely self-contained and requires no external services or credentials.
Environment Variables¶
No environment variables are required for this workflow.
Data Flow¶
Input:
- instructions (string) - Context or keywords describing the desired message template
Processing: - Template library loaded from static data - Keyword-based scoring algorithm matches instructions to template sections - Template extraction prioritizes structured content blocks - Automatic placeholder substitution when data is available
Output:
- output (string) - The selected and formatted message template ready for use
Error Handling¶
The workflow includes built-in fallback mechanisms: - If no template match is found, returns a fallback message: "No matching template found. Please generate an appropriate message based on the context." - Placeholder substitution errors are silently ignored to prevent workflow failures - Template extraction gracefully handles sections without code blocks by returning cleaned section text
Known Limitations¶
Based on the template library structure, this workflow is specifically designed for: - Multi-phase messaging systems (Phases 2-6) - Swahili/English mixed language (Sheng) communication - Business coaching and profit tracking contexts - Sequential step-based interactions
The template matching relies on keyword presence and may not handle completely novel instruction patterns outside the predefined template scope.
Related Workflows¶
This workflow is designed to be called by other workflows in the system that need consistent message generation. It serves as a centralized template service for: - Daily profit tracking workflows - Customer credit recovery processes - Weekly reporting systems - Business coaching interaction flows
Setup Instructions¶
-
Import the Workflow: Copy the workflow JSON and import it into your n8n instance
-
Verify Template Library: Ensure the
dbnode contains the complete message template library with all phases and steps -
Test the Workflow:
- Execute with sample instructions like "step 2.1" or "credit module intro"
- Verify that appropriate templates are returned
- Check placeholder substitution works with test data
-
Integration Setup:
- Configure calling workflows to use the Execute Workflow node
- Pass appropriate instruction strings that match template keywords
- Handle the returned output in your message generation logic
-
Customization:
- Modify the template library in the
dbnode to match your specific use case - Adjust keyword matching logic in the Template Selector if needed
- Add additional placeholder substitution rules as required
- Modify the template library in the
The workflow is ready to use immediately after import, requiring no additional configuration or credentials.