WhatsApp Trigger Workflow¶
This workflow processes incoming WhatsApp messages through Twilio, validates users against a PostgreSQL database, and routes authenticated users to a sales tracking agent for automated responses. It serves as the primary entry point for WhatsApp-based customer interactions.
Purpose¶
No business context provided yet — add a context.md to enrich this documentation.
This workflow appears to be designed for customer support or sales assistance through WhatsApp, allowing registered users to interact with an automated agent while filtering out unauthorized users.
How It Works¶
- Incoming Message: A WhatsApp message arrives via Twilio webhook
- User Validation: The workflow checks if the sender's phone number exists in the
youthEntrepreneursRealdatabase table - Route Decision:
- If user not found: Sends "Sorry, your number was not found in our database" message
- If user found: Extracts phone number and message content, then forwards to the sales tracking agent
- Agent Processing: Calls the "Mark - SalesTrackingAgent" workflow with user details and message
- Response Delivery: Sends the agent's response back to the user via WhatsApp
- Data Export: A separate manual trigger allows exporting all user data to Google Sheets
Workflow Diagram¶
graph TD
A[Twilio WhatsApp Webhook] --> B[Execute SQL Query - Check User]
B --> C{User Found?}
C -->|No| D[Send "User Not Found" Message]
C -->|Yes| E[Set User Phone & Query]
E --> F[Call Sales Tracking Agent]
F --> G[Send WhatsApp Response]
H[Manual Trigger] --> I[Execute SQL Query - Get All Users]
I --> J[Append to Google Sheets]
Trigger¶
- Primary: Webhook trigger that receives POST requests from Twilio when WhatsApp messages are received
- Secondary: Manual trigger for data export functionality
Nodes Used¶
| Node Type | Purpose |
|---|---|
| Webhook | Receives incoming WhatsApp messages from Twilio |
| PostgreSQL | Validates user existence and retrieves user data |
| IF | Conditional logic to route based on user validation |
| Set | Prepares user data for the sales agent workflow |
| Execute Workflow | Calls the "Mark - SalesTrackingAgent" workflow |
| Twilio | Sends WhatsApp responses back to users |
| Google Sheets | Exports user data for reporting |
| Manual Trigger | Allows manual data export |
External Services & Credentials Required¶
Twilio¶
- Credential Name: "Twilio WhatsApp kdp"
- Purpose: Send and receive WhatsApp messages
- Required: Account SID, Auth Token, WhatsApp-enabled phone number
PostgreSQL¶
- Credential Name: "PostgresOnSupabase"
- Purpose: User validation and data retrieval
- Required: Database host, username, password, database name
Google Sheets¶
- Credential Name: "Google Sheets account 3"
- Purpose: Data export functionality
- Required: OAuth2 credentials with Sheets API access
Environment Variables¶
No specific environment variables are configured in this workflow. All configuration is handled through n8n credentials.
Data Flow¶
Input¶
- WhatsApp Message: Contains sender phone number (
WaId), message body (Body), and Twilio metadata - Manual Trigger: No input data required
Processing¶
- Extracts phone number and message content
- Validates user against database
- Formats data for sales agent workflow
Output¶
- WhatsApp Response: Automated response from sales agent or error message
- Google Sheets: Complete user database export (manual trigger only)
Error Handling¶
- User Not Found: Sends a polite rejection message to unregistered phone numbers
- Retry Logic: The "Call Sales Tracking Agent" node has retry enabled for handling temporary failures
- Database Errors: No explicit error handling for database connection issues
Known Limitations¶
- Only processes text messages (NumMedia = 0)
- Requires exact phone number match in database
- No rate limiting or spam protection
- Manual data export requires manual trigger activation
Related Workflows¶
- Mark - SalesTrackingAgent (ID: SQuf6XRV3xERKdsY): Processes validated user queries and generates responses
Setup Instructions¶
-
Import Workflow: Import the JSON into your n8n instance
-
Configure Credentials:
- Set up Twilio API credentials with WhatsApp sandbox or production access
- Configure PostgreSQL connection to your user database
- Set up Google Sheets OAuth2 credentials
-
Database Setup: Ensure your PostgreSQL database has a
youthEntrepreneursRealtable with at minimum:idcolumnphoneNumbercolumn (format: +[country code][number])
-
Twilio Webhook Configuration:
- Copy the webhook URL from the "Twilio WhatsApp" node
- Configure this URL in your Twilio WhatsApp settings
-
Test the Workflow:
- Send a test message from a registered phone number
- Verify the sales agent workflow is accessible
- Test the manual data export functionality
-
Activate: Enable the workflow to start processing live WhatsApp messages