@tgify/types 9.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) KnorpelSenf & Telegraf contributors
4
+ Copyright (c) 2026 IATNAOD
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,111 @@
1
+ # Types for the Telegram Bot API
2
+
3
+ [![Bot API Version](https://img.shields.io/badge/Bot%20API-v9.2-f36caf.svg?style=flat-square&logo=Telegram&labelColor=white&color=blue)](https://core.telegram.org/bots/api) [![NPM version](https://img.shields.io/npm/v/@tgify/types?style=flat-square&logo=npm&labelColor=fff&color=c53635)](https://npmjs.com/package/@tgify/types)
4
+
5
+ This is a fork of the @telegraf/types library. This project will continue updating the Telegram Bot API types, but now for @tgify/tgify. This project provides TypeScript types for the entire [Telegram Bot API](https://core.telegram.org/bots/api).
6
+
7
+ It contains zero bytes of executable code.
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ npm install --save-dev @tgify/types
13
+ ```
14
+
15
+ ## Available Types
16
+
17
+ Generally, this package just exposes a huge load of `interface`s that correspond to the **types** used throughout the Telegram Bot API.
18
+
19
+ 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`.
20
+ 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.
21
+ If you need to access the individual variants of an `Update`, refer to `Update.MessageUpdate` and its siblings.
22
+
23
+ In fact, this pattern is used for various types, namely:
24
+
25
+ - `Update`
26
+ - `Message`
27
+ - `CallbackQuery`
28
+ - `Chat`
29
+ - `ChatFromGetChat`
30
+ - `InlineKeyboardButton`
31
+ - `KeyboardButton`
32
+ - `MessageEntity`
33
+ - `Location`
34
+
35
+ (Naturally, when the API specification is actually modelling types to be unions (e.g. `InlineQueryResult`), this is reflected here as a union type, too.)
36
+
37
+ ## Using API Response objects
38
+
39
+ The Telegram Bot API does not return just the requested data in the body of the response objects.
40
+
41
+ Instead, they are wrapped inside an object that has an `ok: boolean` status flag, indicating success or failure of the preceding API request.
42
+ This outer object is modelled in `@tgify/types` by the `ApiResponse` type.
43
+
44
+ ## Customizing `InputFile` and accessing API methods
45
+
46
+ The Telegram Bot API lets bots send files in [three different ways](https://core.telegram.org/bots/api#sending-files).
47
+ Two of those ways are by specifying a `string`—either a `file_id` or a URL.
48
+ The third option, however, is by uploading files to the server using multipart/form-data.
49
+
50
+ The first two means to send a file are already covered by the type annotations across the library.
51
+ In all places where a `file_id` or a URL is permitted, the corresponding property allows a `string`.
52
+
53
+ We will now look at the type declarations that are relevant for uploading files directly.
54
+ Depending on the code you're using the types for, you may want to support different ways to specify the file to be uploaded.
55
+ 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.
56
+ (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.)
57
+
58
+ This library cannot automatically know what objects you want to support as `InputFile`s.
59
+
60
+ However, you can specify your own version of what an `InputFile` is throughout all affected methods and interfaces.
61
+
62
+ For instance, let's stick with our example and say that you want to support `InputFile`s of the following type.
63
+
64
+ ```ts
65
+ interface MyInputFile {
66
+ path: string;
67
+ }
68
+ ```
69
+
70
+ You can then customize the types to fit your needs by passing your custom `InputFile` to the `ApiMethods` type.
71
+
72
+ ```ts
73
+ import * as Telegram from "@tgify/types";
74
+
75
+ type API = Telegram.ApiMethods<MyInputFile>;
76
+ ```
77
+
78
+ You can now access all types that must respect `MyInputFile` through the `API` type:
79
+
80
+ ```ts
81
+ // The utility types `Opts` and `Ret`:
82
+ type Opts<M extends keyof API> = Telegram.Opts<MyInputFile>[M];
83
+ type Ret<M extends keyof API> = Telegram.Ret<MyInputFile>[M];
84
+ ```
85
+
86
+ Each method takes just a single argument with a structure that corresponds to the object expected by Telegram.
87
+ If you need to directly access that type, consider using `Opts<M>` where `M` is the method name (e.g. `Opts<'getMe'>`).
88
+
89
+ Each method returns the object that is specified by Telegram.
90
+ 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'>`).
91
+
92
+ ```ts
93
+ // The adjusted `InputMedia*` types:
94
+ type InputMedia = Telegram.InputMedia<MyInputFile>;
95
+ type InputMediaPhoto = Telegram.InputMediaPhoto<MyInputFile>;
96
+ type InputMediaVideo = Telegram.InputMediaVideo<MyInputFile>;
97
+ type InputMediaAnimation = Telegram.InputMediaAnimation<MyInputFile>;
98
+ type InputMediaAudio = Telegram.InputMediaAudio<MyInputFile>;
99
+ type InputMediaDocument = Telegram.InputMediaDocument<MyInputFile>;
100
+ ```
101
+
102
+ Note that interfaces other than the ones mentioned above are unaffected by the customization through `MyInputFile`.
103
+ They can simply continue to be imported directly.
104
+
105
+ ## Development
106
+
107
+ This project is written for Deno and built for Node. Running `npm prepare` runs the deno2node script to build for Node.
108
+
109
+ ## Where do the types come from
110
+
111
+ They're handwritten. [Typegram](https://github.com/KnorpelSenf/typegram) was started by [@KnorpelSenf](https://github.com/KnorpelSenf), who eventually used it as a starting point for grammY's [types](https://github.com/grammyjs/types) package. `@tgify/types` started as a fork of Typegram, specialised for Tgify. It is now independently maintained and updated from the Bot API directly.
package/api.d.ts ADDED
@@ -0,0 +1,22 @@
1
+ export interface ApiError {
2
+ ok: false;
3
+ error_code: number;
4
+ description: string;
5
+ parameters?: ResponseParameters;
6
+ }
7
+ export interface ApiSuccess<T> {
8
+ ok: true;
9
+ result: T;
10
+ }
11
+ /** The response contains an object, which always has a Boolean field 'ok' and may have an optional String field 'description' with a human-readable description of the result. If 'ok' equals true, the request was successful and the result of the query can be found in the 'result' field. In case of an unsuccessful request, 'ok' equals false and the error is explained in the 'description'. An Integer 'error_code' field is also returned, but its contents are subject to change in the future. Some errors may also have an optional field 'parameters' of the type ResponseParameters, which can help to automatically handle the error.
12
+
13
+ All methods in the Bot API are case-insensitive.
14
+ All queries must be made using UTF-8. */
15
+ export type ApiResponse<T> = ApiError | ApiSuccess<T>;
16
+ /** Describes why a request was unsuccessful. */
17
+ export interface ResponseParameters {
18
+ /** The group has been migrated to a supergroup with the specified identifier. */
19
+ migrate_to_chat_id?: number;
20
+ /** In case of exceeding flood control, the number of seconds left to wait before the request can be repeated */
21
+ retry_after?: number;
22
+ }
package/index.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ export * from "./api.js";
2
+ export * from "./inline.js";
3
+ export * from "./manage.js";
4
+ export * from "./markup.js";
5
+ export * from "./message.js";
6
+ export * from "./methods.js";
7
+ export * from "./passport.js";
8
+ export * from "./payment.js";
9
+ export * from "./settings.js";
10
+ export * from "./update.js";
package/index.js ADDED
@@ -0,0 +1,2 @@
1
+ /** This prevents runtimes and bundlers from erroring if this module is imported without `type` */
2
+ module.exports = {};