Gathering detailed insights and metrics for @telegraf/types
Gathering detailed insights and metrics for @telegraf/types
Gathering detailed insights and metrics for @telegraf/types
Gathering detailed insights and metrics for @telegraf/types
typegram
Type declarations for the Telegram API
telegraf-session-local
Telegraf local sessions middleware with multiple supported storage types (Memory/FileSync/FileAsync/...) using lowdb
@wayix/telegraf-question-fix
Ask question with async/await
telegraf-question-sm
Ask question with async/await
npm install @telegraf/types
Typescript
Module System
Node Version
NPM Version
TypeScript (99.97%)
JavaScript (0.03%)
Built with Next.js • Fully responsive • SEO optimized • Open source ready
Total Downloads
5,165,099
Last Day
11,170
Last Week
103,907
Last Month
461,858
Last Year
3,936,582
MIT License
18 Stars
275 Commits
7 Forks
2 Watchers
5 Branches
9 Contributors
Updated on Aug 14, 2025
Latest Version
9.0.0
Package Id
@telegraf/types@9.0.0
Unpacked Size
401.73 kB
Size
70.35 kB
File Count
15
NPM Version
10.8.2
Node Version
20.19.4
Published on
Aug 14, 2025
Cumulative downloads
Total Downloads
Last Day
8.8%
11,170
Compared to previous day
Last Week
-8.8%
103,907
Compared to previous week
Last Month
12.7%
461,858
Compared to previous month
Last Year
220.4%
3,936,582
Compared to previous year
1
This project keeps Telegram Bot API types updated for Telegraf. This project provides TypeScript types for the entire Telegram Bot API.
It contains zero bytes of executable code.
1npm install --save-dev @telegraf/types
Generally, this package just exposes a huge load of interface
s that correspond to the types used throughout the Telegram Bot API.
Note that the API specification sometimes only has one name for multiple variants of a type, e.g. there are a number of different Update
s you can receive, but they're all just called Update
.
This package represents such types as large unions of all possible options of what an Update
could be, such that type narrowing can work as expected on your side.
If you need to access the individual variants of an Update
, refer to Update.MessageUpdate
and its siblings.
In fact, this pattern is used for various types, namely:
Update
Message
CallbackQuery
Chat
ChatFromGetChat
InlineKeyboardButton
KeyboardButton
MessageEntity
Location
(Naturally, when the API specification is actually modelling types to be unions (e.g. InlineQueryResult
), this is reflected here as a union type, too.)
The Telegram Bot API does not return just the requested data in the body of the response objects.
Instead, they are wrapped inside an object that has an ok: boolean
status flag, indicating success or failure of the preceding API request.
This outer object is modelled in @telegraf/types
by the ApiResponse
type.
InputFile
and accessing API methodsThe Telegram Bot API lets bots send files in three different ways.
Two of those ways are by specifying a string
—either a file_id
or a URL.
The third option, however, is by uploading files to the server using multipart/form-data.
The first two means to send a file are already covered by the type annotations across the library.
In all places where a file_id
or a URL is permitted, the corresponding property allows a string
.
We will now look at the type declarations that are relevant for uploading files directly.
Depending on the code you're using the types for, you may want to support different ways to specify the file to be uploaded.
As an example, you may want to be able to make calls to sendDocument
with an object that conforms to { path: string }
in order to specify the location of a local file.
(Your code is then assumed to able to translate calls to sendDocument
and the like to multipart/form-data uploads when supplied with an object alike { path: '/tmp/file.txt' }
in the document
property of the argument object.)
This library cannot automatically know what objects you want to support as InputFile
s.
However, you can specify your own version of what an InputFile
is throughout all affected methods and interfaces.
For instance, let's stick with our example and say that you want to support InputFile
s of the following type.
1interface MyInputFile { 2 path: string; 3}
You can then customize the types to fit your needs by passing your custom InputFile
to the ApiMethods
type.
1import * as Telegram from "@telegraf/types"; 2 3type API = Telegram.ApiMethods<MyInputFile>;
You can now access all types that must respect MyInputFile
through the API
type:
1// The utility types `Opts` and `Ret`: 2type Opts<M extends keyof API> = Telegram.Opts<MyInputFile>[M]; 3type Ret<M extends keyof API> = Telegram.Ret<MyInputFile>[M];
Each method takes just a single argument with a structure that corresponds to the object expected by Telegram.
If you need to directly access that type, consider using Opts<M>
where M
is the method name (e.g. Opts<'getMe'>
).
Each method returns the object that is specified by Telegram.
If you directly need to access the return type of a method, consider using Ret<M>
where M
is the method name (e.g. Opts<'getMe'>
).
1// The adjusted `InputMedia*` types: 2type InputMedia = Telegram.InputMedia<MyInputFile>; 3type InputMediaPhoto = Telegram.InputMediaPhoto<MyInputFile>; 4type InputMediaVideo = Telegram.InputMediaVideo<MyInputFile>; 5type InputMediaAnimation = Telegram.InputMediaAnimation<MyInputFile>; 6type InputMediaAudio = Telegram.InputMediaAudio<MyInputFile>; 7type InputMediaDocument = Telegram.InputMediaDocument<MyInputFile>;
Note that interfaces other than the ones mentioned above are unaffected by the customization through MyInputFile
.
They can simply continue to be imported directly.
This project is written for Deno and built for Node. Running npm prepare
runs the deno2node script to build for Node.
They're handwritten. Typegram was started by @KnorpelSenf, who eventually used it as a starting point for grammY's types package. @telegraf/types
started as a fork of Typegram, specialised for Telegraf. It is now independently maintained and updated from the Bot API directly.
No vulnerabilities found.