Skip to content

Rewrite bot to TypeScript + grammY with webhook-first design and Heroku deploy support#29

Draft
Copilot wants to merge 2 commits into
masterfrom
copilot/refactor-bot-to-typescript
Draft

Rewrite bot to TypeScript + grammY with webhook-first design and Heroku deploy support#29
Copilot wants to merge 2 commits into
masterfrom
copilot/refactor-bot-to-typescript

Conversation

Copilot AI commented Apr 1, 2026

Copy link
Copy Markdown

The bot was written in plain JS using Telegraf, relied on Redis/Bull for queuing, and lacked proper Heroku deployment artifacts. This rewrites it in TypeScript with grammY, switches to webhook delivery, and makes the configuration fully generic for any GitHub Pages target.

Core rewrite

  • index.jssrc/index.ts — strict TypeScript throughout; tsconfig.json compiles to dist/
  • Telegraf → grammY — modern, actively maintained bot framework with first-class TS types
  • Bull + Redis removed — replaced with a simple in-memory sequential queue; no add-ons needed on Heroku
  • telegraf-i18n removed — replaced with a tiny YAML + regex helper reusing the existing locales/ru.yaml unchanged
  • dotenv-loaddotenv

Webhook delivery

if (WEBHOOK_URL) {
  await bot.api.setWebhook(webhookUrl)         // registers with Telegram
  createServer(handleUpdate).listen(PORT)      // plain http server
} else {
  await bot.start()                            // long polling for local dev
}

lastCommand state is persisted to disk so it survives Heroku dyno restarts between webhook calls.

Heroku deployment

  • Procfile: web: node dist/index.js
  • app.json now declares every required config var with descriptions (enables the one-click deploy button)
  • Dockerfile updated to a multi-stage Node 20-alpine build

Universality

All paths and the deploy command are env-var-driven — no hardcoded project assumptions remain:

Var Purpose
DATA_FOLDER Where JSON data files are written
IMAGES_FOLDER Where downloaded images are stored
IMAGES_SLUG URL prefix for images in generated JSON
RUN_COMMAND Arbitrary shell command run after each batch (e.g. git push)

Tooling

  • ESLint migrated to v9 flat config (eslint.config.js) with @typescript-eslint
  • Pre-commit hook updated to lint .ts files
  • npm test now runs lint + tsc compile check
Original prompt
  1. Перепиши бота на использование typescript + grammy
  2. Сделай его доступным через webhook а не long polling.
  3. Подготовь для легкого деплоя на Heroku
  4. Сделай его более универсальным, так чтобы его можно было использовать для GitHub pages с любым изначальным источником.

Copilot AI changed the title [WIP] Refactor bot to use TypeScript and grammy framework Rewrite bot to TypeScript + grammY with webhook-first design and Heroku deploy support Apr 1, 2026
Copilot AI requested a review from jfkz April 1, 2026 22:49
Copilot finished work on behalf of jfkz April 1, 2026 22:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants