Message Templates Workflow¶
This workflow serves as an AI-powered message template generator for Sifa, a business coaching chatbot that helps young entrepreneurs in Kenya track profits and recover debts. It takes contextual instructions about conversation states and generates appropriate WhatsApp/SMS messages in Sheng (Swahili/English mix) that match Sifa's warm, peer-like coaching tone.
Purpose¶
No business context provided yet — add a context.md to enrich this documentation.
This workflow supports Sifa's core mission of helping young Kenyan entrepreneurs grow their businesses through daily profit tracking and debt recovery coaching. When the main Sifa chatbot needs to send a message to a youth, it calls this workflow with context about the conversation stage (e.g., "daily sales collection Day 1" or "credit module intro"). The workflow then generates culturally appropriate, contextually relevant messages that maintain Sifa's consistent voice across all interactions.
The workflow serves business coaches, program administrators, and ultimately the young entrepreneurs who receive these carefully crafted messages that guide them through their business development journey.
How It Works¶
- Receive Instructions: The workflow is triggered with specific instructions about what type of message is needed, including conversation context, stage, and any relevant user data
- Load Template Database: A comprehensive database of message templates is loaded, containing over 80 different message patterns organized by coaching phases (onboarding, daily tracking, credit recovery, weekly reports)
- AI Processing: An AI agent analyzes the instructions against the template library to select the most appropriate template pattern
- Message Generation: The AI adapts the selected template to the specific context, filling in variables, matching the youth's communication style, and ensuring the message follows Sifa's tone guidelines
- Output Formatting: The final message is formatted and returned, ready to be sent via WhatsApp or SMS
Workflow Diagram¶
graph TD
A[Execute Workflow Trigger] --> B[Load Message Templates Database]
B --> C[AI Agent Processing]
C --> D[OpenRouter Chat Model]
D --> C
C --> E[Format Output]
A --> |instructions| B
B --> |template library| C
C --> |generated message| E
E --> |final output| F[Return to Caller]
Trigger¶
This workflow is triggered by other n8n workflows via the "Execute Workflow Trigger" node. It expects an input parameter called instructions that contains:
- The conversation stage/context
- User information (name, business type, etc.)
- Specific requirements for the message (tone, length, channel)
- Any data that needs to be included in the message
Nodes Used¶
| Node Type | Node Name | Purpose |
|---|---|---|
| Execute Workflow Trigger | messageTemplatedb | Receives instructions from calling workflows |
| Set | db | Loads the comprehensive message template database with 80+ templates |
| LangChain AI Agent | AI Agent | Processes instructions and generates contextually appropriate messages |
| OpenRouter Chat Model | OpenRouter Chat Model | Provides GPT-5.3 language model capabilities for message generation |
| Set | Edit Fields | Formats the final output for return to the calling workflow |
| Set | db1 | Contains an alternative template database structure (appears unused in current flow) |
External Services & Credentials Required¶
- OpenRouter API: Provides access to GPT-5.3 chat model for AI message generation
- Credential: "OpenRouter account"
- Required for the AI Agent to function
Environment Variables¶
No environment variables are explicitly configured in this workflow. All configuration is handled through the OpenRouter credentials and the embedded template database.
Data Flow¶
Input:
- instructions (string): Contextual information about the required message, including conversation stage, user details, and specific requirements
Processing: - Template database containing 80+ message patterns across 8 sections (onboarding, daily tracking, motivational messages, credit module, etc.) - AI analysis to select and adapt the most appropriate template - Message generation following Sifa's tone guidelines (warm, peer-like, Sheng language mix)
Output:
- output (string): A fully formatted message ready for delivery via WhatsApp or SMS, culturally appropriate and contextually relevant
Error Handling¶
The workflow does not implement explicit error handling nodes. Error management relies on: - The AI Agent's built-in error handling for malformed inputs - OpenRouter API's standard error responses - n8n's default workflow error handling mechanisms
Known Limitations¶
Based on the template database structure, known limitations include: - Messages are optimized for Kenyan context and may not translate well to other regions - The workflow assumes familiarity with Sheng (Swahili/English mix) language patterns - Template selection depends on accurate context provided in instructions - No fallback mechanism if the AI fails to generate appropriate content
Related Workflows¶
This workflow is designed to be called by other Sifa chatbot workflows that handle: - Main conversation flow management - User data tracking and storage - Message delivery via WhatsApp/SMS channels - Business coaching program progression
Setup Instructions¶
-
Import Workflow: Import the JSON configuration into your n8n instance
-
Configure Credentials:
- Set up OpenRouter API credentials with access to GPT-5.3-chat model
- Ensure the credential is named "OpenRouter account" to match the workflow configuration
-
Verify Template Database:
- Review the message templates in the "db" node to ensure they match your use case
- Modify templates if needed for different cultural contexts or business models
-
Test Integration:
- Create a test workflow that calls this one with sample instructions
- Verify that generated messages match expected tone and content
-
Connect to Main System:
- Integrate with your main chatbot workflow using the Execute Workflow node
- Ensure proper instruction formatting for consistent results
-
Monitor Performance:
- Track AI generation quality and adjust system prompts if needed
- Monitor OpenRouter API usage and costs