Skip to content

About

Weekly TGStat stats → Telegram post (widget + caption + CTA), with Postgres state.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

tgstat-to-ads

TGStat → Telegram Ads

CI PRs Node TypeScript Platform

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).

Features

  • Weekly scheduled run (Railway Cron Job)
  • Fetches TGStat /channels/stat JSON 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_MOCK mode to run without calling TGStat (useful when API limits are hit)

Requirements

  • Node.js 26+
  • pnpm 12+
  • Telegram Bot token
  • TGStat API token

Environment variables

Required:

  • TELEGRAM_ADS_BOT_TOKEN — Telegram bot token
  • TELEGRAM_CHAT_ID — target chat/channel id (e.g. -100...)
  • TGSTAT_TOKEN — TGStat API token
  • TGSTAT_CHANNEL_ID — TGStat channel id
  • TGSTAT_WIDGET_URL — TGStat widget image URL (.../stat-widget.png)
  • CTA_URL — URL used in the inline button

Optional:

  • PORT — default 3000 (not used in cron mode, but kept for compatibility)
  • TG_STAT_MOCK — set to 1 or true to use mocked TGStat data

Local development

pnpm install
pnpm typecheck
pnpm test

# Run one-off locally
pnpm cron

Railway setup

  1. Create a new Railway project and connect this repository.
  2. Set the environment variables listed above.
  3. 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)

Notes

  • 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.

License

MIT — see LICENSE.

About

Weekly TGStat stats → Telegram post (widget + caption + CTA), with Postgres state.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages