Prompt
How do I trigger email SMS and push notifications from one API?
Latest observation
To trigger email, SMS, and push notifications from one API, the usual pattern is to build a single notification endpoint that accepts a message payload plus a list of channels, then routes that payload to the right delivery providers behind the scenes.
1) Design one API endpoint
Example:
POST /notifications/send
Content-Type: application/json
{
"recipient": {
"userId": "12345",
"email": "alex@example.com",
"phone": "+15551234567",
"pushToken": "expoPushToken[xxxx]"
},
"channels": ["email", "sms", "push"],
"templateId": "order_shipped",
"data": {
"orderId": "A1001",
"trackingUrl": "https://example.com/track/A1001"
}
}
Your API then:
- validates the request
- determines which channels are enabled
- renders the message/template
- sends each channel through its provider
2) Use a notification service layer
In your backend, create a single service that dispatches to channel-specific handlers:
EmailSender→ SendGrid, SES, Mailgun, etc.SmsSender→ Twilio, Vonage, etc.PushSender→ Firebase Cloud Messaging, APNs, OneSignal, etc.
Pseudo-flow:
POST /notifications/send
-> NotificationService
-> EmailSender if "email" included
-> SmsSender if "sms" included
-> PushSender if "push" included
3) Keep channel formatting separate
Each channel has its own formatting rules:
- Email: HTML + subject + optional text version
- SMS: short plain text, no HTML, length limited
- Push: title + body + optional deep link / data payload
Example template data:
{
"subject": "Your order has shipped",
"emailBody": "<p>Your order A1001 has shipped.</p>",
"smsBody": "Your order A1001 has shipped. Track it here: https://example.com/track/A1001",
"pushTitle": "Order shipped",
"pushBody": "Your order A1001 is on the way."
}
4) Consider async delivery
For reliability, don’t send everything directly in the request thread if traffic is high.
Better approach:
- API receives request
- enqueues a job/message
- workers send notifications asynchronously
Common tools:
- RabbitMQ
- Kafka
- AWS SQS
- Redis queues
- Celery / Sidekiq / BullMQ / Hangfire, etc.
This gives you:
- retries
- failure isolation
- better performance
5) Example implementation pattern
A simple service interface:
class NotificationService:
def send(self, channels, recipient, template_id, data):
if "email" in channels:
EmailSender.send(recipient["email"], template_id, data)
if "sms" in channels:
SmsSender.send(recipient["phone"], template_id, data)
if "push" in channels:
PushSender.send(recipient["pushToken"], template_id, data)
6) Add user preferences
Usually you also want to respect:
- opt-in/opt-out
- quiet hours
- per-channel preferences
- fallback logic
Example:
- if push fails, send SMS
- if SMS is disabled, send email only
7) Return a unified response
Example response:
{
"requestId": "notif_789",
"status": "queued",
"results": {
"email": "queued",
"sms": "queued",
"push": "queued"
}
}
8) If you want a managed solution
If you don’t want to build channel handling yourself, platforms like these can help:
- AWS SNS
- Twilio Notify (or Twilio APIs directly)
- Firebase + email/SMS providers
- OneSignal for push, with other providers for email/SMS
- Courier, Knock, Novu for multi-channel notification orchestration
These are especially useful if you want:
- templates
- preference management
- retries
- analytics
- multi-channel orchestration
If you want, I can give you:
- a Node.js example
- a Python/FastAPI example
- a design for a production-ready notification API