🤖 Automated Telegram notification service for Yandex Delivery orders. Reads orders from D1 database and sends formatted notifications to Telegram channel.
- 📨 Automated Notifications - Sends order updates to Telegram channel every 3 minutes
- 🔄 Smart Processing - Handles new orders, status updates, and delivery completions
- 🚨 Priority System - Urgent orders (delays, cancellations) get immediate attention
- 🇷🇺 Russian Localization - All messages in Russian with proper formatting for Kazakhstan market
- ⏰ Almaty Timezone - Times displayed in local Kazakhstan timezone
- 📊 Rich Formatting - Emojis, inline buttons, and structured messages
- 🔍 Tracking Integration - Direct links to Yandex delivery tracking
yandex-delivery-core (scans orders)
↓ saves with telegram_notified = false
D1 Database (yandex-delivery-history)
↓ reads pending notifications
telegram-notifications (this worker)
↓ sends formatted messages
Telegram API → @cvety_delivery_monitor
npm install
# Telegram Bot API token (from @BotFather)
wrangler secret put TELEGRAM_BOT_TOKEN
# Target channel ID (e.g., @cvety_delivery_monitor)
wrangler secret put TELEGRAM_CHANNEL_ID
# Admin chat ID for error notifications
wrangler secret put TELEGRAM_ADMIN_CHAT_ID
npm run dev
npm run deploy
Health check endpoint
{
"service": "telegram-notifications",
"status": "healthy",
"timestamp": "2024-01-01T12:00:00.000Z"
}
Manually trigger notification sending
{
"success": true,
"result": {
"sent": 15,
"failed": 0,
"errors": []
}
}
Get comprehensive statistics
{
"success": true,
"stats": {
"database": {
"totalOrders": 150,
"pendingNotifications": 8,
"notifiedToday": 42,
"byStatus": {
"new": 3,
"delivered": 5
}
},
"telegram": {
"healthy": true,
"lastCheck": "2024-01-01T12:00:00.000Z"
}
}
}
Send test message to verify connectivity
{
"success": true,
"message": "Test message sent successfully"
}
Comprehensive health check
{
"success": true,
"checks": {
"overall": true,
"database": true,
"telegram": true,
"lastCheck": "2024-01-01T12:00:00.000Z"
}
}
📝 Заказ #ABCD1234 | Новый заказ
📍 Маршрут:
🔸 Откуда: ул. Абая 150, офис Cvety.kz
🔸 Куда: мкр. Самал-2, д. 111, кв. 45
👤 Клиент:
📝 Анна Петрова
📱 +7 777 123 45 67
💰 Стоимость доставки: 1500 KZT
⏰ Создан: 12.01.2024, 14:30
🆔 ID заказа: 12345678-abcd-1234-abcd-123456789012
[🗺 Отследить на карте] [📋 Подробности]
🚚 Заказ #ABCD1234 | Товар забран
👨🚚 Курьер:
📝 Сергей Иванов
📱 +7 701 234 56 78
🚗 Toyota Camry А123БВ02
📍 Адрес доставки:
мкр. Самал-2, д. 111, кв. 45
⏰ Обновлено: 12.01.2024, 15:15
🆔 ID заказа: 12345678-abcd-1234-abcd-123456789012
- Every 3 minutes - Process up to 20 pending notifications
- Priority system - Urgent orders processed first
- Rate limiting - 200ms delay between messages to avoid Telegram limits
- Urgent (100+ points) - Cancelled, failed, stuck orders
- Completed (+50 points) - Delivered orders
- With Courier (+30 points) - Orders with assigned courier
- Recent Updates (+20 points) - Recently updated orders
- ✅ Include: New orders, status changes, deliveries, problems
- ❌ Exclude: Intermediate statuses, orders older than 24 hours
- 🚨 Urgent: Delays, cancellations, stuck orders
Uses existing D1 database yandex-delivery-history
:
-- Orders are marked for notification by yandex-delivery-core
SELECT * FROM delivery_orders
WHERE telegram_notified = false
ORDER BY updated_at DESC;
-- After successful notification
UPDATE delivery_orders
SET telegram_notified = true,
last_telegram_update = CURRENT_TIMESTAMP
WHERE claim_id IN (sent_orders);
- Telegram API Errors - Logged and retried on next cron run
- Database Issues - Health checks prevent processing when DB unavailable
- Admin Notifications - Critical errors sent to admin chat
- Graceful Degradation - Individual order failures don't stop batch processing
- Health Checks - Both API and scheduled health monitoring
- Comprehensive Logging - All operations logged with timestamps
- Statistics API - Real-time stats on notifications sent/failed
- Error Tracking - Failed notifications logged for debugging
- Create bot with @BotFather
- Get bot token
- Add bot to channel as administrator
- Get channel ID (e.g., @cvety_delivery_monitor)
- Configure secrets in Cloudflare Workers
- yandex-delivery-core - Creates/updates orders with
telegram_notified = false
- cvety-admin-react - Can view notification statistics via API
- Telegram Channel - Receives formatted notifications for monitoring team