SIFA Agent Reply¶
This workflow enables human agents to send messages to users through either WhatsApp or SMS channels, while tracking agent takeover sessions in a database. When an agent needs to respond to a user inquiry, they can send a message through this webhook endpoint, and the system will route it to the appropriate messaging channel and record the agent interaction.
Purpose¶
No business context provided yet — add a context.md to enrich this documentation.
How It Works¶
- Webhook Trigger: The workflow starts when an external system (like an agent dashboard) sends a POST request to the webhook endpoint
- Variable Processing: Extracts and processes the incoming data including phone number, message content, preferred channel, and agent name
- Agent Session Tracking: Records the agent takeover in a PostgreSQL database with a 30-minute expiration time
- Channel Detection: Determines whether to send via WhatsApp or SMS based on the channel parameter
- Message Delivery: Routes the message through either Twilio (WhatsApp) or Africa's Talking (SMS)
- Response: Returns a success confirmation with delivery details
Workflow Diagram¶
graph TD
A[Agent Reply Webhook] --> B[Set Variables]
B --> C[Set Agent Takeover]
C --> D{Is WhatsApp?}
D -->|Yes| E[Send WhatsApp via Twilio]
D -->|No| F[Send SMS via Africa's Talking]
E --> G[Respond WhatsApp Success]
F --> H[Respond SMS Success]
Trigger¶
Webhook: POST request to /sifa-agent-reply
Expected payload:
1 2 3 4 5 6 | |
Nodes Used¶
| Node Type | Node Name | Purpose |
|---|---|---|
| Webhook | Agent Reply Webhook2 | Receives incoming agent reply requests |
| Set | Set Variables1 | Processes and formats incoming data |
| Postgres | Set Agent Takeover | Records agent session in database |
| If | Is WhatsApp?2 | Routes message based on channel type |
| HTTP Request | Send WhatsApp (HTTP)1 | Sends WhatsApp messages via Twilio |
| HTTP Request | Send SMS via Africas Talking2 | Sends SMS messages via Africa's Talking |
| Respond to Webhook | Respond WhatsApp1 | Returns WhatsApp delivery confirmation |
| Respond to Webhook | Respond SMS1 | Returns SMS delivery confirmation |
External Services & Credentials Required¶
Twilio (WhatsApp)¶
- Credential:
twilioApi - Purpose: Send WhatsApp messages
- Required: Account SID, Auth Token
- From Number: +254203892316
Africa's Talking (SMS)¶
- Purpose: Send SMS messages
- Required: API Key, Username
- From Number: 24436
PostgreSQL Database¶
- Credential:
postgres - Purpose: Track agent takeover sessions
- Required: Database connection details
Environment Variables¶
No environment variables are used in this workflow. All configuration is handled through node parameters and credentials.
Data Flow¶
Input¶
1 2 3 4 5 6 | |
Output (WhatsApp)¶
1 2 3 4 5 6 | |
Output (SMS)¶
1 2 3 4 5 | |
Error Handling¶
The workflow includes basic error handling:
- All nodes are configured to continue on error (continueRegularOutput or continueErrorOutput)
- If the channel detection fails, it defaults to the SMS path
- Database operations continue even if they fail, ensuring message delivery isn't blocked
Known Limitations¶
- Agent takeover sessions expire after 30 minutes
- WhatsApp messages are limited by Twilio's rate limits and policies
- SMS messages have character encoding limitations (em dashes and arrows are replaced)
- No validation of phone number formats
- No duplicate message prevention
Related Workflows¶
No related workflows specified in the context.
Setup Instructions¶
-
Import the Workflow
- Copy the workflow JSON
- Import into your n8n instance
-
Configure Credentials
- Set up Twilio API credentials for WhatsApp
- Configure Africa's Talking API key
- Set up PostgreSQL database connection
-
Database Setup Create the agent_takeover table:
1 2 3 4 5 6
CREATE TABLE agent_takeover ( phone_number VARCHAR PRIMARY KEY, agent_name VARCHAR NOT NULL, taken_at TIMESTAMP NOT NULL, expires_at TIMESTAMP NOT NULL ); -
Test the Webhook
- Activate the workflow
- Send a test POST request to the webhook URL
- Verify messages are delivered and database is updated
-
Integration
- Use the webhook URL in your agent dashboard or CRM
- Ensure proper payload format is sent
- Monitor execution logs for any issues