Backend API server for the SMS Gateway system. Receives SMS from SIM-Relay devices, stores in database, forwards to Telegram.
SIM-Relay (ESP32)
| HTTPS POST + X-API-Key
v
SIM-Orchestrator (this server)
|--- Database (SQLite/PostgreSQL)
+--- Telegram Bot API
- Docker Desktop (Windows/Mac) or Docker Engine (Linux)
- Telegram Bot token and Chat ID (see Telegram Setup)
Create .env file in project root:
API_KEY=your-secret-api-key-min-32-characters-long
TELEGRAM_BOT_TOKEN=123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11
TELEGRAM_CHAT_ID=123456789Important: API_KEY must match API_KEY in SIM-Relay's secrets.h.
docker-compose up -dServer starts on http://localhost:5000.
curl http://localhost:5000/healthdocker-compose logs -fdocker-compose down- .NET 8.0 SDK
- Database: SQLite (dev) / PostgreSQL (prod)
Copy appsettings.json.example to appsettings.json:
{
"ApiKey": "your-secret-api-key-min-32-characters-long",
"Telegram": {
"BotToken": "123456:ABC-DEF...",
"ChatId": "your-chat-id"
},
"ConnectionStrings": {
"DefaultConnection": "Data Source=sms_gateway.db"
}
}cd src/SIM-Orchestrator
dotnet ef database update
dotnet runServer starts on http://localhost:5000.
Receives SMS from device.
curl -X POST https://your-server.com/api/sms \
-H "Content-Type: application/json" \
-H "X-API-Key: your-api-key" \
-d '{"sender": "+79991234567", "text": "Hello", "timestamp": "2025-12-28 14:30:00"}'Responses:
200 OK— SMS received and saved401 Unauthorized— Missing X-API-Key403 Forbidden— Invalid API key
Health check endpoint.
src/SIM-Orchestrator/
├── Controllers/
│ ├── SmsController.cs # POST /api/sms
│ └── HealthController.cs # GET /api/health
├── Services/
│ ├── SmsStorageService.cs # Database operations
│ ├── TelegramService.cs # Telegram Bot API
│ └── RetryService.cs # Background retry worker
├── Middleware/
│ └── ApiKeyMiddleware.cs # X-API-Key validation
├── Models/
│ └── SmsMessage.cs # Data model
└── Data/
└── AppDbContext.cs # EF Core context
Prerequisites:
- VPS with Ubuntu 24.04
- Docker and docker-compose installed
- Ports 80, 443 open in firewall
1. Install Caddy:
# Download and run setup script
wget https://raw.githubusercontent.com/YOUR_USERNAME/SIM-Orchestrator/main/setup-caddy.sh
chmod +x setup-caddy.sh
./setup-caddy.shOr manually:
# Install Caddy
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https curl
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
sudo apt update
sudo apt install -y caddy
# Create Caddyfile
sudo nano /etc/caddy/CaddyfilePaste:
%YOUR_DOMAIN% {
reverse_proxy localhost:5000
header {
Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
X-Frame-Options "DENY"
X-Content-Type-Options "nosniff"
X-XSS-Protection "1; mode=block"
}
log {
output file /var/log/caddy/sim-orchestrator.log
format json
}
}
2. Start services:
# Open firewall
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
# Start Caddy
sudo systemctl enable caddy
sudo systemctl restart caddy
# Deploy SIM-Orchestrator
cd ~/sim-orchestrator
docker compose up -d3. Verify HTTPS:
curl -I https://%YOUR_DOMAIN%/healthCaddy automatically provisions Let's Encrypt SSL certificates.
dotnet publish -c Release -o /var/www/sim-orchestratorCreate /etc/systemd/system/sim-orchestrator.service:
[Unit]
Description=SIM Orchestrator API
After=network.target
[Service]
Type=notify
WorkingDirectory=/var/www/sim-orchestrator
ExecStart=/usr/bin/dotnet SIM-Orchestrator.dll
Restart=always
User=www-data
Environment=ASPNETCORE_ENVIRONMENT=Production
[Install]
WantedBy=multi-user.targetsudo systemctl enable --now sim-orchestratorUsing docker-compose (recommended):
# Create .env file with your settings
cat > .env << EOF
API_KEY=your-secret-api-key-min-32-characters-long
TELEGRAM_BOT_TOKEN=123456:ABC-DEF...
TELEGRAM_CHAT_ID=123456789
EOF
# Start the service
docker-compose up -d
# Check status
docker-compose ps
docker-compose logs -fOr build and run manually:
docker build -t sim-orchestrator ./src/SIM-Orchestrator
docker run -d -p 5000:8080 \
-e ApiKey="your-api-key" \
-e Telegram__BotToken="your-bot-token" \
-e Telegram__ChatId="your-chat-id" \
-v sms-data:/data \
sim-orchestrator- Message @BotFather →
/newbot - Copy token (format:
123456:ABC-DEF1234...) - Get Chat ID from @userinfobot
| Problem | Solution |
|---|---|
| 401/403 errors | Check X-API-Key matches between device and server |
| Telegram fails | Verify bot token and chat ID; check firewall (port 443) |
| Database errors | Run dotnet ef database update |
| Connection refused | Check server is running and port is open |
- SIM-Relay: ESP32 firmware that sends SMS to this server