Skip to main content

Quick Start

Install the plugin:
pnpm install @corsair-dev/telegram
Add the Telegram plugin to your Corsair instance:
corsair.ts
import { createCorsair } from "corsair";
import { telegram } from "@corsair-dev/telegram";

export const corsair = createCorsair({
    plugins: [telegram()],
    database: db,
    kek: process.env.CORSAIR_KEK!,
});

Authentication

Supported Auth Types

  • bot_token (default) - Telegram bot token

Bot Token Setup

pnpm corsair setup --telegram bot_token=your-bot-token
See Get Credentials for step-by-step instructions.

Options

OptionTypeDescription
authType'bot_token'Authentication method
keystringBot token (optional, uses database if not provided)
webhookSecretstringWebhook secret token (optional)
hooksobjectEndpoint hooks for custom logic
webhookHooksobjectWebhook hooks for event handling
errorHandlersobjectCustom error handlers

Usage

// Send a message
await corsair.telegram.api.messages.sendMessage({
    chat_id: "@mychannel",
    text: "Hello from Corsair!",
});

// Send a photo
await corsair.telegram.api.messages.sendPhoto({
    chat_id: "123456789",
    photo: "https://example.com/image.png",
    caption: "Check this out",
});

// Get chat info
const chat = await corsair.telegram.api.chat.getChat({
    chat_id: "@mychannel",
});

// Get bot info
const me = await corsair.telegram.api.updates.getMe({});

// Get updates (polling)
const updates = await corsair.telegram.api.updates.getUpdates({
    limit: 10,
});

Multi-Tenancy

const tenant = corsair.withTenant("user-123");

await tenant.telegram.api.messages.sendMessage({
    chat_id: "123456789",
    text: "Message for this tenant",
});