Skip to content

Message Templates Workflow

This workflow serves as an AI-powered message template generator for Sifa, a business coaching chatbot designed for young entrepreneurs in Kenya. It processes contextual instructions and generates appropriate WhatsApp/SMS messages in Sheng (Swahili/English mix) that match specific conversation stages and user needs.

Purpose

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

This workflow supports the Sifa coaching program by providing contextually appropriate message templates for different stages of the business coaching journey. The system helps maintain consistent, culturally appropriate communication while adapting to individual user situations and conversation contexts.

How It Works

  1. Input Processing: The workflow receives instructions describing the current conversation context, stage, and specific requirements for message generation
  2. Template Database Loading: Two comprehensive template databases are loaded containing message patterns for different phases (onboarding, daily tracking, credit recovery, weekly reports)
  3. AI Analysis: An AI agent analyzes the context and selects the most appropriate template pattern based on the conversation stage and user needs
  4. Message Generation: The AI adapts the selected template to generate a natural, contextually appropriate message in Sheng
  5. Output Formatting: The final message is formatted and returned for delivery to the user

Workflow Diagram

graph TD
    A[Execute Workflow Trigger] --> B[Load Message Templates DB]
    B --> C[AI Agent Processing]
    C --> D[OpenRouter Chat Model]
    D --> C
    C --> E[Edit Fields - Format Output]
    F[Load Extended Template DB] --> C

Trigger

This workflow is triggered by external calls with input parameters containing: - instructions: Detailed context about the conversation stage, user behavior, and message requirements

Nodes Used

Node Type Node Name Purpose
Execute Workflow Trigger messageTemplatedb Receives input instructions and starts the workflow
Set db Loads the primary message template database with phase-specific patterns
Set db1 Loads extended template database with additional message variants
AI Agent AI Agent Processes context and generates appropriate messages using template patterns
OpenRouter Chat Model OpenRouter Chat Model Provides GPT-5.3 language model capabilities for message generation
Set Edit Fields Formats and structures the final output

External Services & Credentials Required

  • OpenRouter API: Requires valid OpenRouter credentials for accessing GPT-5.3-chat model
    • Credential name: "OpenRouter account"
    • Used for: AI-powered message generation and template adaptation

Environment Variables

No specific environment variables are required for this workflow. All configuration is handled through the OpenRouter credentials and embedded template databases.

Data Flow

Input: - instructions: String containing conversation context, stage information, and specific message requirements

Processing: - Template databases containing message patterns for different coaching phases - AI analysis of context to select appropriate templates - Natural language generation to adapt templates to specific situations

Output: - output: Generated message text ready for delivery via WhatsApp or SMS

Error Handling

The workflow includes basic error handling through: - Template fallback mechanisms in the AI agent - Structured template databases with multiple variants for different scenarios - OpenRouter API error handling through n8n's built-in retry mechanisms

No explicit error nodes are present, but the AI agent is designed to handle edge cases by selecting appropriate fallback templates.

Known Limitations

Based on the template structure, known limitations include: - Messages are optimized for Kenyan context and Sheng language mix - Template selection depends on accurate context description in input instructions - Some templates require specific data placeholders that must be provided in the context - Voice note handling is not supported (templates include redirects to text input)

This workflow appears to be part of a larger Sifa coaching system. Related workflows likely include: - Main conversation handler that calls this template generator - User data management workflows - CEA (Community Enterprise Agent) notification systems - Weekly report generation workflows

Setup Instructions

  1. Import Workflow: Import the JSON workflow definition into your n8n instance

  2. Configure Credentials:

    • Set up OpenRouter API credentials
    • Name the credential "OpenRouter account"
    • Ensure access to GPT-5.3-chat model
  3. Template Database:

    • The template databases are embedded in the workflow
    • No external database setup required
    • Templates include patterns for onboarding, daily tracking, credit recovery, and reporting phases
  4. Testing:

    • Use the pinned test data as a reference for input format
    • Test with various instruction types to verify template selection
    • Validate output messages for appropriate tone and language
  5. Integration:

    • Configure calling workflows to pass properly formatted instruction parameters
    • Ensure output format matches expectations of downstream message delivery systems
    • Set up appropriate error handling in calling workflows
  6. Customization:

    • Modify template databases in the Set nodes to adjust message patterns
    • Update AI agent system prompts to change template selection logic
    • Adjust OpenRouter model settings if different language capabilities are needed