Skip to content

[DEMO TARGET] Pilot Sync-Deploy Test

This workflow demonstrates a sync-deploy system by cleaning up users stuck in weekly report stages on Sundays, restoring their previous conversation state and sending appropriate closing messages via WhatsApp or SMS based on their preferred channel.

Purpose

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

This appears to be a demo/test workflow that handles user state management in what seems to be an entrepreneurship coaching or mentoring system. The workflow identifies users who are stuck in weekly report collection stages and helps them return to their normal conversation flow.

How It Works

  1. Manual Trigger: The workflow starts with a manual trigger (no automated scheduling in this demo version)
  2. Sunday Check: Verifies if today is Sunday using East Africa Time (EAT), stopping execution if it's not
  3. Database Query: Fetches all users currently stuck in any weekly report stage from the database
  4. User Processing: Loops through each stuck user individually
  5. State Restoration: Updates each user's current stage back to their previous stage (or 'idle' if no previous stage exists)
  6. Channel Detection: Checks if the user prefers WhatsApp or SMS communication
  7. Closing Message: Sends an appropriate closing message in Swahili informing them their report is ready

Workflow Diagram

graph TD
    A[Manual Trigger Only] --> B[Check Sunday]
    B --> C[Fetch Stuck Users]
    C --> D[Loop Stuck Users]
    D --> E[Restore Stage]
    E --> F[Is WhatsApp?]
    F -->|Yes| G[Send WhatsApp Close]
    F -->|No| H[Send SMS Close]
    G --> D
    H --> D
    D -->|Complete| I[End]

Trigger

  • Type: Manual Trigger
  • Schedule: None (demo version - production would likely use a cron trigger)
  • Activation: Must be triggered manually from the n8n interface

Nodes Used

Node Type Node Name Purpose
Manual Trigger Manual Trigger Only Starts the workflow manually
Code Check Sunday Validates if current day is Sunday in EAT timezone
Postgres Fetch Stuck Users Queries database for users in weekly report stages
Split In Batches Loop Stuck Users Processes users one by one
Postgres Restore Stage Updates user's current stage back to previous stage
If Is WhatsApp? Determines communication channel preference
Twilio Send WhatsApp Close Sends WhatsApp message via Twilio
HTTP Request Send SMS Close Sends SMS via Africa's Talking API
Sticky Note [DEMO PROOF] Documentation note for demo purposes

External Services & Credentials Required

Postgres Database

  • Credential: Postgres account
  • Purpose: Stores user data and conversation states
  • Tables: youthEntrepreneursReal

Twilio

  • Credential: Twilio account
  • Purpose: WhatsApp message delivery
  • Phone Number: +254203892316

Africa's Talking

  • API Key: Required in header (atsk_ae3de07489f045ef1532a7e407df689bcadff2dbc2555361f3055c6774d779c77c5d9954)
  • Username: toll_free_sms_ke
  • Short Code: 24436
  • Purpose: SMS delivery in Kenya

Environment Variables

No explicit environment variables are used in this workflow. All configuration is handled through: - n8n credential system - Hardcoded values in node configurations

Data Flow

Input

  • Trigger: Manual execution
  • Database Query: Users with currentStage LIKE 'weekly_report_%'

Processing

  • User Fields: phoneNumber, firstName, channel, previousStage
  • State Update: currentStage → previousStage (or 'idle')
  • Message Content: Personalized Swahili message with user's first name

Output

  • WhatsApp/SMS: Closing message to each user
  • Database: Updated user stages
  • Loop Control: Continues until all users processed

Error Handling

The workflow includes basic error handling through: - Sunday Check: Stops execution on non-Sunday days - Conditional Logic: Routes messages based on channel preference - Database Fallback: Uses 'idle' if no previousStage exists

No explicit error catching or retry mechanisms are implemented in this demo version.

Known Limitations

  • Demo Status: This is a test/demo workflow, not production-ready
  • Manual Trigger: Requires manual execution (no automated scheduling)
  • Hardcoded Values: API keys and phone numbers are hardcoded
  • Limited Error Handling: No comprehensive error recovery
  • Single Batch Processing: Processes users one at a time (could be optimized)

Based on the naming convention, this appears to be related to: - [Weekly Report] 9PM Timeout Cleanup (mentioned as the actual production version) - Other youth entrepreneur coaching workflows

Setup Instructions

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

  2. Configure Credentials:

    • Set up Postgres connection with access to youthEntrepreneursReal table
    • Configure Twilio account with WhatsApp Business API access
    • Obtain Africa's Talking API credentials for SMS
  3. Database Schema: Ensure your Postgres database has the required table structure:

    1
    2
    3
    4
    5
    6
    -- Required columns in youthEntrepreneursReal table
    phoneNumber VARCHAR
    firstName VARCHAR
    channel VARCHAR
    currentStage VARCHAR
    previousStage VARCHAR
    

  4. Test Execution:

    • Run manually to test the flow
    • Verify database connections
    • Test both WhatsApp and SMS delivery
  5. Production Deployment:

    • Replace manual trigger with cron trigger for Sunday execution
    • Update API credentials for production environment
    • Add comprehensive error handling and logging