@teactjs/telegram
TelegramAdapter (grammY driver) plus conversation and streaming plugins, serializeOutput, and defineConversation.
The production transport for Teact. TelegramAdapter bridges the core reconciler to the Telegram
Bot API via grammY and supports both polling and webhook (edge) modes. The package also ships the
imperative conversation and streaming plugins.
bun add @teactjs/telegramExports
| Export | Kind | Description |
|---|---|---|
TelegramAdapter | class | Adapter passed to createBot({ adapter }). |
serializeOutput | function | Serialize a rendered output tree to a Telegram send payload. |
conversationsPlugin | plugin | Enables imperative async/await conversation flows. |
defineConversation | function | Declare a named conversation handler. |
streamPlugin | plugin | Enables token streaming into a message (useStream). |
TelegramAdapterConfig, TelegramSendPayload | types | Adapter options and payload shape. |
Conversation, ConversationHandler, ConversationDef, ConversationsPluginOptions, ConversationsConfig, MediaGroupItem | types | Conversation typings. |
Polling (default)
new TelegramAdapter() reads the bot token from the environment (via createBot). Guard the
polling call so it does not run when the module is imported (e.g. on edge):
import { createBot } from "@teactjs/core";
import { TelegramAdapter } from "@teactjs/telegram";
const bot = createBot({
component: App,
adapter: new TelegramAdapter(),
});
if (import.meta.main) bot.start();Webhook / edge
On serverless runtimes, call bot.fetch(request, { token, secretToken }) from your handler instead
of start(). The isolate freezes once the Response resolves, so pass plugins directly to
createBot({ plugins }) (the config file is not loaded on edge) and provide a durable
SessionStore.
Conversations
import { conversationsPlugin, defineConversation } from "@teactjs/telegram";
const onboarding = defineConversation("onboarding", async (convo) => {
const name = await convo.prompt("What's your name?");
await convo.send(`Welcome, ${name}!`);
});
// createBot({ plugins: [conversationsPlugin()] })Streaming
import { streamPlugin } from "@teactjs/telegram";
// createBot({ plugins: [streamPlugin()] }) — then useStream() in a componentSee the Telegram adapter guide for polling vs webhook setup, the Conversations guide, and the Streaming guide.