AgentSkillsCN

gramio

GramIO——一款适用于Node.js、Bun与Deno的类型安全TypeScript Telegram Bot API框架。适用于构建Telegram机器人、处理命令/回调/内联查询、创建键盘布局、格式化消息、上传文件、管理会话/场景、编写插件、配置Webhook,或集成Telegram支付功能。

SKILL.md
--- frontmatter
name: gramio
description: GramIO — type-safe TypeScript Telegram Bot API framework for Node.js, Bun, and Deno. Use when building Telegram bots, handling commands/callbacks/inline queries, creating keyboards, formatting messages, uploading files, managing sessions/scenes, writing plugins, setting up webhooks, or integrating Telegram payments.
metadata:
  author: GramIO
  version: "2026.2.14"
  source: https://github.com/gramiojs/documentation

GramIO

GramIO is a modern, type-safe Telegram Bot API framework for TypeScript. It runs on Node.js, Bun, and Deno with full Bot API coverage, a composable plugin system, and first-class TypeScript support.

When to Use This Skill

  • Creating or modifying Telegram bots
  • Setting up bot commands, callbacks, inline queries, or reactions
  • Building keyboards (reply, inline, remove, force reply)
  • Formatting messages with entities (bold, italic, code, links, mentions)
  • Uploading/downloading files and media
  • Managing user sessions or multi-step conversation flows (scenes)
  • Writing custom plugins
  • Configuring webhooks or long polling
  • Handling payments with Telegram Stars
  • Broadcasting messages with rate limit handling
  • Building Telegram Mini Apps (TMA) with backend auth
  • Containerizing bots with Docker
  • Using standalone @gramio/types for custom Bot API wrappers
  • Writing and publishing custom plugins

Quick Start

bash
npm create gramio bot-name
cd bot-name
npm run dev

Basic Pattern

typescript
import { Bot } from "gramio";

const bot = new Bot(process.env.BOT_TOKEN as string)
    .command("start", (context) => context.send("Hello!"))
    .onStart(({ info }) => console.log(`@${info.username} started`))
    .onError(({ context, kind, error }) => console.error(`[${kind}]`, error));

bot.start();

Critical Concepts

  1. Method chaining — handlers, hooks, and plugins chain via .command(), .on(), .extend(), etc. Order matters.
  2. Type-safe context — context is automatically typed based on the update type. Use context.is("message") for type narrowing in generic handlers.
  3. Plugin systemnew Plugin("name").derive(() => ({ ... })) adds typed properties to context. Register via bot.extend(plugin).
  4. Hooks lifecycle — onStart → (updates with onError) → onStop. API calls: preRequest → call → onResponse/onResponseError.
  5. Error suppressionbot.api.method({ suppress: true }) returns error instead of throwing.
  6. Lazy plugins — async plugins (without await) load at bot.start(). Use await for immediate loading.
  7. Derive vs Decorate.derive() runs per-update (computed), .decorate() injects static values once.

Official Plugins

PluginPackagePurpose
Session@gramio/sessionPersistent per-user data storage
Scenes@gramio/scenesMulti-step conversation flows
I18n@gramio/i18nInternationalization (TS-native or Fluent)
Autoload@gramio/autoloadFile-based handler loading
Prompt@gramio/promptInteractive single-question prompts
Auto Retry@gramio/auto-retryRetry on 429 rate limits
Media Cache@gramio/media-cacheCache file_ids
Media Group@gramio/media-groupHandle album messages
Split@gramio/splitSplit long messages
Auto Answer CB@gramio/auto-answer-callback-queryAuto-answer callbacks
PostHog@gramio/posthogAnalytics + feature flags

References

Core

TopicDescriptionReference
Bot ConfigurationConstructor, API options, proxy, test DC, debuggingbot-configuration
Bot APICalling methods, suppress, withRetries, type helpersbot-api
Context & Updatesderive, decorate, middleware, start/stop, type narrowingcontext
Triggerscommand, hears, callbackQuery, inlineQuery, reactiontriggers
HooksonStart, onStop, onError, preRequest, onResponsehooks
Updates & Lifecyclestart/stop options, graceful shutdown (SIGINT/SIGTERM)updates

Features

TopicDescriptionReference
KeyboardsKeyboard, InlineKeyboard, layout helpers, stylingkeyboards
Formattingbold, italic, code, pre, link, mention, joinformatting
FilesMediaUpload, MediaInput, download, Bun.file()files
CallbackDataType-safe callback data schemascallback-data
StorageIn-memory, Redis, Cloudflare adaptersstorage
Telegram StarsPayments, invoices, subscriptions, inline invoices, refunds, test modetelegram-stars
Types@gramio/types, type helpers, Proxy wrapper, declaration mergingtypes

Infrastructure

TopicDescriptionReference
WebhookFramework integration, tunneling, custom handlerswebhook
Rate LimitswithRetries, broadcasting, queuesrate-limits
DockerDockerfile, multi-stage build, Docker Composedocker
TMAMini Apps, mkcert HTTPS, @gramio/init-data authtma

Plugins

PluginDescriptionReference
SessionPer-user data, Redis supportsession
ScenesMulti-step flows, state, navigationscenes
I18nTS-native and Fluent internationalizationi18n
AutoloadFile-based handler discoveryautoload
PromptSend + wait for responseprompt
Othersauto-retry, media-cache, media-group, split, posthogother
Plugin DevelopmentWriting custom plugins, derive/decorate/error, lazy loadingplugin-development

Examples

ExampleDescriptionFile
Basic botCommands, hooks, error handlingbasic.ts
KeyboardsReply, inline, columns, conditionalkeyboards.ts
CallbackDataType-safe callback schemascallback-data.ts
FormattingAll entity types, join helperformatting.ts
File uploadPath, URL, buffer, media groupsfile-upload.ts
Error handlingCustom errors, suppress, scopederror-handling.ts
WebhookFramework integrationwebhook.ts
SessionCounters, settings, Redissession.ts
ScenesRegistration flow with stepsscenes.ts
Telegram StarsPayments, invoices, refundstelegram-stars.ts
TMAElysia server, init-data auth, webhooktma.ts
DockerGraceful shutdown, webhook/polling toggledocker.ts