Message Templates Workflow¶
This workflow provides a deterministic template selection system for generating contextually appropriate messages in the Sifa coaching program. It replaces LLM-based template selection with a keyword-matching algorithm that selects the most relevant message template from a comprehensive library covering all phases of the youth business coaching journey.
Purpose¶
No business context provided yet — add a context.md to enrich this documentation.
How It Works¶
-
Input Reception: The workflow receives instructions containing context about what type of message needs to be generated (step numbers, phase identifiers, keywords)
-
Template Database Loading: A comprehensive message template library is loaded containing structured templates for all phases of the Sifa coaching program (onboarding, practice, daily tracking, credit recovery, weekly reports)
-
Keyword-Based Matching: The Template Selector node analyzes the input instructions against the template library using a scoring system that matches:
- Step numbers (e.g., "2.1", "3.6")
- Phase identifiers (e.g., "phase 4a", "credit module")
- Context keywords (e.g., "sales", "expenses", "recovery")
-
Template Extraction: The highest-scoring template section is selected, and the actual message template is extracted from code blocks within that section
-
Placeholder Substitution: Common placeholders like
[Name]and[firstName]are automatically substituted with available data -
Output Formatting: The final template is returned as structured output ready for message generation
Workflow Diagram¶
graph TD
A[messageTemplatedb - Workflow Trigger] --> B[db - Template Database]
B --> C[Template Selector - Keyword Matching]
C --> D[Edit Fields - Output Formatting]
A -.->|instructions| B
B -.->|messagTemplates| C
C -.->|matched template| D
D -.->|formatted output| E[End]
Trigger¶
This workflow is triggered by other workflows in the system via the Execute Workflow Trigger node. It expects an input parameter called instructions containing the context for template selection.
Nodes Used¶
| Node Type | Node Name | Purpose |
|---|---|---|
| Execute Workflow Trigger | messageTemplatedb | Receives input parameters from calling workflows |
| Set | db | Stores the comprehensive message template library as static data |
| Code | Template Selector | Implements keyword-based scoring algorithm to match instructions to templates |
| Set | Edit Fields | Formats the selected template as the final output |
External Services & Credentials Required¶
This workflow operates entirely with internal n8n functionality and requires no external services or credentials.
Environment Variables¶
No environment variables are required for this workflow.
Data Flow¶
Input:
- instructions (string): Context describing the type of message needed, including step numbers, phase identifiers, and relevant keywords
Output:
- output (string): The selected message template with basic placeholder substitutions applied
Internal Data:
- messagTemplates (string): Comprehensive template library containing structured message templates for all coaching phases
- Scoring algorithm results and template extraction logic
Error Handling¶
The workflow includes basic error handling: - If no matching template is found, it returns a fallback message indicating no match was found - Placeholder substitution errors are silently ignored to prevent workflow failures - The scoring algorithm gracefully handles malformed input by defaulting to zero scores
Known Limitations¶
Based on the template library structure, this workflow has several constraints: - Templates are designed specifically for the Sifa coaching program's phases and may not be suitable for other contexts - The keyword matching algorithm may not capture nuanced context that an LLM might understand - Placeholder substitution is limited to basic name fields and doesn't handle complex data transformations - The template library is static and requires manual updates to add new message types
Related Workflows¶
This workflow is designed to be called by other workflows in the Sifa coaching system that need to generate contextually appropriate messages for youth participants.
Setup Instructions¶
-
Import the Workflow: Import the JSON into your n8n instance
-
Verify Template Library: Ensure the
dbnode contains the complete message template library with all coaching phases -
Test Template Selection:
- Test with various instruction formats (e.g., "step 2.1", "credit module intro")
- Verify that appropriate templates are selected for different contexts
-
Configure Calling Workflows: Set up other workflows to call this one using the Execute Workflow node with proper
instructionsparameter -
Monitor Performance: Check that the keyword matching algorithm performs adequately for your use cases and adjust scoring weights if needed
-
Update Templates: Regularly review and update the template library in the
dbnode as coaching program requirements evolve