---
name: telegram-alerts
description: Send notifications to Telegram bot for service alerts, deployment status, and system warnings. Integrates with @peramix_vps_bot.
---

# Telegram Alerts Skill

Push notifications to Telegram for important events and alerts.

## Configuration

Bot: `@peramix_vps_bot`
Chat ID: `1185240496` (User's Telegram ID)

## Alert Types

### 🔴 Critical (Immediate)
- Service down/crashed
- Database connection failed
- Disk > 95%
- Memory > 95%
- SSL expired

### 🟡 Warning (Within 5 min)
- Service unhealthy
- Disk > 80%
- Memory > 85%
- SSL < 14 days
- High error rate

### 🟢 Info (Batched hourly)
- Deployment complete
- Backup successful
- Cleanup completed
- Health check passed

## Message Format

```
🔴 CRITICAL: rima-backend DOWN

VPS: 60 (10.180.160.60)
Service: rima-backend
Status: Exited (1) 5 minutes ago
Last Log: connection refused postgres:5432

Action Taken: Attempting restart...

---
⏰ 2026-01-29 19:30:00 UTC
```

## Send Methods

### Via Clawdbot API
```bash
curl -X POST "http://localhost:3001/api/telegram/send" \
  -H "Content-Type: application/json" \
  -d '{"chat_id": "1185240496", "message": "Alert message"}'
```

### Via Telegram Bot API Direct
```bash
curl -X POST "https://api.telegram.org/bot${BOT_TOKEN}/sendMessage" \
  -d "chat_id=1185240496" \
  -d "text=Alert message" \
  -d "parse_mode=Markdown"
```

## Alert Triggers

### Health Check Failed
```bash
# Check and alert
if ! curl -sf http://service/health; then
  send_telegram "🔴 Service health check failed"
fi
```

### Disk Space Warning
```bash
DISK_USAGE=$(df / | awk 'NR==2 {print $5}' | tr -d '%')
if [ $DISK_USAGE -gt 80 ]; then
  send_telegram "🟡 Disk usage at ${DISK_USAGE}%"
fi
```

### Deployment Notification
```bash
send_telegram "🟢 Deployed: rima-backend v2.0.0
Commit: abc1234
Status: Healthy
URL: https://rima-api.zesbe.my.id"
```

## Integration with Proactive Mode

After ANY significant action:
1. Determine alert level
2. Format message with context
3. Send to Telegram
4. Log alert locally

## Rate Limiting

- Critical: No limit
- Warning: Max 1 per service per 15 min
- Info: Batched, max 10 per hour

## Silent Hours (Optional)

- Suppress non-critical alerts 00:00-07:00
- Critical alerts always sent
- Queue warnings for morning summary
