Built and signed on GitHub ActionsBuilt and signed on GitHub Actions
Built and signed on GitHub Actions
latest
gramiojs/typesWorks with
•JSR Score100%•This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers




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
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 sectionmethods- exportsAPIMethodswhich describes the api functionsobjects- exports objects with theTelegramprefix (for example Update)params- exports params that are used inmethodswithParamspostfix
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
Generate types manually
Types are generated by fetching the live Telegram Bot API docs via @gramio/schema-parser.
- Clone this repo and open it
git clone https://github.com/gramiojs/types.git
- Install dependencies
bun install
- Run types code-generation
bun generate
- Profit! Check out the types of Telegram Bot API in
outfolder!
Examples
Built and signed on
GitHub Actions
Add Package
deno add jsr:@gramio/types
Import symbol
import * as types from "@gramio/types";
Import directly with a jsr specifier
import * as types from "jsr:@gramio/types";