Daily Nudge System — BASELINE¶
This workflow sends automated daily nudges to youth entrepreneurs at 7PM and 8PM via SMS or WhatsApp, encouraging them to track their business sales and profits. It operates as a baseline measurement system, logging all nudge decisions for analysis while not actually sending messages to users.
Purpose¶
No business context provided yet — add a context.md to enrich this documentation.
How It Works¶
The workflow operates on two daily schedules (7PM and 8PM) and follows this process:
- Schedule Triggers: At 7PM and 8PM daily, the workflow checks if it's Sunday (skips execution on Sundays)
- Baseline Logging: Creates a baseline run record via webhook for tracking purposes
- User Fetching: Retrieves active users from the database, including both regular users and internal team members
- Channel Detection: For each user, determines whether they prefer WhatsApp or SMS communication
- Chat History Analysis: For WhatsApp users, checks recent chat activity to avoid duplicate messaging
- Message Generation: Creates personalized nudge messages asking about daily sales or profits
- Decision Logging: Records all nudge decisions (channel choice, message content, eligibility) via webhook
- Database Storage: Saves nudge messages to chat history for tracking purposes
The workflow processes three user groups: - 7PM Regular Users: Active entrepreneurs who onboarded before today - 7PM Internal Team: Internal team members for testing - 8PM All Users: Combined processing with enhanced chat history filtering
Mermaid Diagram¶
graph TD
A[7PM Nudge Trigger] --> B[Create Baseline Run 7PM]
C[8PM Nudge Trigger] --> D[Create Baseline Run 8PM]
B --> E{Is Sunday? 7PM}
D --> F{Is Sunday? 8PM}
E -->|No| G[Flag Evening Session Started]
F -->|No| H[Fetch Active Users 8PM]
G --> I[Fetch Active Users 7PM]
G --> J[Fetch Internal Team Users]
I --> K[Dedup Users 7PM]
J --> L[Dedup Users Internal]
H --> M[Dedup Users 8PM]
K --> N{Is WhatsApp User? 7PM}
L --> O{Is WhatsApp User? Internal}
M --> P[Loop Users 8PM]
N -->|Yes| Q[Loop WhatsApp Users 7PM]
N -->|No| R[Loop SMS Users 7PM]
O -->|Yes| S[Loop WhatsApp Users Internal]
O -->|No| T[Loop SMS Users Internal]
P --> U[Fetch Chat History 8PM]
U --> V{Has Chat Data? 8PM}
V -->|No| W{Is WhatsApp User? 8PM}
Q --> X[Fetch Last WhatsApp ChatLog 7PM]
R --> Y[Set SMS Nudge - Sales Question 7PM]
S --> Z[Fetch Last WhatsApp ChatLog Internal]
T --> AA[Set SMS Nudge - Sales Question Internal]
W -->|Yes| BB[Fetch Last WhatsApp ChatLog 8PM]
W -->|No| CC[Set SMS Nudge - Sales Question 8PM]
X --> DD{Has WhatsApp ChatLog? 7PM}
Z --> EE{Has WhatsApp ChatLog? Internal}
BB --> FF{Has WhatsApp ChatLog? 8PM}
DD -->|Yes| GG{ChatLog Within 24hrs? 7PM}
EE -->|Yes| HH{ChatLog Within 24hrs? Internal}
FF -->|Yes| II{ChatLog Within 24hrs? 8PM}
GG -->|No| JJ[Set SMS Nudge - Profit Question 7PM]
HH -->|No| KK[Set SMS Nudge - Profit Question Internal]
II -->|No| LL[Set SMS Nudge - Profit Question 8PM]
Y --> MM[POST Decision 7PM SMS]
AA --> NN[POST Decision Internal SMS]
CC --> OO[POST Decision 8PM SMS]
JJ --> PP[POST Decision 7PM WhatsApp]
KK --> QQ[POST Decision Internal WhatsApp]
LL --> RR[POST Decision 8PM WhatsApp]
MM --> SS[Save Nudge to DB 7PM SMS]
PP --> TT[Save Nudge to DB 7PM WhatsApp]
NN --> UU[Save Nudge to DB Internal SMS]
QQ --> VV[Save Nudge to DB Internal WhatsApp]
OO --> WW[Save Nudge to DB 8PM SMS]
RR --> XX[Save Nudge to DB 8PM WhatsApp]
Trigger¶
- Schedule Trigger (7PM): Runs daily at 7:00 PM
- Schedule Trigger (8PM): Runs daily at 8:00 PM
- Sunday Skip: Both triggers skip execution on Sundays (weekday = 7)
Nodes Used¶
| Node Type | Count | Purpose |
|---|---|---|
| Schedule Trigger | 2 | Daily execution at 7PM and 8PM |
| Postgres | 15 | Database queries for users, chat logs, and data storage |
| HTTP Request | 10 | Webhook calls for baseline run creation and decision logging |
| If (Conditional) | 12 | Logic branching for user types, chat history, and day checking |
| Set | 6 | Message content preparation for different nudge variants |
| Split in Batches | 5 | User processing loops |
| Remove Duplicates | 3 | User deduplication by phone number |
| Filter | 1 | Recent chat filtering (within 60 minutes) |
| Aggregate | 1 | Chat data consolidation |
| No Operation | 1 | Data passthrough |
External Services & Credentials Required¶
Database Credentials¶
- Postgres account 2: Database connection for user data, chat logs, and nudge storage
- Required tables:
youthEntrepreneursReal,youthProgressReport,chatLog,n8n_chat_histories
- Required tables:
Webhook Endpoints¶
- Baseline Run Creation:
https://sifa.alpha-test.kriftx.app/webhooks/baseline/nudge-run/[token] - Decision Logging:
https://sifa.alpha-test.kriftx.app/webhooks/baseline/nudge-decision/[token]
Environment Variables¶
No explicit environment variables are used. Configuration is embedded in node parameters:
- Webhook URLs with authentication tokens
- Database connection details via credentials
- WhatsApp contact URL: https://wa.me/254203892316
Data Flow¶
Input¶
- User Data: Phone numbers, names, business info, onboarding status from database
- Chat History: Recent WhatsApp interactions and SMS chat logs
- Trigger Time: 7PM or 8PM execution context
Processing¶
- User eligibility filtering (onboarded before today, not 'new' status)
- Channel preference detection (WhatsApp vs SMS)
- Recent activity analysis (24-hour and 60-minute windows)
- Personalized message generation with user names
Output¶
- Baseline Run Records: Execution tracking via webhook
- Decision Logs: Channel choices, message content, user eligibility via webhook
- Chat History: Nudge messages stored in
n8n_chat_historiestable - Database Updates: Evening session flags in user records
Error Handling¶
The workflow includes several error handling mechanisms:
- Continue on Error: Most database operations use
continueRegularOutputorcontinueErrorOutput - Never Error Responses: HTTP requests configured with
neverError: truefor webhook calls - Always Output Data: Critical nodes marked to ensure workflow continuation
- Graceful Degradation: Missing chat logs or user data don't stop processing
- Fallback Paths: Alternative message variants when primary conditions aren't met
Known Limitations¶
Based on the workflow structure:
- Sunday Exclusion: No nudges sent on Sundays
- Timezone Dependency: Uses Africa/Nairobi timezone for day calculations
- No Actual Sending: This is a baseline measurement system - messages are logged but not delivered
- Internal Team Filtering: Some queries exclude internal team members while others include them
- Chat History Dependency: WhatsApp logic relies on chatLog table availability
Related Workflows¶
No related workflows mentioned in the provided context.
Setup Instructions¶
-
Import Workflow: Import the JSON into your n8n instance
-
Configure Database Credentials:
- Create PostgreSQL connection named "Postgres account 2"
- Ensure access to required tables:
youthEntrepreneursReal,youthProgressReport,chatLog,n8n_chat_histories
-
Set Up Webhook Endpoints:
- Configure baseline run creation webhook URL
- Configure decision logging webhook URL
- Ensure authentication tokens are properly embedded
-
Verify Database Schema:
youthEntrepreneursReal: phoneNumber, firstName, channel, businessOwned, preferredTime, eveningSessionStartedyouthProgressReport: phoneNumber, onboardingStatus, onboardedAtchatLog: userPhone, channel, created_atn8n_chat_histories: session_id, message, created_time
-
Test Execution:
- Manually trigger to verify database connections
- Check webhook endpoints respond correctly
- Validate timezone settings for Africa/Nairobi
-
Activate Workflow: Enable the workflow for daily execution at 7PM and 8PM
-
Monitor Logs: Check execution history and webhook responses for proper baseline data collection