Skip to content

SMSTrigger

This workflow processes incoming SMS messages from Africa's Talking, validates users against a database, and either redirects WhatsApp users to their preferred channel or processes SMS queries through a sales tracking agent.

Purpose

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

How It Works

  1. Incoming SMS Reception: The workflow receives SMS messages via Africa's Talking webhook
  2. Message Processing: Extracts the sender's phone number and message text
  3. User Validation: Checks if the sender exists in the youth entrepreneurs database
  4. Channel Routing: Determines the user's preferred communication channel (SMS or WhatsApp)
  5. Response Handling: Either redirects WhatsApp users to WhatsApp or processes SMS queries through the sales tracking agent
  6. Reply Delivery: Sends appropriate responses back via SMS

The workflow includes error handling for unknown users and ensures messages are routed to the correct communication channel based on user preferences.

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 -->|WhatsApp User| H[Send SMS via Africa's Talking1]
    G -->|SMS User| I[setUserPhoneNumnberAndQuery]
    I --> J["Call 'Mark - SalesTrackingAgent'"]
    J --> K[If1]
    K -->|Has Output| L[Send SMS via Africa's Talking]
    K -->|No Output| M[No Operation, do nothing]

Trigger

Webhook Trigger: Africa's Talking Incoming messages - Type: HTTP POST webhook - Path: 0f856185-73f9-46e4-ac8f-fb3458a0bdc3 - Status: Currently disabled - Receives incoming SMS messages from Africa's Talking service

Nodes Used

Node Type Node Name Purpose
Webhook Africa's Talking Incoming messages Receives incoming SMS messages
Set setSMSfields Extracts phone number and message text
Postgres Execute a SQL query Checks if user exists in database
If ifUserNotFound Routes based on user existence
HTTP Request Send SMS via Africa's Talking2 Sends "user not found" message
Postgres Execute a SQL query1 Gets user's preferred channel
If If Routes based on channel preference
HTTP Request Send SMS via Africa's Talking1 Redirects WhatsApp users
Set setUserPhoneNumnberAndQuery Prepares data for sales agent
Execute Workflow Call 'Mark - SalesTrackingAgent' Processes SMS queries
If If1 Checks if agent response exists
HTTP Request Send SMS via Africa's Talking Sends agent response
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
  • Purpose: Stores youth entrepreneur data including phone numbers and channel preferences
  • Tables Used: youthEntrepreneursReal

Sub-workflow

  • Workflow ID: SQuf6XRV3xERKdsY
  • Name: "Mark - SalesTrackingAgent"
  • Purpose: Processes user queries and generates responses

Environment Variables

No environment variables are explicitly configured in this workflow. All configuration is handled through: - Hard-coded API credentials (should be moved to credential store) - Database connection via n8n credentials - Workflow references via workflow IDs

Data Flow

Input

  • SMS Message: Received via Africa's Talking webhook
    • from: Sender's phone number
    • text: Message content
    • to: Destination short code
    • id: Message ID
    • date: Timestamp

Processing

  • User Lookup: Phone number validation against database
  • Channel Detection: Determines if user prefers SMS or WhatsApp
  • Query Processing: For SMS users, processes queries through sales tracking agent

Output

  • SMS Response: Sent back to user via Africa's Talking API
    • WhatsApp redirect message with link
    • Sales tracking agent response
    • "User not found" error message

Error Handling

  1. Unknown Users: Users not found in database receive a "number not found" message
  2. WhatsApp Redirection: Users with WhatsApp preference are redirected with a link to WhatsApp
  3. Empty Responses: If the sales tracking agent returns no output, no SMS is sent (No Operation node)
  4. Database Errors: Handled by n8n's built-in retry mechanisms

Known Limitations

  • Workflow is currently disabled
  • API keys are hard-coded in the workflow (security risk)
  • Limited to Kenya-based phone numbers via Africa's Talking
  • No rate limiting or spam protection
  • Single language support (appears to use Swahili)
  • Mark - SalesTrackingAgent (SQuf6XRV3xERKdsY): Processes user queries and generates contextual responses

Setup Instructions

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

  2. Configure Database Connection:

    • Set up PostgreSQL credential named "PostgresOnSupabase"
    • Ensure access to youthEntrepreneursReal table with columns:
      • phoneNumber (string)
      • channel (string: "SMS" or "WhatsApp")
  3. Configure Africa's Talking:

    • Create Africa's Talking account
    • Obtain API key and replace the hard-coded value
    • Set up webhook URL pointing to your n8n instance
    • Configure short code 24436
  4. Set Up Sub-workflow:

    • Ensure "Mark - SalesTrackingAgent" workflow exists
    • Verify workflow ID SQuf6XRV3xERKdsY is correct
  5. Security Improvements:

    • Move API key to n8n credentials store
    • Set up proper authentication for webhook endpoint
  6. Enable Workflow: Change the workflow status from disabled to active

  7. Test: Send a test SMS to your Africa's Talking number to verify the flow works correctly