@tgwrapper/starter-migration
v0.2.6
Published
Migration starter for moving Telegraf or grammY bots to TGWrapper
Maintainers
Readme
TGWrapper Migration Starter
Requirements: Node.js
>=22.13,pnpm,tsx, Redis>=6.2Use case: side-by-side migration reference from Telegraf-style handlers to TGWrapper.
Included: before/after sample entrypoints, Redis session adapter wiring, and production deployment notes.
Template package for migrating a stateful Telegram bot from Telegraf-style handlers to TGWrapper with Redis-backed sessions, Compare-and-Swap writes, and structured logs.
Use this starter when you want a side-by-side migration reference:
src/bot-before.tsshows the Telegraf baseline.src/bot-after.tsshows the TGWrapper implementation.dist/contains built JavaScript entrypoints afterpnpm build.
Quick Start
pnpm create @tgwrapper my-migration-bot --template migration
cd my-migration-bot
cp .env.example .env
pnpm installEdit .env, then run one of the entrypoints:
export BOT_TOKEN="your_botfather_token"
export REDIS_URL="redis://localhost:6379"
pnpm tsx src/bot-before.ts
pnpm tsx src/bot-after.tsExpected TGWrapper startup output:
{
"event": "startup",
"serviceName": "registration-service",
"mode": "polling",
"redisUrl": "redis://localhost:6379"
}Environment Variables
| Name | Required | Default | Description |
| ----------- | -------- | ------------------------ | ------------------------------------------------------- |
| BOT_TOKEN | yes | none | Telegram bot token from BotFather. |
| REDIS_URL | no | redis://localhost:6379 | Redis connection used by the TGWrapper session adapter. |
What Gets Installed
The npm package is a project template, not a library API. It ships:
src/bot-before.tssrc/bot-after.ts- compiled
dist/files README.mdCHANGELOG.mdtsconfig.json.env.example
Copy the files into your own application and then change package name, commands, Redis topology, tenant IDs, bot IDs, telemetry destinations, and handlers.
What You Still Need to Implement
- Your application-specific session state schema and migration path.
- The production event flow and webhook/runtime integration.
- Secret management for
BOT_TOKENandREDIS_URL. - Any stateful user routing or service-specific business logic.
Manual Copy Fallback
Power users can install this package directly and copy the template files:
pnpm add -D @tgwrapper/starter-migration
mkdir my-migration-bot
cp -R node_modules/@tgwrapper/starter-migration/{src,tsconfig.json,.env.example} my-migration-bot/Migration Checklist
- Install
@tgwrapper/core,@tgwrapper/adapter-redis, and@tgwrapper/observability. - Define a strict session state interface with
version: number. - Replace implicit
ctx.sessionmutations with explicitcompareAndSetwrites. - Replace
ctx.reply(...)withbot.sendMessage(...). - Attach observability during startup.
- Handle
SIGINTandSIGTERMto stop polling and close Redis.
How This Maps to Production
This starter uses polling because it is easiest for local migration work. For production:
- switch the TGWrapper client to webhook mode;
- expose the webhook handler from your HTTP platform;
- keep Redis shared across all running instances;
- route JSON logs to your production log pipeline;
- keep
BOT_TOKENand Redis credentials in your secret manager.
