Skip to main content

@gramio/types@10.1.0
Built and signed on GitHub Actions

Works with
This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score100%
License
MIT
Downloads5/wk
Published2 weeks ago (10.1.0)

Code-generated and Auto-published Telegram Bot API types

Code-generated and Auto-published Telegram Bot API types

Bot API npm npm downloads JSR JSR Score

Versioning

9.0.x types are for 9.0 Telegram Bot API

Usage as an NPM package

import type { APIMethods, APIMethodReturn } from "@gramio/types";

type SendMessageReturn = Awaited<ReturnType<APIMethods["sendMessage"]>>;
//   ^? type SendMessageReturn = TelegramMessage

type GetMeReturn = APIMethodReturn<"getMe">;
//   ^? type GetMeReturn = TelegramUser

Please see API Types References

Auto-update package

This library is updated automatically to the latest version of the Telegram Bot API in case of changes thanks to CI CD! If the github action failed, there are no changes in the Bot API

Imports (after @gramio/)

  • index - exports everything in the section
  • methods - exports APIMethods which describes the api functions
  • objects - exports objects with the Telegram prefix (for example Update)
  • params - exports params that are used in methods with Params postfix

Write you own type-safe Telegram Bot API wrapper

import type {
    APIMethods,
    APIMethodParams,
    TelegramAPIResponse,
} from "@gramio/types";

const TBA_BASE_URL = "https://api.telegram.org/bot";
const TOKEN = "";

const api = new Proxy({} as APIMethods, {
    get:
        <T extends keyof APIMethods>(_target: APIMethods, method: T) =>
        async (params: APIMethodParams<T>) => {
            const response = await fetch(`${TBA_BASE_URL}${TOKEN}/${method}`, {
                method: "POST",
                headers: {
                    "Content-Type": "application/json",
                },
                body: JSON.stringify(params),
            });

            const data = (await response.json()) as TelegramAPIResponse;
            if (!data.ok) throw new Error(`Some error occurred in ${method}`);

            return data.result;
        },
});

api.sendMessage({
    chat_id: 1,
    text: "message",
});

Usage with @gramio/keyboards

import { Keyboard } from "@gramio/keyboards";

// the code from the example above

api.sendMessage({
    chat_id: 1,
    text: "message with keyboard",
    reply_markup: new Keyboard().text("button text"),
});

With File uploading support

Documentation

Generate types manually

Types are generated by fetching the live Telegram Bot API docs via @gramio/schema-parser.

  1. Clone this repo and open it
git clone https://github.com/gramiojs/types.git
  1. Install dependencies
bun install
  1. Run types code-generation
bun generate
  1. Profit! Check out the types of Telegram Bot API in out folder!

Examples

import

import { TelegramUser, SendMessageParams, APIMethods, APIMethodReturn } from "@gramio/types";

Based on Bot API v10.1 (11.06.2026)

Generated at 11.06.2026, 18:06:00 using types and schema generators

Built and signed on
GitHub Actions

Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@gramio/types

Import symbol

import * as types from "@gramio/types";
or

Import directly with a jsr specifier

import * as types from "jsr:@gramio/types";