SMSTrigger¶
This workflow handles incoming SMS messages through Africa's Talking, validates users against a database, and either redirects WhatsApp users to their preferred channel or processes SMS inquiries through an AI sales tracking agent.
Purpose¶
No business context provided yet — add a context.md to enrich this documentation.
How It Works¶
- Incoming SMS Reception: The workflow receives SMS messages via Africa's Talking webhook
- Message Processing: Extracts the sender's phone number and message text from the incoming SMS
- User Validation: Checks if the sender's phone number exists in the
youthEntrepreneursRealdatabase table - Unknown User Handling: If the user is not found, sends an error message via SMS
- Channel Preference Check: For known users, retrieves their preferred communication channel from the database
- WhatsApp Redirection: If the user's preferred channel is WhatsApp, sends them a message with a WhatsApp link instead of processing the SMS
- SMS Processing: For users who prefer SMS, forwards the inquiry to the "Mark - SalesTrackingAgent" workflow
- Response Delivery: If the sales agent generates a response, sends it back to the user via SMS
Mermaid Diagram¶
graph TD
A[Africa's Talking Incoming messages] --> B[setSMSfields]
B --> C[Execute a SQL query]
C --> D[ifUserNotFound]
D -->|User Not Found| E[Send SMS via Africa's Talking2]
D -->|User Found| F[Execute a SQL query1]
F --> G[If]
G -->|Channel = WhatsApp| H[Send SMS via Africa's Talking1]
G -->|Channel ≠ WhatsApp| I[setUserPhoneNumnberAndQuery]
I --> J[Call 'Mark - SalesTrackingAgent']
J --> K[If1]
K -->|Has Response| L[Send SMS via Africa's Talking]
K -->|No Response| M[No Operation, do nothing]
Trigger¶
Webhook Trigger: Listens for POST requests from Africa's Talking SMS service at the endpoint /webhook/0f856185-73f9-46e4-ac8f-fb3458a0bdc3
Nodes Used¶
| Node Type | Node Name | Purpose |
|---|---|---|
| Webhook | Africa's Talking Incoming messages | Receives incoming SMS webhooks |
| Set | setSMSfields | Extracts phone number and message text |
| PostgreSQL | Execute a SQL query | Checks if user exists in database |
| If | ifUserNotFound | Routes based on user existence |
| PostgreSQL | Execute a SQL query1 | Retrieves user's preferred channel |
| If | If | Routes based on channel preference |
| Set | setUserPhoneNumnberAndQuery | Prepares data for sales agent |
| Execute Workflow | Call 'Mark - SalesTrackingAgent' | Processes inquiry through AI agent |
| If | If1 | Checks if agent generated response |
| HTTP Request | Send SMS via Africa's Talking | Sends agent response via SMS |
| HTTP Request | Send SMS via Africa's Talking1 | Sends WhatsApp redirect message |
| HTTP Request | Send SMS via Africa's Talking2 | Sends user not found error |
| No Operation | No Operation, do nothing | Handles empty responses |
| Sticky Note | Sticky Note | Documentation note |
External Services & Credentials Required¶
Africa's Talking SMS API¶
- API Key: Required for sending SMS messages
- Username:
toll_free_sms_ke - Short Code:
24436 - Base URL:
https://api.africastalking.com/version1/messaging
PostgreSQL Database¶
- Credential Name:
PostgresOnSupabase - Database: Contains
youthEntrepreneursRealtable - Required Fields:
id,phoneNumber,channel
Related Workflows¶
- Mark - SalesTrackingAgent (ID:
SQuf6XRV3xERKdsY): Processes user inquiries and generates responses
Environment Variables¶
No environment variables are explicitly used in this workflow. Configuration is handled through: - Hardcoded Africa's Talking credentials (API key visible in workflow) - Database credentials stored in n8n credential system - Static webhook path and short code values
Data Flow¶
Input (Africa's Talking Webhook)¶
1 2 3 4 5 6 7 8 9 | |
Processing¶
- Extracts phone number (removes leading +)
- Validates against database
- Retrieves channel preference
- Routes to appropriate handler
Output (SMS Response)¶
- Error message for unknown users
- WhatsApp redirect for WhatsApp users
- AI-generated response for SMS users
Error Handling¶
- Unknown Users: Users not found in the database receive the message "Sorry, your number was not found in our database"
- WhatsApp Users: Users with WhatsApp preference receive a redirect message with link to WhatsApp
- Empty Responses: If the sales agent doesn't generate a response, no SMS is sent (handled by No Operation node)
- Retry Logic: The "Call 'Mark - SalesTrackingAgent'" node has retry enabled for handling temporary failures
Known Limitations¶
- API key is hardcoded in the workflow (security risk)
- No validation of message content or length limits
- Single database table dependency
- No handling for malformed webhook payloads
- WhatsApp redirect uses hardcoded phone number (254203892316)
Related Workflows¶
- Mark - SalesTrackingAgent: Processes user inquiries and generates contextual responses for sales tracking
Setup Instructions¶
- Import Workflow: Import the JSON into your n8n instance
- Configure Database Credential:
- Create PostgreSQL credential named "PostgresOnSupabase"
- Ensure access to
youthEntrepreneursRealtable with fields:id,phoneNumber,channel
- Set Up Africa's Talking:
- Replace the hardcoded API key with your own
- Configure webhook URL in Africa's Talking dashboard to point to your n8n instance
- Verify short code and username match your Africa's Talking account
- Deploy Related Workflow:
- Ensure "Mark - SalesTrackingAgent" workflow is deployed and accessible
- Test Integration:
- Send test SMS to your Africa's Talking number
- Verify database lookups and response delivery
- Security Hardening:
- Move API key to environment variable or credential store
- Add webhook authentication if required
- Review and update hardcoded phone numbers