Local Development
Set Up Local Secrets
Create a .dev.vars file in the project root:
BOT_TOKEN=your-bot-token-here
BOT_INFO={"id":123456789,"is_bot":true,"first_name":"MyBot","username":"MyBot","can_join_groups":true,"can_read_all_group_messages":false,"supports_inline_queries":true}
Initialize Local Database
npm run db:init:local
Start Dev Server
npm run dev
Wrangler starts a local server at http://localhost:8787.
Expose with a Tunnel
To receive Telegram webhooks locally, you need to expose your local server with a tunnel:
Using cloudflared:
cloudflared tunnel --url http://localhost:8787
Or using ngrok:
ngrok http 8787
Then register the webhook on the tunnel URL:
https://your-tunnel-url.trycloudflare.com/setup
Available Commands
| Command | Description |
|---|---|
npm run dev | Start local dev server (port 8787) |
npm run db:init:local | Apply migrations to local D1 |
npm run check | TypeScript + ESLint + Prettier check |
npm run lint | Run ESLint |
npm run lint:fix | Run ESLint with auto-fix |
npm run format | Format with Prettier |
npm run format:check | Check formatting without changes |