Telegram botları2 dakikalık okuma

Deploy a TypeScript Telegraf bot to a Node.js worker

Host compiled Telegraf code with its production dependencies, check the entry file and verify polling after a redeploy.

Compile the TypeScript app

For a project with src/index.ts, configure TypeScript to produce dist/index.js. Keep telegraf in dependencies so the production install includes it. Match the emitted module format to package.json. With a NodeNext build and "type": "module", use ESM imports in your source.

Run your project’s build locally. Upload the dist directory, package.json, and the lockfile to a Node.js polling botu deployment from Telegram bot hosting.

Run the built entry file

Set MAIN_FILE şuraya dist/index.js and store TELEGRAM_BOT_TOKEN in Variables. Bring up the hosted copy only after stopping the old poller. An example entry using signals supported by the Telegraf polling runner looks like this.

src/index.ts
import { Telegraf } from 'telegraf';

const token = process.env.TELEGRAM_BOT_TOKEN;
if (!token) throw new Error('Set TELEGRAM_BOT_TOKEN in Variables');
const bot = new Telegraf(token);
bot.command('release', (ctx) => ctx.reply('Telegraf build is running'));

process.once('SIGINT', () => bot.stop('SIGINT'));
process.once('SIGTERM', () => bot.stop('SIGTERM'));
await bot.launch();

Check the release that is actually running

Gönder /release in a private chat. Change the response locally, rebuild, upload the new output and restart the worker. If the reply still has the old text, check that the entry file points to the uploaded output and the same bot token is saved.

A module-not-found error before polling usually points to an omitted dependency, wrong build path or inconsistent module format. Check Console before changing any Telegram settings. Telegraf startup and shutdown examples.