Skip to content

V4 - DailyTrackingRouter - Warenga

This workflow serves as the central routing hub for the Warenga coaching system, intelligently directing user messages to specialized handlers based on their current context, emotional state, and interaction history. It acts as the traffic controller that ensures users receive the most appropriate response whether they need emotional support, are in the middle of daily check-ins, or require general coaching assistance.

Purpose

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

How It Works

  1. Receives Input: The workflow is triggered by another workflow (typically Francis, the main message handler) with a user's phone number, message query, and communication channel
  2. Fetches User Context: Queries the PostgreSQL database to retrieve comprehensive user information including their current emotional state, recent interactions, micro-actions, and coaching progress
  3. Analyzes and Routes: Processes the user context and message content to determine the most appropriate handler, following a priority system:
    • Explicit commands (MENU, HELP) take highest priority
    • Emotional pause status overrides other routing
    • Active coaching sessions (credit, daily check-ins) are prioritized
    • General coaching serves as the fallback
  4. Executes Handler: Routes to one of nine specialized workflows based on the determined path
  5. Handles Fallback: For general queries, prepares enriched context data before routing to the main coaching agent

Workflow Diagram

graph TD
    A[When Executed by Another Workflow] --> B[Get User Context]
    B --> C[Parse & Route]
    C --> D[Route Switch]

    D --> E[Call EmotionalSupportHandler]
    D --> F[Call MorningCheckInHandler]
    D --> G[Call MiddayPeerTipHandler]
    D --> H[Call EveningWrapHandler]
    D --> I[Call MorningCheckInHandler Credit Followup]
    D --> J[Call Credit Path]
    D --> K[Call MenuHandler]
    D --> L[Call HelpHandler]
    D --> M[Build CA Inputs]

    M --> N[Call CoachingAgent]

Trigger

Execute Workflow Trigger: Accepts three input parameters from calling workflows: - phoneNumber: User's phone number for identification - query: The user's message content - channel: Communication channel (SMS, WhatsApp, etc.)

Nodes Used

Node Type Node Name Purpose
Execute Workflow Trigger When Executed by Another Workflow Receives input from calling workflows
PostgreSQL Get User Context Retrieves user data and session context from database
Code Parse & Route Analyzes user context and determines routing logic
Switch Route Directs flow to appropriate handler based on routing decision
Execute Workflow Call EmotionalSupportHandler Handles users in emotional pause state
Execute Workflow Call MorningCheckInHandler Processes morning check-in interactions
Execute Workflow Call MiddayPeerTipHandler Manages midday peer tip sessions
Execute Workflow Call EveningWrapHandler Handles evening wrap-up conversations
Execute Workflow Call MorningCheckInHandler (Credit Followup) Processes credit-related follow-ups
Execute Workflow Call Credit Path Manages credit session workflows
Execute Workflow Call MenuHandler Processes menu navigation requests
Execute Workflow Call HelpHandler Handles help and support requests
Code Build CA Inputs Prepares context data for general coaching agent
Execute Workflow Call CoachingAgent Handles general coaching conversations

External Services & Credentials Required

PostgreSQL Database

  • Credential Name: sifaV4Dev
  • Purpose: Stores user profiles, session context, micro-actions, and coaching progress
  • Required Permissions: Read access to user tables and session context functions

Connected Workflows

  • EmotionalSupportHandler (ID: RbLs1LNSKF4BY9fi)
  • MorningCheckInHandler (ID: ols16yA9tt6dZbhR)
  • MiddayPeerTipHandler (ID: CFyq1K8XW5XhIPha)
  • EveningWrapHandler (ID: NDoAphb3YdWIk2w3)
  • Credit Path (ID: Qw5luvKnAzENQsMB)
  • MenuHandler (ID: zHz74QAFHsQ1NzzO)
  • HelpHandler (ID: IujrgiCJrgrDY3rX)
  • CoachingAgent (ID: Bz0GPL2vYbDw8ygf)

Environment Variables

No specific environment variables are required for this workflow. All configuration is handled through n8n's credential system and workflow connections.

Data Flow

Input Data

1
2
3
4
5
{
  "phoneNumber": "string",
  "query": "string", 
  "channel": "string"
}

Processing Data (Internal)

The workflow enriches the input with user context including: - User profile information (name, onboarding status, SIFA level) - Emotional state and pause status - Current micro-actions and business ownership - Recent interaction history and nudge steps - Timezone-adjusted timestamps

Output Data

Varies by route, but typically includes the original input plus any additional context required by the target handler workflow.

Error Handling

The workflow includes basic error handling through: - Fallback Routing: If no specific route matches, defaults to the general CoachingAgent - Null Safety: Code nodes handle missing or null user data gracefully with default values - Database Error Tolerance: If user context retrieval fails, the workflow can still route based on available input data

Known Limitations

  • Routing logic is hardcoded and requires workflow updates to modify routing rules
  • Database dependency means the workflow cannot function if PostgreSQL is unavailable
  • No built-in retry mechanism for failed sub-workflow calls
  • Timezone handling is fixed to Africa/Nairobi (EAT)

This workflow serves as a central hub connecting to multiple specialized handlers: - Francis: The main message ingestion workflow that typically calls this router - EmotionalSupportHandler: Provides specialized support for users in emotional distress - Daily Check-in Handlers: Morning, midday, and evening interaction workflows - Credit Path: Manages financial coaching and credit-related conversations - Menu/Help Handlers: Process navigation and support requests - CoachingAgent: The main AI-powered coaching conversation handler

Setup Instructions

  1. Import Workflow: Import the JSON into your n8n instance
  2. Configure Database Credential:
    • Create a PostgreSQL credential named sifaV4Dev
    • Ensure it has access to the user context function get_session_context_v4
  3. Link Connected Workflows:
    • Verify all referenced workflow IDs exist in your instance
    • Update workflow IDs in Execute Workflow nodes if needed
  4. Test Database Connection:
    • Execute the "Get User Context" node with a test phone number
    • Verify the context function returns expected user data structure
  5. Validate Routing Logic:
    • Test with different user states and message types
    • Ensure each route directs to the correct handler workflow
  6. Activate Workflow: Enable the workflow once all connections are verified