A tiny cron-style Node.js app that posts Telegram channel statistics (from TGStat) to a Telegram channel as one photo message (TGStat widget image + HTML caption + inline CTA button).
- Weekly scheduled run (Railway Cron Job)
- Fetches TGStat
/channels/statJSON and maps metrics into a readable caption - Downloads the TGStat widget PNG and uploads it as a Telegram photo
- Attaches an inline CTA button directly to the photo message
- Optional
TG_STAT_MOCKmode to run without calling TGStat (useful when API limits are hit)
- Node.js 26+
- pnpm 12+
- Telegram Bot token
- TGStat API token
Required:
TELEGRAM_ADS_BOT_TOKEN— Telegram bot tokenTELEGRAM_CHAT_ID— target chat/channel id (e.g.-100...)TGSTAT_TOKEN— TGStat API tokenTGSTAT_CHANNEL_ID— TGStat channel idTGSTAT_WIDGET_URL— TGStat widget image URL (.../stat-widget.png)CTA_URL— URL used in the inline button
Optional:
PORT— default3000(not used in cron mode, but kept for compatibility)TG_STAT_MOCK— set to1ortrueto use mocked TGStat data
pnpm install
pnpm typecheck
pnpm test
# Run one-off locally
pnpm cron- Create a new Railway project and connect this repository.
- Set the environment variables listed above.
- Create a Railway Cron Job:
- Build command:
pnpm install --frozen-lockfile && pnpm build - Run command:
pnpm cron:prod - Schedule: every Monday at 08:00 UTC (or whatever you need)
- Build command:
- Each run publishes a new post; previous posts are not deleted. Telegram bots can only delete channel messages younger than 48 hours, so with a weekly schedule the old post is always out of reach.
- Telegram photo captions have a size limit. If the caption becomes too long, you may need to shorten it or split into multiple messages.
MIT — see LICENSE.