V4 - messageTemplates¶
A deterministic template selector workflow that replaces LLM calls with keyword-based template lookup for Sifa's messaging system. This workflow processes instructions and returns the most appropriate message template from a comprehensive library of pre-written responses.
Purpose¶
No business context provided yet — add a context.md to enrich this documentation.
How It Works¶
- Trigger Reception: The workflow receives instructions through an Execute Workflow Trigger, typically containing step numbers, phase identifiers, or contextual keywords
- Template Database Loading: A comprehensive message template library is loaded containing all Sifa's standardized responses organized by phases and steps
- Intelligent Template Selection: A JavaScript-based selector analyzes the input instructions against the template library using keyword matching and scoring
- Template Extraction: The best matching template is extracted from the library, with code blocks and formatting preserved
- Data Substitution: Common placeholders like
[Name]and[firstName]are automatically substituted with actual data when available - Output Formatting: The selected template is formatted and returned as the workflow output
Mermaid Diagram¶
graph TD
A[messageTemplatedb<br/>Execute Workflow Trigger] --> B[db<br/>Set Node]
B --> C[Template Selector<br/>Code Node]
C --> D[Edit Fields<br/>Set Node]
Trigger¶
Execute Workflow Trigger - Activated when called by other workflows with input parameters containing:
- instructions: Text containing step numbers, phase identifiers, or contextual keywords for template selection
Nodes Used¶
| Node Type | Node Name | Purpose |
|---|---|---|
| Execute Workflow Trigger | messageTemplatedb | Receives instructions from calling workflows |
| Set | db | Stores the comprehensive message template library |
| Code | Template Selector | Performs keyword-based template matching and selection |
| Set | Edit Fields | Formats and outputs the selected template |
External Services & Credentials Required¶
None - this workflow operates entirely with internal logic and stored templates.
Environment Variables¶
None required.
Data Flow¶
Input:
- instructions: String containing keywords, step numbers, or phase identifiers
Output:
- output: Selected message template with placeholders substituted where possible
Processing: - Keyword extraction and scoring against template sections - Step number and phase matching with high priority scoring - Template block extraction from markdown code blocks - Automatic placeholder substitution for common variables
Error Handling¶
The workflow includes graceful fallback handling: - If no matching template is found, returns a fallback message indicating no match - Placeholder substitution errors are silently ignored to prevent workflow failures - Invalid input gracefully defaults to returning instructions for manual handling
Known Limitations¶
- Template selection is based on keyword matching rather than semantic understanding
- Placeholder substitution is limited to common variables (
[Name],[firstName]) - Template library must be manually maintained within the workflow
- No dynamic template generation - relies entirely on pre-written content
Related Workflows¶
This workflow is designed to be called by other Sifa messaging workflows that need to retrieve appropriate message templates based on context.
Setup Instructions¶
- Import Workflow: Import the JSON configuration into your n8n instance
- Verify Template Library: Check that the
dbnode contains the complete message template library - Test Template Selection: Run test executions with various instruction types to verify template matching
- Configure Calling Workflows: Ensure other workflows are configured to call this workflow with appropriate instruction parameters
- Monitor Performance: Verify that template selection is working correctly and returning expected outputs
The workflow is ready to use immediately after import, requiring no external credentials or environment configuration.