Code-generated and Auto-published Telegram Bot API types
Versioning
7.0.x types - for 7.0 Telegram Bot API
import type { ApiMethods } from "@gramio/types";
type SendMessageReturn = ReturnType<ApiMethods["sendMessage"]>;
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
- exports ApiMethods
which describes the api functionsobjects
- exports objects with the Telegram
prefix (for example Update)params
- exports params that are used in methods
Write you own type-safe Telegram Bot API wrapper
import type { ApiMethods, 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: Parameters<ApiMethods[T]>[0]) => {
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",
});
import { Keyboard } from "@gramio/keyboards";
api.sendMessage({
chat_id: 1,
text: "message with keyboard",
reply_markup: new Keyboard().text("button text"),
});
With File uploading support
Documentation
Generate types manually
Prerequire - rust
- Clone this repo and open it
git clone https://github.com/gramiojs/types.git
- Clone repo with Telegram Bot API schema generator
git clone https://github.com/ark0f/tg-bot-api.git
- Run the JSON schema generator in the
cloned
folder
cd tg-bot-api && cargo run --package gh-pages-generator --bin gh-pages-generator -- dev && cd ..
- Run types code-generation from the
root
of the project
bun generate
or, if you don't use bun
, use tsx
npx tsx src/index.ts
- Profit! Check out the types of Telegram Bot API in
out
folder!