Gathering detailed insights and metrics for typegram
Gathering detailed insights and metrics for typegram
Gathering detailed insights and metrics for typegram
Gathering detailed insights and metrics for typegram
npm install typegram
Typescript
Module System
Node Version
NPM Version
91.4
Supply Chain
100
Quality
76.2
Maintenance
100
Vulnerability
100
License
TypeScript (99.96%)
JavaScript (0.04%)
Total Downloads
4,004,141
Last Day
639
Last Week
9,057
Last Month
38,995
Last Year
610,436
MIT License
122 Stars
225 Commits
3 Forks
2 Watchers
2 Branches
7 Contributors
Updated on Apr 10, 2025
Minified
Minified + Gzipped
Latest Version
5.2.0
Package Id
typegram@5.2.0
Unpacked Size
278.66 kB
Size
50.11 kB
File Count
16
NPM Version
8.19.1
Node Version
18.9.0
Published on
Aug 18, 2023
Cumulative downloads
Total Downloads
Last Day
-20.2%
639
Compared to previous day
Last Week
-8.3%
9,057
Compared to previous week
Last Month
-10.5%
38,995
Compared to previous month
Last Year
-36%
610,436
Compared to previous year
1
Please consider contributing to @grammyjs/types instead.
typegram
is legacy and will not be updated directly anymore. Instead, @grammyjs/types is maintained and kept in sync with the Bot API specification. Changes are backported totypegram
periodically to keep older projects running.
This project provides TypeScript types for the entire Telegram Bot API in version 6.8.
It contains zero bytes of executable code.
1npm install --save-dev typegram
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:
CallbackQuery
Chat
ChatFromGetChat
InlineKeyboardButton
KeyboardButton
Message
MessageEntity
Location
Update
(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 typegram
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 typegram
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.)
typegram
cannot possibly 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 typegram
to fit your needs by passing your custom InputFile
to the ApiMethods
type.
1import * as Typegram from "typegram"; 2 3type API = Typegram.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> = Typegram.Opts<MyInputFile>[M]; 3type Ret<M extends keyof API> = Typegram.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 = Typegram.InputMedia<MyInputFile>; 3type InputMediaPhoto = Typegram.InputMediaPhoto<MyInputFile>; 4type InputMediaVideo = Typegram.InputMediaVideo<MyInputFile>; 5type InputMediaAnimation = Typegram.InputMediaAnimation<MyInputFile>; 6type InputMediaAudio = Typegram.InputMediaAudio<MyInputFile>; 7type InputMediaDocument = Typegram.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 from typegram
.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
2 existing vulnerabilities detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 5
Details
Reason
Found 6/30 approved changesets -- score normalized to 2
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-06-16
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More