V4 - MorningCheckInHandler - Warenga¶
This workflow handles morning check-ins for business coaching participants, processing their responses about micro-actions they attempted the previous day. It intelligently routes users through different conversation flows based on their emotional state and micro-action outcomes, while awarding engagement points.
Purpose¶
No business context provided yet — add a context.md to enrich this documentation.
How It Works¶
- Context Retrieval: Fetches user information including their current micro-action, business details, and coaching level from the database
- Emotional Safety Check: Scans the user's message for distress keywords and routes to emotional support if needed
- Response Matching: Attempts to match the user's response to predefined outcome options (C1-C7 for credit actions, P1-P5 for profit actions)
- Smart Routing: Based on the match result:
- If emotional distress detected → Routes to EmotionalSupportHandler
- If outcome matched → Routes to appropriate handler (Credit or Profit) and awards 5 points
- If no match → Presents interactive list of options
- Fallback Handling: For users without current micro-actions, uses their first micro-action or provides general encouragement
Workflow Diagram¶
graph TD
A[When Executed by Another Workflow] --> B[Get User Context]
B --> C[Parse & Route]
C --> D[Route]
D --> E[Call EmotionalSupportHandler]
D --> F[Credit or Profit?]
D --> G[Present List]
F --> H[Call Credit Path]
F --> I[Call ProfitOutcomeHandler]
H --> J[Award 5pts Morning]
H --> K[Outcome Output]
I --> J
I --> K
Trigger¶
Execute Workflow Trigger - This workflow is called by other workflows with the following inputs:
- phoneNumber: User's phone number
- query: User's message/response
- channel: Communication channel (WhatsApp, SMS, etc.)
Nodes Used¶
| Node Type | Node Name | Purpose |
|---|---|---|
| Execute Workflow Trigger | When Executed by Another Workflow | Receives input parameters from calling workflow |
| PostgreSQL | Get User Context | Fetches user session context from database |
| Code | Parse & Route | Analyzes user input and determines routing logic |
| Switch | Route | Routes to different paths based on analysis results |
| If | Credit or Profit? | Determines whether to use credit or profit outcome handler |
| Execute Workflow | Call EmotionalSupportHandler | Handles users showing emotional distress |
| Execute Workflow | Call Credit Path | Processes credit-related micro-action outcomes |
| Execute Workflow | Call ProfitOutcomeHandler | Processes profit-related micro-action outcomes |
| Execute Workflow | Award 5pts Morning | Awards engagement points for participation |
| Code | Outcome Output | Formats final response output |
| Code | Present List | Creates interactive option list for users |
External Services & Credentials Required¶
- PostgreSQL Database: Stores user context and session data
- Credential:
sifaV4Dev - Used for: Retrieving user micro-actions, business info, and coaching levels
- Credential:
Environment Variables¶
No specific environment variables are documented in this workflow.
Data Flow¶
Input:
- phoneNumber (string): User identifier
- query (string): User's response message
- channel (string): Communication channel
Output:
- output (string): Response message to send to user
- outputType (string): Type of response ('plain' or 'interactive')
- outputOptions (array): Available options for interactive responses
Error Handling¶
The workflow includes basic error handling through: - Fallback values for missing user data (defaults to 'rafiki', 'biashara', 'Kifaru') - Graceful handling of users without micro-actions - Default responses when outcome processing fails
Known Limitations¶
Based on the workflow implementation: - Emotional keyword detection is limited to predefined Swahili phrases - Outcome matching relies on exact text matching which may miss variations - Day 1 users without current micro-actions fall back to first micro-action - No handling for users who haven't started any micro-actions
Related Workflows¶
This workflow calls several other workflows: - EmotionalSupportHandler (ID: RbLs1LNSKF4BY9fi) - Handles emotional distress - Credit Path (ID: Qw5luvKnAzENQsMB) - Processes credit outcome responses - ProfitOutcomeHandler (ID: xnOnTy0r35KDaYEk) - Processes profit outcome responses - Award Points Tool (ID: JmJObsTea34h5bjX) - Awards engagement points
Setup Instructions¶
- Import the workflow into your n8n instance
- Configure PostgreSQL credentials:
- Create a PostgreSQL connection named
sifaV4Dev - Ensure it has access to the user context function
get_session_context_v4
- Create a PostgreSQL connection named
- Set up dependent workflows:
- Import and configure EmotionalSupportHandler
- Import and configure Credit Path workflow
- Import and configure ProfitOutcomeHandler
- Import and configure Award Points Tool
- Update workflow references:
- Verify all Execute Workflow nodes point to correct workflow IDs
- Test connections between workflows
- Database setup:
- Ensure the
get_session_context_v4function exists in your PostgreSQL database - Verify user context data structure matches expected format
- Ensure the
- Test the workflow:
- Execute with sample data to verify all paths work correctly
- Test emotional keyword detection
- Verify outcome matching logic
- Confirm point awarding functionality