grammy-tools 1.36.2
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 +21 -0
- package/README.md +339 -0
- package/out/bot.d.ts +314 -0
- package/out/bot.js +669 -0
- package/out/composer.d.ts +764 -0
- package/out/composer.js +704 -0
- package/out/context.d.ts +1618 -0
- package/out/context.js +1976 -0
- package/out/convenience/constants.d.ts +98 -0
- package/out/convenience/constants.js +37 -0
- package/out/convenience/frameworks.d.ts +216 -0
- package/out/convenience/frameworks.js +370 -0
- package/out/convenience/inline_query.d.ts +401 -0
- package/out/convenience/inline_query.js +461 -0
- package/out/convenience/input_media.d.ts +72 -0
- package/out/convenience/input_media.js +82 -0
- package/out/convenience/keyboard.d.ts +763 -0
- package/out/convenience/keyboard.js +935 -0
- package/out/convenience/session.d.ts +345 -0
- package/out/convenience/session.js +455 -0
- package/out/convenience/webhook.d.ts +59 -0
- package/out/convenience/webhook.js +80 -0
- package/out/core/api.d.ts +1628 -0
- package/out/core/api.js +1907 -0
- package/out/core/client.d.ts +180 -0
- package/out/core/client.js +226 -0
- package/out/core/error.d.ts +53 -0
- package/out/core/error.js +87 -0
- package/out/core/payload.d.ts +39 -0
- package/out/core/payload.js +199 -0
- package/out/filter.d.ts +959 -0
- package/out/filter.js +378 -0
- package/out/mod.d.ts +14 -0
- package/out/mod.js +43 -0
- package/out/platform.node.d.ts +16 -0
- package/out/platform.node.js +43 -0
- package/out/shim.node.d.ts +2 -0
- package/out/shim.node.js +7 -0
- package/out/types.d.ts +1 -0
- package/out/types.js +17 -0
- package/out/types.node.d.ts +78 -0
- package/out/types.node.js +107 -0
- package/out/web.d.ts +1 -0
- package/out/web.mjs +5172 -0
- package/package.json +71 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { DEFAULT_UPDATE_TYPES } from "../bot.js";
|
|
2
|
+
declare const ALL_UPDATE_TYPES: readonly ["message", "edited_message", "channel_post", "edited_channel_post", "business_connection", "business_message", "edited_business_message", "deleted_business_messages", "inline_query", "chosen_inline_result", "callback_query", "shipping_query", "pre_checkout_query", "poll", "poll_answer", "my_chat_member", "chat_join_request", "chat_boost", "removed_chat_boost", "chat_member", "message_reaction", "message_reaction_count"];
|
|
3
|
+
declare const ALL_CHAT_PERMISSIONS: {
|
|
4
|
+
readonly is_anonymous: true;
|
|
5
|
+
readonly can_manage_chat: true;
|
|
6
|
+
readonly can_delete_messages: true;
|
|
7
|
+
readonly can_manage_video_chats: true;
|
|
8
|
+
readonly can_restrict_members: true;
|
|
9
|
+
readonly can_promote_members: true;
|
|
10
|
+
readonly can_change_info: true;
|
|
11
|
+
readonly can_invite_users: true;
|
|
12
|
+
readonly can_post_stories: true;
|
|
13
|
+
readonly can_edit_stories: true;
|
|
14
|
+
readonly can_delete_stories: true;
|
|
15
|
+
readonly can_post_messages: true;
|
|
16
|
+
readonly can_edit_messages: true;
|
|
17
|
+
readonly can_pin_messages: true;
|
|
18
|
+
readonly can_manage_topics: true;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Types of the constants used in the Telegram Bot API. Currently holds all
|
|
22
|
+
* available update types as well as all chat permissions.
|
|
23
|
+
*/
|
|
24
|
+
export interface ApiConstants {
|
|
25
|
+
/**
|
|
26
|
+
* List of update types a bot receives by default. Useful if you want to
|
|
27
|
+
* receive all update types but `chat_member`, `message_reaction`, and
|
|
28
|
+
* `message_reaction_count`.
|
|
29
|
+
*
|
|
30
|
+
* ```ts
|
|
31
|
+
* // Built-in polling:
|
|
32
|
+
* bot.start({ allowed_updates: DEFAULT_UPDATE_TYPES });
|
|
33
|
+
* // grammY runner:
|
|
34
|
+
* run(bot, { runner: { fetch: { allowed_updates: DEFAULT_UPDATE_TYPES } } });
|
|
35
|
+
* // Webhooks:
|
|
36
|
+
* await bot.api.setWebhook(url, { allowed_updates: DEFAULT_UPDATE_TYPES });
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* See the [Bot API reference](https://core.telegram.org/bots/api#update)
|
|
40
|
+
* for more information.
|
|
41
|
+
*/
|
|
42
|
+
DEFAULT_UPDATE_TYPES: typeof DEFAULT_UPDATE_TYPES[number];
|
|
43
|
+
/**
|
|
44
|
+
* List of all available update types. Useful if you want to receive all
|
|
45
|
+
* updates from the Bot API, rather than just those that are delivered by
|
|
46
|
+
* default.
|
|
47
|
+
*
|
|
48
|
+
* The main use case for this is when you want to receive `chat_member`,
|
|
49
|
+
* `message_reaction`, and `message_reaction_count` updates, as they need to
|
|
50
|
+
* be enabled first. Use it like so:
|
|
51
|
+
*
|
|
52
|
+
* ```ts
|
|
53
|
+
* // Built-in polling:
|
|
54
|
+
* bot.start({ allowed_updates: ALL_UPDATE_TYPES });
|
|
55
|
+
* // grammY runner:
|
|
56
|
+
* run(bot, { runner: { fetch: { allowed_updates: ALL_UPDATE_TYPES } } });
|
|
57
|
+
* // Webhooks:
|
|
58
|
+
* await bot.api.setWebhook(url, { allowed_updates: ALL_UPDATE_TYPES });
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* See the [Bot API reference](https://core.telegram.org/bots/api#update)
|
|
62
|
+
* for more information.
|
|
63
|
+
*/
|
|
64
|
+
ALL_UPDATE_TYPES: typeof ALL_UPDATE_TYPES[number];
|
|
65
|
+
/**
|
|
66
|
+
* An object containing all available chat permissions. Useful if you want
|
|
67
|
+
* to lift restrictions from a user, as this action requires you to pass
|
|
68
|
+
* `true` for all permissions. Use it like so:
|
|
69
|
+
*
|
|
70
|
+
* ```ts
|
|
71
|
+
* // On `Bot`:
|
|
72
|
+
* await bot.api.restrictChatMember(chat_id, user_id, ALL_CHAT_PERMISSIONS);
|
|
73
|
+
* // On `Api`:
|
|
74
|
+
* await ctx.api.restrictChatMember(chat_id, user_id, ALL_CHAT_PERMISSIONS);
|
|
75
|
+
* // On `Context`:
|
|
76
|
+
* await ctx.restrictChatMember(user_id, ALL_CHAT_PERMISSIONS);
|
|
77
|
+
* await ctx.restrictAuthor(ALL_CHAT_PERMISSIONS);
|
|
78
|
+
* ```
|
|
79
|
+
*
|
|
80
|
+
* See the [Bot API reference](https://core.telegram.org/bots/api#update)
|
|
81
|
+
* for more information.
|
|
82
|
+
*/
|
|
83
|
+
ALL_CHAT_PERMISSIONS: keyof typeof ALL_CHAT_PERMISSIONS;
|
|
84
|
+
}
|
|
85
|
+
interface TypeOf {
|
|
86
|
+
DEFAULT_UPDATE_TYPES: typeof DEFAULT_UPDATE_TYPES;
|
|
87
|
+
ALL_UPDATE_TYPES: typeof ALL_UPDATE_TYPES;
|
|
88
|
+
ALL_CHAT_PERMISSIONS: typeof ALL_CHAT_PERMISSIONS;
|
|
89
|
+
}
|
|
90
|
+
type ValuesFor<T> = {
|
|
91
|
+
[K in keyof T]: K extends keyof TypeOf ? Readonly<TypeOf[K]> : never;
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* A container for constants used in the Telegram Bot API. Currently holds all
|
|
95
|
+
* available update types as well as all chat permissions.
|
|
96
|
+
*/
|
|
97
|
+
export declare const API_CONSTANTS: ValuesFor<ApiConstants>;
|
|
98
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.API_CONSTANTS = void 0;
|
|
4
|
+
const bot_js_1 = require("../bot.js");
|
|
5
|
+
const ALL_UPDATE_TYPES = [
|
|
6
|
+
...bot_js_1.DEFAULT_UPDATE_TYPES,
|
|
7
|
+
"chat_member",
|
|
8
|
+
"message_reaction",
|
|
9
|
+
"message_reaction_count",
|
|
10
|
+
];
|
|
11
|
+
const ALL_CHAT_PERMISSIONS = {
|
|
12
|
+
is_anonymous: true,
|
|
13
|
+
can_manage_chat: true,
|
|
14
|
+
can_delete_messages: true,
|
|
15
|
+
can_manage_video_chats: true,
|
|
16
|
+
can_restrict_members: true,
|
|
17
|
+
can_promote_members: true,
|
|
18
|
+
can_change_info: true,
|
|
19
|
+
can_invite_users: true,
|
|
20
|
+
can_post_stories: true,
|
|
21
|
+
can_edit_stories: true,
|
|
22
|
+
can_delete_stories: true,
|
|
23
|
+
can_post_messages: true,
|
|
24
|
+
can_edit_messages: true,
|
|
25
|
+
can_pin_messages: true,
|
|
26
|
+
can_manage_topics: true,
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* A container for constants used in the Telegram Bot API. Currently holds all
|
|
30
|
+
* available update types as well as all chat permissions.
|
|
31
|
+
*/
|
|
32
|
+
exports.API_CONSTANTS = {
|
|
33
|
+
DEFAULT_UPDATE_TYPES: bot_js_1.DEFAULT_UPDATE_TYPES,
|
|
34
|
+
ALL_UPDATE_TYPES,
|
|
35
|
+
ALL_CHAT_PERMISSIONS,
|
|
36
|
+
};
|
|
37
|
+
Object.freeze(exports.API_CONSTANTS);
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { type Update } from "../types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Abstraction over a request-response cycle, providing access to the update, as
|
|
4
|
+
* well as a mechanism for responding to the request and to end it.
|
|
5
|
+
*/
|
|
6
|
+
export interface ReqResHandler<T = void> {
|
|
7
|
+
/**
|
|
8
|
+
* The update object sent from Telegram, usually resolves the request's JSON
|
|
9
|
+
* body
|
|
10
|
+
*/
|
|
11
|
+
update: Promise<Update>;
|
|
12
|
+
/**
|
|
13
|
+
* X-Telegram-Bot-Api-Secret-Token header of the request, or undefined if
|
|
14
|
+
* not present
|
|
15
|
+
*/
|
|
16
|
+
header?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Ends the request immediately without body, called after every request
|
|
19
|
+
* unless a webhook reply was performed
|
|
20
|
+
*/
|
|
21
|
+
end?: () => void;
|
|
22
|
+
/**
|
|
23
|
+
* Sends the specified JSON as a payload in the body, used for webhook
|
|
24
|
+
* replies
|
|
25
|
+
*/
|
|
26
|
+
respond: (json: string) => unknown | Promise<unknown>;
|
|
27
|
+
/**
|
|
28
|
+
* Responds that the request is unauthorized due to mismatching
|
|
29
|
+
* X-Telegram-Bot-Api-Secret-Token headers
|
|
30
|
+
*/
|
|
31
|
+
unauthorized: () => unknown | Promise<unknown>;
|
|
32
|
+
/**
|
|
33
|
+
* Some frameworks (e.g. Deno's std/http `listenAndServe`) assume that
|
|
34
|
+
* handler returns something
|
|
35
|
+
*/
|
|
36
|
+
handlerReturn?: Promise<T>;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Middleware for a web framework. Creates a request-response handler for a
|
|
40
|
+
* request. The handler will be used to integrate with the compatible framework.
|
|
41
|
+
*/
|
|
42
|
+
export type FrameworkAdapter = (...args: any[]) => ReqResHandler<any>;
|
|
43
|
+
export type LambdaAdapter = (event: {
|
|
44
|
+
body?: string;
|
|
45
|
+
headers: Record<string, string | undefined>;
|
|
46
|
+
}, _context: unknown, callback: (arg0: unknown, arg1: Record<string, unknown>) => Promise<unknown>) => ReqResHandler;
|
|
47
|
+
export type LambdaAsyncAdapter = (event: {
|
|
48
|
+
body?: string;
|
|
49
|
+
headers: Record<string, string | undefined>;
|
|
50
|
+
}, _context: unknown) => ReqResHandler;
|
|
51
|
+
export type AzureAdapter = (context: {
|
|
52
|
+
res?: {
|
|
53
|
+
[key: string]: any;
|
|
54
|
+
};
|
|
55
|
+
}, request: {
|
|
56
|
+
body?: unknown;
|
|
57
|
+
}) => ReqResHandler;
|
|
58
|
+
export type AzureAdapterV4 = (request: {
|
|
59
|
+
headers: {
|
|
60
|
+
get(name: string): string | null;
|
|
61
|
+
};
|
|
62
|
+
json(): Promise<unknown>;
|
|
63
|
+
}) => ReqResHandler<{
|
|
64
|
+
status: number;
|
|
65
|
+
body?: string;
|
|
66
|
+
} | {
|
|
67
|
+
jsonBody: string;
|
|
68
|
+
}>;
|
|
69
|
+
export type BunAdapter = (request: {
|
|
70
|
+
headers: Headers;
|
|
71
|
+
json: () => Promise<Update>;
|
|
72
|
+
}) => ReqResHandler<Response>;
|
|
73
|
+
export type CloudflareAdapter = (event: {
|
|
74
|
+
request: Request;
|
|
75
|
+
respondWith: (response: Promise<Response>) => void;
|
|
76
|
+
}) => ReqResHandler;
|
|
77
|
+
export type CloudflareModuleAdapter = (request: Request) => ReqResHandler<Response>;
|
|
78
|
+
export type ElysiaAdapter = (ctx: {
|
|
79
|
+
body: Update;
|
|
80
|
+
headers: Record<string, string | undefined>;
|
|
81
|
+
set: {
|
|
82
|
+
headers: Record<string, string>;
|
|
83
|
+
status: number;
|
|
84
|
+
};
|
|
85
|
+
}) => ReqResHandler<string>;
|
|
86
|
+
export type ExpressAdapter = (req: {
|
|
87
|
+
body: Update;
|
|
88
|
+
header: (header: string) => string | undefined;
|
|
89
|
+
}, res: {
|
|
90
|
+
end: (cb?: () => void) => typeof res;
|
|
91
|
+
set: (field: string, value?: string | string[]) => typeof res;
|
|
92
|
+
send: (json: string) => typeof res;
|
|
93
|
+
status: (code: number) => typeof res;
|
|
94
|
+
}) => ReqResHandler;
|
|
95
|
+
export type FastifyAdapter = (request: {
|
|
96
|
+
body: unknown;
|
|
97
|
+
headers: any;
|
|
98
|
+
}, reply: {
|
|
99
|
+
status: (code: number) => typeof reply;
|
|
100
|
+
headers: (headers: Record<string, string>) => typeof reply;
|
|
101
|
+
code: (code: number) => typeof reply;
|
|
102
|
+
send: {
|
|
103
|
+
(): typeof reply;
|
|
104
|
+
(json: string): typeof reply;
|
|
105
|
+
};
|
|
106
|
+
}) => ReqResHandler;
|
|
107
|
+
export type HonoAdapter = (c: {
|
|
108
|
+
req: {
|
|
109
|
+
json: <T>() => Promise<T>;
|
|
110
|
+
header: (header: string) => string | undefined;
|
|
111
|
+
};
|
|
112
|
+
body(data: string): Response;
|
|
113
|
+
body(data: null, status: 204): Response;
|
|
114
|
+
status: (status: any) => void;
|
|
115
|
+
json: (json: string) => Response;
|
|
116
|
+
}) => ReqResHandler<Response>;
|
|
117
|
+
export type HttpAdapter = (req: {
|
|
118
|
+
headers: Record<string, string | string[] | undefined>;
|
|
119
|
+
on: (event: string, listener: (chunk: unknown) => void) => typeof req;
|
|
120
|
+
once: (event: string, listener: () => void) => typeof req;
|
|
121
|
+
}, res: {
|
|
122
|
+
writeHead: {
|
|
123
|
+
(status: number): typeof res;
|
|
124
|
+
(status: number, headers: Record<string, string>): typeof res;
|
|
125
|
+
};
|
|
126
|
+
end: (json?: string) => void;
|
|
127
|
+
}) => ReqResHandler;
|
|
128
|
+
export type KoaAdapter = (ctx: {
|
|
129
|
+
get: (header: string) => string | undefined;
|
|
130
|
+
set: (key: string, value: string) => void;
|
|
131
|
+
status: number;
|
|
132
|
+
body: string;
|
|
133
|
+
request: {
|
|
134
|
+
body?: unknown;
|
|
135
|
+
};
|
|
136
|
+
response: {
|
|
137
|
+
body: unknown;
|
|
138
|
+
status: number;
|
|
139
|
+
};
|
|
140
|
+
}) => ReqResHandler;
|
|
141
|
+
export type NextAdapter = (req: {
|
|
142
|
+
body: Update;
|
|
143
|
+
headers: Record<string, string | string[] | undefined>;
|
|
144
|
+
}, res: {
|
|
145
|
+
end: (cb?: () => void) => typeof res;
|
|
146
|
+
status: (code: number) => typeof res;
|
|
147
|
+
json: (json: string) => any;
|
|
148
|
+
send: (json: string) => any;
|
|
149
|
+
}) => ReqResHandler;
|
|
150
|
+
export type NHttpAdapter = (rev: {
|
|
151
|
+
body: unknown;
|
|
152
|
+
headers: {
|
|
153
|
+
get: (header: string) => string | null;
|
|
154
|
+
};
|
|
155
|
+
response: {
|
|
156
|
+
sendStatus: (status: number) => void;
|
|
157
|
+
status: (status: number) => {
|
|
158
|
+
send: (json: string) => void;
|
|
159
|
+
};
|
|
160
|
+
};
|
|
161
|
+
}) => ReqResHandler;
|
|
162
|
+
export type OakAdapter = (ctx: {
|
|
163
|
+
request: {
|
|
164
|
+
body: {
|
|
165
|
+
json: () => Promise<Update>;
|
|
166
|
+
};
|
|
167
|
+
headers: {
|
|
168
|
+
get: (header: string) => string | null;
|
|
169
|
+
};
|
|
170
|
+
};
|
|
171
|
+
response: {
|
|
172
|
+
status: number;
|
|
173
|
+
type: string | undefined;
|
|
174
|
+
body: unknown;
|
|
175
|
+
};
|
|
176
|
+
}) => ReqResHandler;
|
|
177
|
+
export type ServeHttpAdapter = (requestEvent: {
|
|
178
|
+
request: Request;
|
|
179
|
+
respondWith: (response: Response) => void;
|
|
180
|
+
}) => ReqResHandler;
|
|
181
|
+
export type StdHttpAdapter = (req: Request) => ReqResHandler<Response>;
|
|
182
|
+
export type SveltekitAdapter = ({ request }: {
|
|
183
|
+
request: Request;
|
|
184
|
+
}) => ReqResHandler<unknown>;
|
|
185
|
+
export type WorktopAdapter = (req: {
|
|
186
|
+
json: () => Promise<Update>;
|
|
187
|
+
headers: {
|
|
188
|
+
get: (header: string) => string | null;
|
|
189
|
+
};
|
|
190
|
+
}, res: {
|
|
191
|
+
end: (data: BodyInit | null) => void;
|
|
192
|
+
send: (status: number, json: string) => void;
|
|
193
|
+
}) => ReqResHandler;
|
|
194
|
+
export declare const adapters: {
|
|
195
|
+
"aws-lambda": LambdaAdapter;
|
|
196
|
+
"aws-lambda-async": LambdaAsyncAdapter;
|
|
197
|
+
azure: AzureAdapter;
|
|
198
|
+
"azure-v4": AzureAdapterV4;
|
|
199
|
+
bun: BunAdapter;
|
|
200
|
+
cloudflare: CloudflareAdapter;
|
|
201
|
+
"cloudflare-mod": CloudflareModuleAdapter;
|
|
202
|
+
elysia: ElysiaAdapter;
|
|
203
|
+
express: ExpressAdapter;
|
|
204
|
+
fastify: FastifyAdapter;
|
|
205
|
+
hono: HonoAdapter;
|
|
206
|
+
http: HttpAdapter;
|
|
207
|
+
https: HttpAdapter;
|
|
208
|
+
koa: KoaAdapter;
|
|
209
|
+
"next-js": NextAdapter;
|
|
210
|
+
nhttp: NHttpAdapter;
|
|
211
|
+
oak: OakAdapter;
|
|
212
|
+
serveHttp: ServeHttpAdapter;
|
|
213
|
+
"std/http": StdHttpAdapter;
|
|
214
|
+
sveltekit: SveltekitAdapter;
|
|
215
|
+
worktop: WorktopAdapter;
|
|
216
|
+
};
|