A production-ready Cloudflare Worker that automatically checks DESCO prepaid electricity meter balances daily and sends notifications via Telegram.
- ✅ Automated Daily Checks: Runs every day at 1:00 AM (Asia/Dhaka timezone)
- ✅ Multiple Accounts: Supports checking multiple DESCO account numbers
- ✅ Telegram Notifications: Sends formatted balance updates to your Telegram chat
- ✅ Retry Logic: Implements exponential backoff for API failures
- ✅ Manual Trigger: Test anytime via
/runendpoint - ✅ Error Handling: Robust error handling with detailed logging
- ✅ Zero Dependencies: Uses only Cloudflare Workers runtime
- ✅ Multiple Account Support: You Can get balance notification for multiple accounts
🔌 DESCO Prepaid Balance Update
🕐 20 Oct 2025, 1:00 AM (Asia/Dhaka)
• Account 12345511 → 374.04 ৳
• Account 12345512 → 250.32 ৳
💰 Total Balance: 624.36 ৳
- Node.js (v18 or later)
- npm or yarn
- Cloudflare account (free tier works)
- Telegram bot token and chat ID
cd ./desco-balance-notification
npm install- Open Telegram and search for @BotFather
- Send
/newbotand follow the instructions - Save the bot token (looks like
123456789:ABCdefGHIjklMNOpqrsTUVwxyz) - Start a chat with your new bot and send any message
- Get your chat ID by visiting:
Look for
https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getUpdates"chat":{"id":123456789}in the response
Set your secrets using the Wrangler CLI:
# Set Telegram Bot Token
wrangler secret put TELEGRAM_BOT_TOKEN
# When prompted, paste your bot token
# Set Telegram Chat ID
wrangler secret put TELEGRAM_CHAT_ID
# When prompted, paste your chat ID (e.g., 123456789)
# Set Account Numbers (comma-separated)
wrangler secret put ACCOUNT_NUMBERS
# When prompted, enter: 12345511,12345512,12345513
# Or as JSON array: ["12345511","12345512","12345513"]Alternative: Use npm scripts
npm run secret:telegram-token
npm run secret:chat-id
npm run secret:accounts# Start local development server
npm run dev
# In another terminal, test the endpoint
curl http://localhost:8787/runnpm run deployAfter deployment, you'll get a URL like:
https://desco-balance-notification.<your-subdomain>.workers.dev
The worker runs automatically every day at 1:00 AM Asia/Dhaka time (19:00 UTC).
Test the worker anytime by visiting:
https://desco-balance-notification.<your-subdomain>.workers.dev/run
Or use curl:
curl https://desco-balance-notification.<your-subdomain>.workers.dev/runcurl https://desco-balance-notification.<your-subdomain>.workers.dev/healthThe cron trigger is configured in wrangler.toml:
[triggers]
crons = ["0 19 * * *"] # 1:00 AM Asia/Dhaka (UTC+6)To change the schedule, modify the cron expression:
0 19 * * *= 1:00 AM Dhaka0 13 * * *= 7:00 PM Dhaka0 0 * * *= 6:00 AM Dhaka
You can specify account numbers in two formats:
Comma-separated:
12345511,12345512,12345513
JSON array:
["12345511","12345512","12345513"]desco-balance-notification/
├── src/
│ └── index.ts # Main worker code
├── wrangler.toml # Cloudflare Workers configuration
├── package.json # Dependencies and scripts
├── tsconfig.json # TypeScript configuration
├── .gitignore # Git ignore rules
└── README.md # This file
GET https://prepaid.desco.org.bd/api/unified/customer/getBalance?accountNo=12345511
Response:
{
"code": 200,
"desc": "OK",
"data": {
"accountNo": "12345511",
"meterNo": "1234556025",
"balance": 374.04,
"currentMonthConsumption": null,
"readingTime": "2025-10-20"
}
}POST https://api.telegram.org/bot<token>/sendMessage
# Stream real-time logs
npm run tail
# Or directly with wrangler
wrangler tailVisit the Cloudflare Dashboard:
- Go to Workers & Pages
- Select your worker
- Click on "Triggers" tab
- View cron trigger history
-
Check secrets are set correctly:
wrangler secret list
-
Verify bot token and chat ID:
curl "https://api.telegram.org/bot<YOUR_TOKEN>/getMe" -
Check worker logs:
npm run tail
The worker implements retry logic with exponential backoff. If DESCO API is slow:
- Default timeout: 10 seconds
- Retries: 3 attempts
- Backoff: 1s, 2s, 3s
- Cron triggers only work on deployed workers (not local dev)
- Check the Cloudflare dashboard for trigger history
- Verify the cron expression in
wrangler.toml
- ✅ Secrets are stored securely in Cloudflare's encrypted storage
- ✅ Never commit secrets to git
- ✅ Account numbers are treated as sensitive data
- ✅ Use Telegram bot tokens, not user tokens
Cloudflare Workers Free Tier includes:
- 100,000 requests/day
- 10ms CPU time per request
This worker uses:
- 1 cron trigger/day
- ~2-5ms CPU time per run
- Well within free tier limits
MIT
For issues or questions:
- Check the Cloudflare Workers docs
- Review the worker logs with
wrangler tail - Test the DESCO API directly to verify it's working
Powered Cloudflare Workers