Skip to main content

npm scripts

ScriptCommandDescription
npm run devtsx watch src/bot/index.tsDevelopment mode — auto-reloads on file changes
npm run buildtscCompiles TypeScript to dist/
npm startnode dist/bot/index.jsProduction mode — runs the compiled output
npm run test:dealstsx src/scripts/testDeals.tsRuns the deals pipeline standalone, without launching the bot
Use npm run test:deals to verify your credentials and filter settings before starting the bot. It runs the full two-layer pipeline and prints results to stdout without sending anything to Telegram.

Startup sequence

When the bot process starts (src/bot/index.ts), it executes the following steps in order:
1

Clear stale snapshot

clearStaleSnapshot() is called immediately. If data/snapshot.json was written on a previous calendar day, it is deleted so the bot does not serve outdated deals.
2

Create bot instance

A Telegraf bot instance is created using the BOT_TOKEN from config.
3

Register commands

registerCommands(bot) attaches handlers for /start, /deals, /stop, and /help.
4

Start the scheduler

startScheduler() initializes the node-cron job that broadcasts deals to all subscribers on the configured schedule (default: 0 9 * * * — 9 AM Colombia time).
5

Launch the bot

bot.launch() connects to the Telegram API via long polling and begins processing incoming messages.
The bot uses long polling, not webhooks. It initiates outbound connections to the Telegram API — no inbound port needs to be open on your server.

Graceful shutdown

The process listens for SIGINT (Ctrl+C) and SIGTERM (sent by process managers and container runtimes) and calls bot.stop() on either signal:
process.once('SIGINT', () => bot.stop('SIGINT'));
process.once('SIGTERM', () => bot.stop('SIGTERM'));
This ensures in-flight requests are completed and the Telegram session is cleanly closed before the process exits.

Build docs developers (and LLMs) love