A FastAPI microservice that integrates with EdgeX Foundry to forward notifications as SMS messages via Twilio. This service acts as a bridge between EdgeX's notification system and SMS delivery.
- ✅ Receives EdgeX notifications via REST webhooks
- ✅ Supports both JSON and plain text payload formats
- ✅ Automatically adds Indian country code (+91) when needed
- ✅ Integrates with Twilio for SMS delivery
- ✅ Health check endpoints for monitoring
- ✅ Docker containerized for easy deployment
- ✅ Comprehensive logging for debugging
EdgeX Foundry → Subscription Service → FastAPI SMS Forwarder → Twilio API → SMS Delivery
- Python 3.10+
- Docker and Docker Compose
- Twilio account with SMS capabilities
- EdgeX Foundry (Napa release or later)
git clone <your-repo-url>
cd edgex-sms-forwarderCreate a .env file:
TWILIO_SID=your_twilio_account_sid
TWILIO_TOKEN=your_twilio_auth_token
TWILIO_PHONE=your_twilio_phone_number # Format: +1234567890docker build -t edgex-sms-forwarder:1.0.0 .Create a subscription in EdgeX to forward notifications:
curl -X POST http://<edgex-host>:59860/api/v3/subscription \
-H 'Content-Type: application/json' \
-d '{
"name": "sms-alerts",
"channels": [{
"type": "REST",
"host": "edgex-sms-forwarder",
"port": 9876,
"path": "/send-sms/7358886350", # Phone number in path
"httpMethod": "POST"
}],
"categories": ["ALERT", "SECURITY"],
"severities": ["CRITICAL"],
"resendLimit": 3
}'Add to your docker-compose.yml:
sms-forwarder:
image: edgex-sms-forwarder:1.1.3
container_name: edgex-sms-forwarder
ports:
- "9876:9876"
environment:
- TWILIO_SID=
- TWILIO_TOKEN=
- TWILIO_PHONE=
networks:
magistrala-base-net: null
restart: unless-stopped
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:9876/health"]
interval: 30s
timeout: 10s
retries: 3POST /send-sms/{phone_number}
Parameters:
phone_number: Phone number (with or without +91 country code)body: Notification content (JSON or plain text)
Supported JSON Formats:
// Simple format
{"content": "Alert message", "severity": "CRITICAL"}
// EdgeX format
[{"apiVersion": "v3", "notification": {"content": "Alert", "severity": "CRITICAL"}}]
// Plain text
"Smoke alert: 200% exceeds threshold"GET /health
Returns service status and Twilio configuration status.
GET /
Service information endpoint.
# Plain text
curl -X POST http://localhost:9876/send-sms/7358556350 \
-H "Content-Type: text/plain" \
-d "Server temperature critical: 95°C"
# JSON
curl -X POST http://localhost:9876/send-sms/7358556350 \
-H "Content-Type: application/json" \
-d '{"content": "Network outage detected", "severity": "CRITICAL"}'788856350→ automatically converted to+91788856350+91788856350→ used as-is91788856350→ converted to+91788856350
- 422 Unprocessable Entity: Check if EdgeX is sending proper JSON format
- SMS not delivered: Verify Twilio credentials and phone number format
- Connection refused: Ensure the service is running on port 9876
docker logs edgex-sms-forwardercurl http://localhost:9876/healthpython -m venv venv
source venv/bin/activate
pip install -r app/requirements.txt
uvicorn app.main:app --host 0.0.0.0 --port 9876 --reload# Test with sample payloads
python test_sms.py
- 🔒 Never commit Twilio credentials to version control
- 🔒 Use EdgeX secret store for production credentials
- 🔒 Validate phone numbers to prevent SMS abuse
- 🔒 Consider adding authentication for the API endpoints
MIT License - see LICENSE file for details.
For issues and questions:
- Check the logs:
docker logs edgex-sms-forwarder - Verify Twilio account status
- Ensure EdgeX subscription is properly configured
- Check network connectivity between containers
- Fork the repository
- Create a feature branch
- Make changes with tests
- Submit a pull request
Note: This service is designed for EdgeX Foundry Napa release and may require adjustments for other versions.