Skip to content

Check Nudge Channel and Send Daily Nudges

This workflow automatically sends daily engagement nudges to youth entrepreneurs through their preferred communication channel (WhatsApp or SMS), checking their recent activity to avoid over-messaging and personalizing content based on their interaction history.

Purpose

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

How It Works

  1. Scheduled Triggers: The workflow runs at 7 PM and 8 PM daily to send engagement nudges
  2. User Retrieval: Fetches active youth entrepreneurs from the database, excluding internal team members
  3. Duplicate Removal: Removes duplicate phone numbers to prevent multiple messages
  4. Channel Detection: Determines if users prefer WhatsApp or SMS based on their profile or recent chat history
  5. Activity Check: For WhatsApp users, checks if they've interacted within the last 24 hours to avoid spam
  6. Message Personalization: Creates personalized messages asking about daily sales/profits
  7. Multi-Channel Delivery: Sends via WhatsApp (Twilio) for engaged users or SMS (Africa's Talking) for others
  8. Chat History Logging: Records all sent messages in the chat history database
  9. Batch Processing: Processes users in batches to manage system load
  10. Onboarding Status Update: Updates user status to "active" after successful nudge delivery

Workflow Diagram

graph TD
    A[7PM Nudge Trigger] --> B[Get Active Users]
    A1[8PM Nudge Trigger] --> B1[Get Active Users]
    C[Manual Trigger] --> D[Get Non-Active Users]

    B --> E[Remove Duplicates]
    B1 --> E1[Remove Duplicates]
    D --> F[Check WhatsApp History]

    E --> G{Channel = WhatsApp?}
    E1 --> H[Loop Over Items]
    F --> I[Update to Active Status]

    G -->|Yes| J[Loop Over Items - WhatsApp Path]
    G -->|No| K[Loop Over Items - SMS Path]

    J --> L[Check Chat Log]
    K --> M[Set SMS Message]

    L --> N{Chat Record Exists?}
    M --> O[Send SMS]

    N -->|Yes| P{Less than 24hrs?}
    N -->|No| Q[Set WhatsApp Redirect Message]

    P -->|Yes| R[Send WhatsApp Message]
    P -->|No| Q

    Q --> S[Send SMS with WhatsApp Link]
    R --> T[Log to Chat History]
    O --> U[Log to Chat History]
    S --> V[Log to Chat History]

    H --> W[Get Chat History]
    W --> X[Filter Recent Activity]
    X --> Y[Aggregate Data]
    Y --> Z{Has Recent Activity?}

    Z -->|No| AA{Channel = WhatsApp?}
    Z -->|Yes| BB[Continue Loop]

    AA -->|Yes| CC[Send WhatsApp]
    AA -->|No| DD[Send SMS]

    T --> BB
    U --> BB
    V --> BB
    CC --> EE[Log Message]
    DD --> FF[Log Message]
    EE --> BB
    FF --> BB

Triggers

  • 7PM Nudge: Schedule trigger that runs daily at 7:00 PM
  • 8PM Nudge: Schedule trigger that runs daily at 8:00 PM
  • Manual Trigger: For testing and manual execution

Nodes Used

Node Type Purpose
Schedule Trigger Automated daily execution at 7 PM and 8 PM
Manual Trigger Manual workflow testing and execution
Postgres Database operations for user data and chat history
HTTP Request SMS sending via Africa's Talking API
Twilio WhatsApp message sending
If/Filter Conditional logic and data filtering
Split in Batches Process users in manageable batches
Set/Edit Fields Message content preparation
Remove Duplicates Prevent duplicate messaging
Aggregate Combine filtered chat history data
No Op Workflow organization and labeling

External Services & Credentials Required

Africa's Talking SMS API

  • Credential: API key for SMS sending
  • Usage: Sending SMS messages to users without WhatsApp or as fallback

Twilio WhatsApp API

  • Credential: Twilio API credentials
  • Usage: Sending WhatsApp messages to engaged users

PostgreSQL Database

  • Credential: Database connection to Supabase
  • Usage: User data storage and chat history logging

Environment Variables

No explicit environment variables are used. All configuration is handled through n8n credentials and node parameters.

Data Flow

Input Data

  • User records from youthEntrepreneursReal table
  • Chat history from n8n_chat_histories and chatLog tables
  • Scheduled trigger timestamps

Processing

  • User filtering based on onboarding status and phone number availability
  • Channel preference detection (WhatsApp vs SMS)
  • Recent activity analysis (last 24 hours)
  • Message personalization with user's first name

Output Data

  • Sent messages via WhatsApp or SMS
  • Updated chat history records
  • Updated user onboarding status

Error Handling

  • Continue on Error: The getUserRecord3 node has error handling to continue workflow execution even if database logging fails
  • Always Output Data: Several database query nodes are configured to always output data, preventing workflow stops on empty results
  • Fallback Messaging: If WhatsApp delivery fails or user hasn't been active, the system falls back to SMS delivery

Known Limitations

Based on the workflow structure: - Hard-coded phone number exclusion (+254712287952) suggests testing/admin filtering - Messages are currently in Swahili, limiting to Swahili-speaking users - 24-hour activity window is fixed and not configurable - No delivery confirmation or retry logic for failed messages

No related workflows specified in the current context.

Setup Instructions

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

  2. Configure Credentials:

    • Set up PostgreSQL connection to Supabase with credential name "PostgresOnSupabase"
    • Configure Twilio WhatsApp API with credential name "Twilio WhatsApp kdp"
    • Add Africa's Talking API key in HTTP request nodes
  3. Database Setup: Ensure these tables exist:

    • youthEntrepreneursReal: User data with columns for phoneNumber, firstName, onboardingStatus, channel
    • n8n_chat_histories: Chat logging with session_id and message columns
    • chatLog: User interaction history with userPhone, channel, and created_at columns
  4. Schedule Configuration:

    • Enable the "7PM Nudge" and "8PM Nudge" schedule triggers
    • Adjust timing as needed for your timezone
  5. Message Customization:

    • Update message templates in the "setNudgeMessage" nodes
    • Modify sender IDs and phone numbers for your region
  6. Testing:

    • Use the manual trigger to test with a small user subset
    • Verify database logging and message delivery
    • Check error handling with invalid phone numbers
  7. Monitoring:

    • Monitor execution logs for failed deliveries
    • Track chat history entries for audit purposes
    • Review user engagement metrics post-implementation