📢 Notify Service¶
Multi-channel messaging and notification system
🎯 Overview¶
The Notify Service is a comprehensive multi-channel messaging system that handles push notifications, SMS, email, and WhatsApp communications across the Appgain platform. It provides unified messaging capabilities with high throughput, delivery tracking, and campaign management.
🏗️ Architecture¶
Core Components¶
- Message Router: Routes messages to appropriate channels
- Channel Manager: Manages different communication channels
- Campaign Engine: Handles bulk messaging and campaigns
- Delivery Tracker: Monitors message delivery status
- Rate Limiter: Manages sending rates and throttling
Technology Stack¶
- Node.js: Runtime environment
- Firebase Cloud Messaging (FCM): Android push notifications
- Apple Push Notification Service (APNs): iOS push notifications
- SMS Gateways: Multiple SMS providers
- Email Providers: SMTP and email service integration
- WhatsApp Business API: WhatsApp messaging
- Redis: Message queuing and caching
Infrastructure¶
- Server:
ovh-parse-server - Port: 3001 (HTTP), 3002 (HTTPS)
- Environment: Production, Staging, Development
- Channels: Push, SMS, Email, WhatsApp
🔧 Configuration¶
Server Details¶
- Server:
ovh-parse-server - Port: 3001 (HTTP), 3002 (HTTPS)
- Base URL:
https://notify.appgain.io - Environment: Production, Staging, Development
Service Configuration¶
// notify-service.config.js
module.exports = {
channels: {
push: {
fcm: {
serverKey: process.env.FCM_SERVER_KEY,
projectId: process.env.FCM_PROJECT_ID
},
apns: {
keyId: process.env.APNS_KEY_ID,
teamId: process.env.APNS_TEAM_ID,
privateKey: process.env.APNS_PRIVATE_KEY
}
},
sms: {
providers: ['twilio', 'nexmo', 'africastalking'],
defaultProvider: 'twilio'
},
email: {
smtp: {
host: process.env.SMTP_HOST,
port: process.env.SMTP_PORT,
secure: true,
auth: {
user: process.env.SMTP_USER,
pass: process.env.SMTP_PASS
}
}
},
whatsapp: {
businessApi: {
accessToken: process.env.WHATSAPP_ACCESS_TOKEN,
phoneNumberId: process.env.WHATSAPP_PHONE_NUMBER_ID
}
}
},
rateLimits: {
push: 1000, // messages per minute
sms: 100, // messages per minute
email: 500, // messages per minute
whatsapp: 50 // messages per minute
}
}
API Endpoints¶
# Send notification
POST /notify/send
{
"channel": "push|sms|email|whatsapp",
"recipients": ["user1", "user2"],
"message": {
"title": "Notification Title",
"body": "Notification message",
"data": {}
}
}
# Send campaign
POST /notify/campaign
{
"name": "Campaign Name",
"channel": "push",
"recipients": ["user1", "user2"],
"message": {
"title": "Campaign Title",
"body": "Campaign message"
},
"schedule": "2024-01-01T10:00:00Z"
}
# Check delivery status
GET /notify/status/{messageId}
# Get delivery reports
GET /notify/reports?start=2024-01-01&end=2024-01-31
📊 Channel Management¶
Push Notifications¶
// Send push notification
const pushNotification = {
channel: 'push',
recipients: ['device_token_1', 'device_token_2'],
message: {
title: 'New Message',
body: 'You have a new message',
data: {
type: 'message',
id: '12345'
},
badge: 1,
sound: 'default'
}
};
SMS Messaging¶
// Send SMS
const smsMessage = {
channel: 'sms',
recipients: ['+1234567890', '+0987654321'],
message: {
body: 'Your verification code is: 123456',
from: 'Appgain'
}
};
Email Messaging¶
// Send email
const emailMessage = {
channel: 'email',
recipients: ['user@example.com'],
message: {
subject: 'Welcome to Appgain',
body: 'Welcome to our platform!',
html: '<h1>Welcome</h1><p>Welcome to our platform!</p>'
}
};
WhatsApp Messaging¶
// Send WhatsApp message
const whatsappMessage = {
channel: 'whatsapp',
recipients: ['+1234567890'],
message: {
body: 'Hello from Appgain!',
type: 'text'
}
};
🔍 Monitoring & Analytics¶
Delivery Tracking¶
// Track delivery status
const deliveryStatus = {
messageId: 'msg_12345',
status: 'delivered|failed|pending',
channel: 'push',
recipient: 'device_token',
timestamp: '2024-01-01T10:00:00Z',
error: null
};
Performance Metrics¶
- Delivery Rate: >95% successful delivery
- Response Time: <2 seconds average
- Throughput: 10,000+ messages per minute
- Uptime: 99.9% service availability
Analytics Dashboard¶
# Get delivery statistics
GET /notify/analytics/delivery?period=30d
# Get channel performance
GET /notify/analytics/channels?period=7d
# Get campaign performance
GET /notify/analytics/campaigns?campaignId=12345
🔒 Security¶
Authentication¶
- API Keys: Secure API key authentication
- JWT Tokens: Token-based authentication
- Rate Limiting: Per-channel rate limiting
- IP Whitelisting: Allowed IP addresses
Data Protection¶
- Message Encryption: End-to-end encryption
- PII Protection: Personal data anonymization
- GDPR Compliance: Data privacy compliance
- Audit Logging: Complete audit trail
📈 Performance¶
Capabilities¶
- Multi-Channel: Push, SMS, Email, WhatsApp
- High Throughput: 10,000+ messages/minute
- Real-Time: Instant message delivery
- Scalable: Horizontal scaling support
Limitations¶
- Rate Limits: Channel-specific rate limits
- Message Size: 4KB maximum for push notifications
- Recipients: 1,000 maximum per batch
- Campaign Size: 100,000 maximum recipients
🔗 Integration Examples¶
Parse Server Integration¶
// Parse Server integration
Parse.Cloud.afterSave('Notification', async (request) => {
const notification = request.object;
await fetch('https://notify.appgain.io/notify/send', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${process.env.NOTIFY_API_KEY}`
},
body: JSON.stringify({
channel: notification.get('channel'),
recipients: notification.get('recipients'),
message: {
title: notification.get('title'),
body: notification.get('body')
}
})
});
});
Automator Integration¶
// Automator workflow integration
const automatorWorkflow = {
trigger: 'user_signup',
actions: [
{
type: 'notify',
channel: 'email',
template: 'welcome_email',
recipients: ['{{user.email}}'],
data: {
userName: '{{user.name}}',
signupDate: '{{user.createdAt}}'
}
},
{
type: 'notify',
channel: 'push',
template: 'welcome_push',
recipients: ['{{user.deviceToken}}']
}
]
};
Campaign Management¶
// Create and schedule campaign
const campaign = {
name: 'Black Friday Sale',
channel: 'push',
recipients: ['user1', 'user2', 'user3'],
message: {
title: 'Black Friday Sale!',
body: 'Get 50% off on all items',
data: {
campaignId: 'black_friday_2024',
deepLink: 'appgain://sale/black-friday'
}
},
schedule: '2024-11-29T09:00:00Z',
conditions: {
userSegment: 'active_users',
timezone: 'America/New_York'
}
};
🛠️ Troubleshooting¶
Common Issues¶
Delivery Failures¶
# Check delivery status
curl -X GET "https://notify.appgain.io/notify/status/msg_12345" \
-H "Authorization: Bearer YOUR_API_KEY"
# Check channel health
curl -X GET "https://notify.appgain.io/notify/health" \
-H "Authorization: Bearer YOUR_API_KEY"
Rate Limiting¶
# Check rate limits
curl -X GET "https://notify.appgain.io/notify/limits" \
-H "Authorization: Bearer YOUR_API_KEY"
# Response
{
"push": {
"limit": 1000,
"used": 850,
"remaining": 150,
"resetTime": "2024-01-01T11:00:00Z"
}
}
Authentication Errors¶
# Verify API key
curl -X GET "https://notify.appgain.io/notify/verify" \
-H "Authorization: Bearer YOUR_API_KEY"
Debug Commands¶
# Test push notification
curl -X POST "https://notify.appgain.io/notify/send" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"channel": "push",
"recipients": ["device_token"],
"message": {
"title": "Test",
"body": "Test message"
}
}'
# Check service logs
tail -f /var/log/notify-service/app.log
📚 Documentation¶
External Resources¶
- Notify API: API Documentation
- Firebase FCM: FCM Documentation
- Apple APNs: APNs Documentation
- WhatsApp Business API: WhatsApp API
Monitoring Tools¶
- Grafana Dashboards: Real-time delivery metrics
- Prometheus: Performance monitoring
- ELK Stack: Log analysis and alerting
- Custom Analytics: Delivery success tracking
Development Tools¶
- Postman Collection: API testing and documentation
- GitLab Repository: AppGain Notify Backend
- Development Environment: Docker setup for local testing
- Testing Framework: Automated notification testing
🔗 Related Resources¶
- System Architecture? → System Architecture
- Push Sender? → Push Sender
- Task Queue? → Task Queue
- WhatsApp Lite? → WhatsApp Lite Channel
- Learning Resources? → Learning Resources
Ask Chehab GPT