Webhook Overview
Webhooks are HTTP POST requests that OTPIQ sends to your specified endpoint whenever there’s a status update for your SMS messages. This allows you to:- Get real-time delivery confirmations
- Track message failures immediately
- Update your application’s status in real-time
- Avoid the need for constant API polling
How to Configure Webhooks
To enable webhooks, include adeliveryReport
object in your SMS request:
Webhook Configuration Fields
The HTTPS URL where delivery status updates will be sent. Must use HTTPS
protocol. Example:
https://your-app.com/webhooks/sms-status
Controls when webhooks are triggered: -
"all"
- Receive webhooks for all
status updates (sent, delivered, failed) - "final"
- Only receive webhooks
for final status updates (delivered or failed)Optional secret key for webhook authentication. This will be sent in the
X-OTPIQ-Webhook-Secret
header for security verification. Example:
your_webhook_secret_123
Webhook Payload Structure
Each webhook request contains a JSON payload with the following structure:Required Fields
Unique message identifier that matches the ID returned when you sent the SMS.
Example:
sms_1234567890abcdef
Your configured report type (
"all"
or "final"
).Whether this is the final status update for this message. When
true
, no
further webhooks will be sent for this message.The messaging channel used:
"sms"
, "whatsapp"
, or "telegram"
.Current delivery status: -
"sent"
- Message has been sent to the provider -
"delivered"
- Message confirmed delivered to recipient - "failed"
-
Message could not be deliveredOptional Fields
Failure reason (only included when status is
"failed"
). Example: "Carrier rejected the message"
Sender ID used (included when a custom sender ID was provided for any message
type). Example:
"OTPIQ"
Delivery Status Flow
SMS Messages
- sent → Message accepted by carrier
- delivered → Message confirmed delivered to recipient
- failed → Message could not be delivered
WhatsApp Messages
- sent → Message sent to WhatsApp servers
- delivered → Message delivered to recipient’s device
- failed → Message could not be sent or delivered
Telegram Messages
- sent → Message sent to Telegram servers
- delivered → Message delivered to recipient
- failed → Message could not be sent
Webhook Examples
Example 1: SMS with Custom Sender ID
Request:- Sent Status:
- Delivered Status:
Example 2: WhatsApp with Final-Only Reports
Request:Example 3: Verification with WhatsApp Custom Sender
Request:- Sent Status:
- Delivered Status:
Example 4: Failed Message
Request:Security Best Practices
Always implement proper security measures when handling webhooks to protect
your application.
1. Use HTTPS
Webhook URLs must use HTTPS to ensure secure transmission of delivery status data.2. Verify Webhook Secret
Check theX-OTPIQ-Webhook-Secret
header to verify the webhook authenticity:
3. Respond Quickly
Your webhook endpoint should respond with a 2xx status code within 10 seconds to acknowledge receipt.4. Handle Duplicates
Implement idempotency using thesmsId
to handle potential duplicate webhooks:
5. Log Everything
Log all webhook requests for debugging and monitoring purposes.Common Issues & Solutions
Webhook Not Received
Possible Causes:- Webhook URL is not accessible from the internet
- Server is not responding within 10 seconds
- HTTPS certificate issues
- Verify webhook URL accessibility
- Check server logs for errors
- Ensure HTTPS is properly configured
Authentication Failures
Possible Causes:- Webhook secret mismatch
- Missing or incorrect header validation
- Verify webhook secret matches exactly
- Check
X-OTPIQ-Webhook-Secret
header name and value
Timeout Errors
Possible Causes:- Webhook endpoint taking too long to respond
- Heavy processing blocking the response
- Respond quickly (within 10 seconds)
- Implement async processing for heavy operations
Testing Webhooks
Using webhook.site
For testing purposes, you can use webhook.site to inspect webhook payloads:- Go to webhook.site
- Copy the generated URL
- Use it as your
webhookUrl
in API requests - Send a test SMS
- Monitor the webhook payloads in real-time
Sample Webhook Handler
Here’s a basic Node.js webhook handler example:Rate Limits
- Webhook Delivery: Up to 10 retries with exponential backoff
- Timeout: 10 seconds per webhook request
- Queue Size: Unlimited webhook queue
If your webhook endpoint consistently fails or times out, OTPIQ may
temporarily disable webhook delivery to prevent system overload.