Quick start
Run your first Teact bot — token, entry file, createBot, and TelegramAdapter in a few steps.
You need Bun and a bot token from @BotFather.
Step 1 — Install
Scaffold a new project (recommended) — pick a template and features interactively:
bun create teact my-bot
cd my-bot
bun installOr add Teact to an existing project:
bun add @teactjs/core @teactjs/ui @teactjs/telegram reactComponents come from @teactjs/ui; createBot, the router, and all hooks come from
@teactjs/core; the grammY-powered adapter is @teactjs/telegram. react is a peer
dependency. See Installation for npm/pnpm and details.
Step 2 — Token
Create .env in the project root:
# .env
TELEGRAM_BOT_TOKEN=your_token_hereThe token env var is always TELEGRAM_BOT_TOKEN — createBot reads process.env.TELEGRAM_BOT_TOKEN when no explicit token is passed.
Step 3 — Entry file
A minimal bot wires a root component and the Telegram adapter:
import { createBot, useState } from "@teactjs/core";
import { Message, Button, InlineKeyboard } from "@teactjs/ui";
import { TelegramAdapter } from "@teactjs/telegram";
function Counter() {
const [count, setCount] = useState(0);
return (
<Message text={`Count: ${count}`}>
<InlineKeyboard>
<Button text="-1" onClick={() => setCount((c) => c - 1)} />
<Button text="+1" onClick={() => setCount((c) => c + 1)} />
</InlineKeyboard>
</Message>
);
}
const bot = createBot({
component: Counter,
adapter: new TelegramAdapter(),
token: process.env.TELEGRAM_BOT_TOKEN!,
});
if (import.meta.main) bot.start();Guarding bot.start() behind import.meta.main keeps long-running polling out of the module when the
same file is imported elsewhere (e.g. a serverless handler that calls bot.fetch(request) instead).
Step 4 — Run
bun devOpen Telegram, find your bot, send a message or /start. You should see the counter and inline buttons.
Step 5 — Router (optional)
For multiple screens, swap component for a router. createRouter(routes, options?) maps paths to
components:
import { createBot, createRouter } from "@teactjs/core";
import { TelegramAdapter } from "@teactjs/telegram";
const router = createRouter({
"/": Home,
"/about": About,
});
const bot = createBot({
router,
adapter: new TelegramAdapter(),
token: process.env.TELEGRAM_BOT_TOKEN!,
});component and router are mutually exclusive. See Router for guards, params, and navigation.
Step 6 — Bot commands (optional)
Register Telegram menu commands and deep links via createBot({ commands: { ... } }). See Commands.