Files
vercel__chat/packages/adapter-telegram
github-actions[bot] 28cbcb2994 Version Packages (#192)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2026-03-07 12:39:16 -08:00
..
2026-03-07 12:39:16 -08:00
2026-03-07 12:39:16 -08:00
2026-02-27 09:58:28 -08:00

@chat-adapter/telegram

npm version npm downloads

Telegram adapter for Chat SDK.

Installation

npm install chat @chat-adapter/telegram

Usage

import { Chat } from "chat";
import { createTelegramAdapter } from "@chat-adapter/telegram";

const bot = new Chat({
  userName: "mybot",
  adapters: {
    telegram: createTelegramAdapter({
      botToken: process.env.TELEGRAM_BOT_TOKEN!,
    }),
  },
});

Features include mentions, reactions, typing indicators, file uploads, and card fallback rendering with inline keyboard buttons for card actions.

Polling mode

When developing locally, you typically can't expose a public URL for Telegram to send webhooks to. Polling mode uses getUpdates to fetch messages directly from Telegram instead — no public endpoint needed.

The longPolling option is entirely optional. Sensible defaults are applied when omitted.

import { createMemoryState } from "@chat-adapter/state-memory";

const telegram = createTelegramAdapter({
  botToken: process.env.TELEGRAM_BOT_TOKEN!,
  mode: "polling",
  // Optional — fine-tune polling behavior:
  // longPolling: { timeout: 30, dropPendingUpdates: false },
});

const bot = new Chat({
  userName: "mybot",
  adapters: { telegram },
  state: createMemoryState(),
});

// Optional manual control
await telegram.resetWebhook();
await telegram.startPolling();
await telegram.stopPolling();

Auto mode

With mode: "auto" (the default), the adapter picks the right strategy for you. In a serverless environment like Vercel it uses webhooks; everywhere else (e.g. local dev) it falls back to polling.

const telegram = createTelegramAdapter({
  botToken: process.env.TELEGRAM_BOT_TOKEN!,
  mode: "auto", // default
});

const bot = new Chat({
  userName: "mybot",
  adapters: { telegram },
  state: createMemoryState(),
});

// Call initialize() so polling can start in long-running local processes:
void bot.initialize();

console.log(telegram.runtimeMode); // "webhook" | "polling"

Documentation

Full setup instructions, configuration reference, and features at chat-sdk.dev/docs/adapters/telegram.

License

MIT