Skip to content

Repository files navigation

Telegram Bot TypeScript SDK

Docs Telegram Bot API Telegram WebApp

Type-safe TypeScript SDK for building Telegram bots. Types are generated from the official Bot API documentation; everything else is a thin layer over native fetch with zero runtime dependencies.

๐Ÿ“ฆ Packages

Package What it is Use it when
@effect-ak/tg-bot-api TypeScript types for the whole Bot API + Mini Apps (Telegram.WebApp), regenerated from https://core.telegram.org You only need types (own client, Mini App front-end)
@effect-ak/tg-bot-client HTTP client: client.execute("send_message", { โ€ฆ }) for every method, typed errors, automatic file uploads Sending notifications, managing channels, integrating Telegram in an app
@effect-ak/tg-bot Bot framework: fluent builder, guarded handlers, long polling or webhooks, inline-keyboard screens as data Building a bot โ€” locally, on a VPS, or on Cloudflare Workers / Bun / Deno

Dependency chain: api โ† client โ† bot. Method names are snake_case exactly as in the official docs.

๐Ÿš€ Quick Start

Bot Framework

npm install @effect-ak/tg-bot
import { createBot } from "@effect-ak/tg-bot"

await createBot()
  .command("/start", ({ ctx }) => ctx.reply("Welcome!"))
  .onText(({ payload, ctx }) => ctx.reply(`You said: ${payload.text}`))
  .run({ bot_token: "YOUR_BOT_TOKEN" })

HTTP Client

npm install @effect-ak/tg-bot-client
import { makeTgBotClient } from "@effect-ak/tg-bot-client"

const client = makeTgBotClient({
  bot_token: "YOUR_BOT_TOKEN"
})

await client.execute("send_message", {
  chat_id: 123456789,
  text: "Hello, World!"
})

Webhook on Cloudflare Workers, inline-keyboard UI as data

import { createBot, defineScreens } from "@effect-ak/tg-bot"

const screens = defineScreens({
  root: { text: "Main menu", buttons: [[{ label: "Hours", next: "hours" }]] },
  hours: { text: "Monโ€“Fri 9โ€“18", parent: "root" }
})

const bot = createBot().use(screens)

export default {
  fetch: (request: Request, env: Env) =>
    bot.webhook({ bot_token: env.BOT_TOKEN, secret_token: env.WEBHOOK_SECRET })(request)
}

A complete, deployable demo (several bots behind one token, KV state, GitHub Actions deploy) lives in example/.

๐ŸŽฏ Key Features

  • Always Up-to-Date: Types generated from official Telegram API documentation
  • Fully Type-Safe: Complete TypeScript support for all API methods and types; errors are tagged unions
  • Runs Anywhere: native fetch, no dependencies โ€” Node.js 18+, Bun, Deno, Cloudflare Workers, browsers
  • Polling or Webhooks: long polling needs no public URL; webhooks verify Telegram's secret token out of the box
  • Screens: inline-keyboard navigation declared as data (defineScreens) โ€” Back, actions, edit-in-place handled for you

๐Ÿ“š Documentation

Full documentation and API reference: tg-bot-sdk.website

๐Ÿค– For LLMs and Coding Agents

๐ŸŽฎ Playground

Try it in your browser: Telegram Bot Playground

๐Ÿ› ๏ธ Development

Setup

pnpm install
pnpm build

CI/CD

Push to main triggers two GitHub Actions workflows:

  1. Build โ€” runs pnpm build, pnpm typecheck, and pnpm test
  2. Release โ€” runs after a successful Build, uses changesets to version and publish packages to npm

To release a new version:

  1. Create a changeset: pnpm changeset
  2. Commit the generated changeset file and merge to main
  3. The Release workflow will open a "Release" PR that bumps versions
  4. Merge the PR โ€” packages are automatically published to npm

Packages are published with npm provenance via OIDC between GitHub Actions and npm, so every published version is cryptographically signed and linked back to its source commit and workflow run.

About

A comprehensive library with full Telegram Bot API type support

Topics

Resources

Stars

29 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages