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.
Files changed (45) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +339 -0
  3. package/out/bot.d.ts +314 -0
  4. package/out/bot.js +669 -0
  5. package/out/composer.d.ts +764 -0
  6. package/out/composer.js +704 -0
  7. package/out/context.d.ts +1618 -0
  8. package/out/context.js +1976 -0
  9. package/out/convenience/constants.d.ts +98 -0
  10. package/out/convenience/constants.js +37 -0
  11. package/out/convenience/frameworks.d.ts +216 -0
  12. package/out/convenience/frameworks.js +370 -0
  13. package/out/convenience/inline_query.d.ts +401 -0
  14. package/out/convenience/inline_query.js +461 -0
  15. package/out/convenience/input_media.d.ts +72 -0
  16. package/out/convenience/input_media.js +82 -0
  17. package/out/convenience/keyboard.d.ts +763 -0
  18. package/out/convenience/keyboard.js +935 -0
  19. package/out/convenience/session.d.ts +345 -0
  20. package/out/convenience/session.js +455 -0
  21. package/out/convenience/webhook.d.ts +59 -0
  22. package/out/convenience/webhook.js +80 -0
  23. package/out/core/api.d.ts +1628 -0
  24. package/out/core/api.js +1907 -0
  25. package/out/core/client.d.ts +180 -0
  26. package/out/core/client.js +226 -0
  27. package/out/core/error.d.ts +53 -0
  28. package/out/core/error.js +87 -0
  29. package/out/core/payload.d.ts +39 -0
  30. package/out/core/payload.js +199 -0
  31. package/out/filter.d.ts +959 -0
  32. package/out/filter.js +378 -0
  33. package/out/mod.d.ts +14 -0
  34. package/out/mod.js +43 -0
  35. package/out/platform.node.d.ts +16 -0
  36. package/out/platform.node.js +43 -0
  37. package/out/shim.node.d.ts +2 -0
  38. package/out/shim.node.js +7 -0
  39. package/out/types.d.ts +1 -0
  40. package/out/types.js +17 -0
  41. package/out/types.node.d.ts +78 -0
  42. package/out/types.node.js +107 -0
  43. package/out/web.d.ts +1 -0
  44. package/out/web.mjs +5172 -0
  45. package/package.json +71 -0
package/out/filter.js ADDED
@@ -0,0 +1,378 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.matchFilter = matchFilter;
4
+ exports.parse = parse;
5
+ exports.preprocess = preprocess;
6
+ const filterQueryCache = new Map();
7
+ // === Obtain O(1) filter function from query
8
+ /**
9
+ * > This is an advanced function of grammY.
10
+ *
11
+ * Takes a filter query and turns it into a predicate function that can check in
12
+ * constant time whether a given context object satisfies the query. The created
13
+ * predicate can be passed to `bot.filter` and will narrow down the context
14
+ * accordingly.
15
+ *
16
+ * This function is used internally by `bot.on` but exposed for advanced usage
17
+ * like the following.
18
+ * ```ts
19
+ * // Listens for updates except forwards of messages or channel posts
20
+ * bot.drop(matchFilter(':forward_origin'), ctx => { ... })
21
+ * ```
22
+ *
23
+ * Check out the
24
+ * [documentation](https://grammy.dev/ref/core/composer#on)
25
+ * of `bot.on` for examples. In addition, the
26
+ * [website](https://grammy.dev/guide/filter-queries) contains more
27
+ * information about how filter queries work in grammY.
28
+ *
29
+ * @param filter A filter query or an array of filter queries
30
+ */
31
+ function matchFilter(filter) {
32
+ var _a;
33
+ const queries = Array.isArray(filter) ? filter : [filter];
34
+ const key = queries.join(",");
35
+ const predicate = (_a = filterQueryCache.get(key)) !== null && _a !== void 0 ? _a : (() => {
36
+ const parsed = parse(queries);
37
+ const pred = compile(parsed);
38
+ filterQueryCache.set(key, pred);
39
+ return pred;
40
+ })();
41
+ return (ctx) => predicate(ctx);
42
+ }
43
+ function parse(filter) {
44
+ return Array.isArray(filter)
45
+ ? filter.map((q) => q.split(":"))
46
+ : [filter.split(":")];
47
+ }
48
+ function compile(parsed) {
49
+ const preprocessed = parsed.flatMap((q) => check(q, preprocess(q)));
50
+ const ltree = treeify(preprocessed);
51
+ const predicate = arborist(ltree); // arborists check trees
52
+ return (ctx) => !!predicate(ctx.update, ctx);
53
+ }
54
+ function preprocess(filter) {
55
+ const valid = UPDATE_KEYS;
56
+ const expanded = [filter]
57
+ // expand L1
58
+ .flatMap((q) => {
59
+ const [l1, l2, l3] = q;
60
+ // only expand if shortcut is given
61
+ if (!(l1 in L1_SHORTCUTS))
62
+ return [q];
63
+ // only expand for at least one non-empty part
64
+ if (!l1 && !l2 && !l3)
65
+ return [q];
66
+ // perform actual expansion
67
+ const targets = L1_SHORTCUTS[l1];
68
+ const expanded = targets.map((s) => [s, l2, l3]);
69
+ // assume that bare L1 expansions are always correct
70
+ if (l2 === undefined)
71
+ return expanded;
72
+ // only filter out invalid expansions if we don't do this later
73
+ if (l2 in L2_SHORTCUTS && (l2 || l3))
74
+ return expanded;
75
+ // filter out invalid expansions, e.g. `channel_post:new_chat_member` for empty L1
76
+ return expanded.filter(([s]) => { var _a; return !!((_a = valid[s]) === null || _a === void 0 ? void 0 : _a[l2]); });
77
+ })
78
+ // expand L2
79
+ .flatMap((q) => {
80
+ const [l1, l2, l3] = q;
81
+ // only expand if shortcut is given
82
+ if (!(l2 in L2_SHORTCUTS))
83
+ return [q];
84
+ // only expand for at least one non-empty part
85
+ if (!l2 && !l3)
86
+ return [q];
87
+ // perform actual expansion
88
+ const targets = L2_SHORTCUTS[l2];
89
+ const expanded = targets.map((s) => [l1, s, l3]);
90
+ // assume that bare L2 expansions are always correct
91
+ if (l3 === undefined)
92
+ return expanded;
93
+ // filter out invalid expansions
94
+ return expanded.filter(([, s]) => { var _a, _b; return !!((_b = (_a = valid[l1]) === null || _a === void 0 ? void 0 : _a[s]) === null || _b === void 0 ? void 0 : _b[l3]); });
95
+ });
96
+ if (expanded.length === 0) {
97
+ throw new Error(`Shortcuts in '${filter.join(":")}' do not expand to any valid filter query`);
98
+ }
99
+ return expanded;
100
+ }
101
+ function check(original, preprocessed) {
102
+ if (preprocessed.length === 0)
103
+ throw new Error("Empty filter query given");
104
+ const errors = preprocessed
105
+ .map(checkOne)
106
+ .filter((r) => r !== true);
107
+ if (errors.length === 0)
108
+ return preprocessed;
109
+ else if (errors.length === 1)
110
+ throw new Error(errors[0]);
111
+ else {
112
+ throw new Error(`Invalid filter query '${original.join(":")}'. There are ${errors.length} errors after expanding the contained shortcuts: ${errors.join("; ")}`);
113
+ }
114
+ }
115
+ function checkOne(filter) {
116
+ const [l1, l2, l3, ...n] = filter;
117
+ if (l1 === undefined)
118
+ return "Empty filter query given";
119
+ if (!(l1 in UPDATE_KEYS)) {
120
+ const permitted = Object.keys(UPDATE_KEYS);
121
+ return `Invalid L1 filter '${l1}' given in '${filter.join(":")}'. \
122
+ Permitted values are: ${permitted.map((k) => `'${k}'`).join(", ")}.`;
123
+ }
124
+ if (l2 === undefined)
125
+ return true;
126
+ const l1Obj = UPDATE_KEYS[l1];
127
+ if (!(l2 in l1Obj)) {
128
+ const permitted = Object.keys(l1Obj);
129
+ return `Invalid L2 filter '${l2}' given in '${filter.join(":")}'. \
130
+ Permitted values are: ${permitted.map((k) => `'${k}'`).join(", ")}.`;
131
+ }
132
+ if (l3 === undefined)
133
+ return true;
134
+ const l2Obj = l1Obj[l2];
135
+ if (!(l3 in l2Obj)) {
136
+ const permitted = Object.keys(l2Obj);
137
+ return `Invalid L3 filter '${l3}' given in '${filter.join(":")}'. ${permitted.length === 0
138
+ ? `No further filtering is possible after '${l1}:${l2}'.`
139
+ : `Permitted values are: ${permitted.map((k) => `'${k}'`).join(", ")}.`}`;
140
+ }
141
+ if (n.length === 0)
142
+ return true;
143
+ return `Cannot filter further than three levels, ':${n.join(":")}' is invalid!`;
144
+ }
145
+ function treeify(paths) {
146
+ var _a, _b;
147
+ const tree = {};
148
+ for (const [l1, l2, l3] of paths) {
149
+ const subtree = ((_a = tree[l1]) !== null && _a !== void 0 ? _a : (tree[l1] = {}));
150
+ if (l2 !== undefined) {
151
+ const set = ((_b = subtree[l2]) !== null && _b !== void 0 ? _b : (subtree[l2] = new Set()));
152
+ if (l3 !== undefined)
153
+ set.add(l3);
154
+ }
155
+ }
156
+ return tree;
157
+ }
158
+ function or(left, right) {
159
+ return (obj, ctx) => left(obj, ctx) || right(obj, ctx);
160
+ }
161
+ function concat(get, test) {
162
+ return (obj, ctx) => {
163
+ const nextObj = get(obj, ctx);
164
+ return nextObj && test(nextObj, ctx);
165
+ };
166
+ }
167
+ function leaf(pred) {
168
+ return (obj, ctx) => pred(obj, ctx) != null;
169
+ }
170
+ function arborist(tree) {
171
+ const l1Predicates = Object.entries(tree).map(([l1, subtree]) => {
172
+ const l1Pred = (obj) => obj[l1];
173
+ const l2Predicates = Object.entries(subtree).map(([l2, set]) => {
174
+ const l2Pred = (obj) => obj[l2];
175
+ const l3Predicates = Array.from(set).map((l3) => {
176
+ const l3Pred = l3 === "me" // special handling for `me` shortcut
177
+ ? (obj, ctx) => {
178
+ const me = ctx.me.id;
179
+ return testMaybeArray(obj, (u) => u.id === me);
180
+ }
181
+ : (obj) => testMaybeArray(obj, (e) => e[l3] || e.type === l3);
182
+ return l3Pred;
183
+ });
184
+ return l3Predicates.length === 0
185
+ ? leaf(l2Pred)
186
+ : concat(l2Pred, l3Predicates.reduce(or));
187
+ });
188
+ return l2Predicates.length === 0
189
+ ? leaf(l1Pred)
190
+ : concat(l1Pred, l2Predicates.reduce(or));
191
+ });
192
+ if (l1Predicates.length === 0) {
193
+ throw new Error("Cannot create filter function for empty query");
194
+ }
195
+ return l1Predicates.reduce(or);
196
+ }
197
+ function testMaybeArray(t, pred) {
198
+ const p = (x) => x != null && pred(x);
199
+ return Array.isArray(t) ? t.some(p) : p(t);
200
+ }
201
+ // === Define a structure to validate the queries
202
+ // L3
203
+ const ENTITY_KEYS = {
204
+ mention: {},
205
+ hashtag: {},
206
+ cashtag: {},
207
+ bot_command: {},
208
+ url: {},
209
+ email: {},
210
+ phone_number: {},
211
+ bold: {},
212
+ italic: {},
213
+ underline: {},
214
+ strikethrough: {},
215
+ spoiler: {},
216
+ blockquote: {},
217
+ expandable_blockquote: {},
218
+ code: {},
219
+ pre: {},
220
+ text_link: {},
221
+ text_mention: {},
222
+ custom_emoji: {},
223
+ };
224
+ const USER_KEYS = {
225
+ me: {},
226
+ is_bot: {},
227
+ is_premium: {},
228
+ added_to_attachment_menu: {},
229
+ };
230
+ const FORWARD_ORIGIN_KEYS = {
231
+ user: {},
232
+ hidden_user: {},
233
+ chat: {},
234
+ channel: {},
235
+ };
236
+ const STICKER_KEYS = {
237
+ is_video: {},
238
+ is_animated: {},
239
+ premium_animation: {},
240
+ };
241
+ const REACTION_KEYS = {
242
+ emoji: {},
243
+ custom_emoji: {},
244
+ paid: {},
245
+ };
246
+ // L2
247
+ const COMMON_MESSAGE_KEYS = {
248
+ forward_origin: FORWARD_ORIGIN_KEYS,
249
+ is_topic_message: {},
250
+ is_automatic_forward: {},
251
+ business_connection_id: {},
252
+ text: {},
253
+ animation: {},
254
+ audio: {},
255
+ document: {},
256
+ paid_media: {},
257
+ photo: {},
258
+ sticker: STICKER_KEYS,
259
+ story: {},
260
+ video: {},
261
+ video_note: {},
262
+ voice: {},
263
+ contact: {},
264
+ dice: {},
265
+ game: {},
266
+ poll: {},
267
+ venue: {},
268
+ location: {},
269
+ entities: ENTITY_KEYS,
270
+ caption_entities: ENTITY_KEYS,
271
+ caption: {},
272
+ effect_id: {},
273
+ has_media_spoiler: {},
274
+ new_chat_title: {},
275
+ new_chat_photo: {},
276
+ delete_chat_photo: {},
277
+ message_auto_delete_timer_changed: {},
278
+ pinned_message: {},
279
+ invoice: {},
280
+ proximity_alert_triggered: {},
281
+ chat_background_set: {},
282
+ giveaway_created: {},
283
+ giveaway: { only_new_members: {}, has_public_winners: {} },
284
+ giveaway_winners: { only_new_members: {}, was_refunded: {} },
285
+ giveaway_completed: {},
286
+ video_chat_scheduled: {},
287
+ video_chat_started: {},
288
+ video_chat_ended: {},
289
+ video_chat_participants_invited: {},
290
+ web_app_data: {},
291
+ };
292
+ const MESSAGE_KEYS = {
293
+ ...COMMON_MESSAGE_KEYS,
294
+ new_chat_members: USER_KEYS,
295
+ left_chat_member: USER_KEYS,
296
+ group_chat_created: {},
297
+ supergroup_chat_created: {},
298
+ migrate_to_chat_id: {},
299
+ migrate_from_chat_id: {},
300
+ successful_payment: {},
301
+ refunded_payment: {},
302
+ users_shared: {},
303
+ chat_shared: {},
304
+ connected_website: {},
305
+ write_access_allowed: {},
306
+ passport_data: {},
307
+ boost_added: {},
308
+ forum_topic_created: {},
309
+ forum_topic_edited: { name: {}, icon_custom_emoji_id: {} },
310
+ forum_topic_closed: {},
311
+ forum_topic_reopened: {},
312
+ general_forum_topic_hidden: {},
313
+ general_forum_topic_unhidden: {},
314
+ sender_boost_count: {},
315
+ };
316
+ const CHANNEL_POST_KEYS = {
317
+ ...COMMON_MESSAGE_KEYS,
318
+ channel_chat_created: {},
319
+ };
320
+ const BUSINESS_CONNECTION_KEYS = {
321
+ can_reply: {},
322
+ is_enabled: {},
323
+ };
324
+ const MESSAGE_REACTION_KEYS = {
325
+ old_reaction: REACTION_KEYS,
326
+ new_reaction: REACTION_KEYS,
327
+ };
328
+ const MESSAGE_REACTION_COUNT_UPDATED_KEYS = {
329
+ reactions: REACTION_KEYS,
330
+ };
331
+ const CALLBACK_QUERY_KEYS = { data: {}, game_short_name: {} };
332
+ const CHAT_MEMBER_UPDATED_KEYS = { from: USER_KEYS };
333
+ // L1
334
+ const UPDATE_KEYS = {
335
+ message: MESSAGE_KEYS,
336
+ edited_message: MESSAGE_KEYS,
337
+ channel_post: CHANNEL_POST_KEYS,
338
+ edited_channel_post: CHANNEL_POST_KEYS,
339
+ business_connection: BUSINESS_CONNECTION_KEYS,
340
+ business_message: MESSAGE_KEYS,
341
+ edited_business_message: MESSAGE_KEYS,
342
+ deleted_business_messages: {},
343
+ inline_query: {},
344
+ chosen_inline_result: {},
345
+ callback_query: CALLBACK_QUERY_KEYS,
346
+ shipping_query: {},
347
+ pre_checkout_query: {},
348
+ poll: {},
349
+ poll_answer: {},
350
+ my_chat_member: CHAT_MEMBER_UPDATED_KEYS,
351
+ chat_member: CHAT_MEMBER_UPDATED_KEYS,
352
+ chat_join_request: {},
353
+ message_reaction: MESSAGE_REACTION_KEYS,
354
+ message_reaction_count: MESSAGE_REACTION_COUNT_UPDATED_KEYS,
355
+ chat_boost: {},
356
+ removed_chat_boost: {},
357
+ purchased_paid_media: {},
358
+ };
359
+ // === Define some helpers for handling shortcuts, e.g. in 'edit:photo'
360
+ const L1_SHORTCUTS = {
361
+ "": ["message", "channel_post"],
362
+ msg: ["message", "channel_post"],
363
+ edit: ["edited_message", "edited_channel_post"],
364
+ };
365
+ const L2_SHORTCUTS = {
366
+ "": ["entities", "caption_entities"],
367
+ media: ["photo", "video"],
368
+ file: [
369
+ "photo",
370
+ "animation",
371
+ "audio",
372
+ "document",
373
+ "video",
374
+ "video_note",
375
+ "voice",
376
+ "sticker",
377
+ ],
378
+ };
package/out/mod.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ export { Bot, type BotConfig, BotError, type ErrorHandler, type PollingOptions, } from "./bot.js";
2
+ export { InputFile } from "./types.js";
3
+ export { type CallbackQueryContext, type ChatTypeContext, type ChosenInlineResultContext, type CommandContext, Context, type GameQueryContext, type HearsContext, type InlineQueryContext, type ReactionContext, } from "./context.js";
4
+ export * from "./convenience/constants.js";
5
+ export * from "./convenience/inline_query.js";
6
+ export * from "./convenience/input_media.js";
7
+ export * from "./convenience/keyboard.js";
8
+ export * from "./convenience/session.js";
9
+ export * from "./convenience/webhook.js";
10
+ export { type CallbackQueryMiddleware, type ChatTypeMiddleware, type CommandMiddleware, Composer, type GameQueryMiddleware, type HearsMiddleware, type InlineQueryMiddleware, type Middleware, type MiddlewareFn, type MiddlewareObj, type NextFunction, type ReactionMiddleware, } from "./composer.js";
11
+ export { type Filter, type FilterQuery, matchFilter } from "./filter.js";
12
+ export { Api } from "./core/api.js";
13
+ export { type ApiCallFn, type ApiClientOptions, type RawApi, type TransformableApi, type Transformer, type WebhookReplyEnvelope, } from "./core/client.js";
14
+ export { GrammyError, HttpError } from "./core/error.js";
package/out/mod.js ADDED
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.HttpError = exports.GrammyError = exports.Api = exports.matchFilter = exports.Composer = exports.Context = exports.InputFile = exports.BotError = exports.Bot = void 0;
18
+ // Commonly used stuff
19
+ var bot_js_1 = require("./bot.js");
20
+ Object.defineProperty(exports, "Bot", { enumerable: true, get: function () { return bot_js_1.Bot; } });
21
+ Object.defineProperty(exports, "BotError", { enumerable: true, get: function () { return bot_js_1.BotError; } });
22
+ var types_js_1 = require("./types.js");
23
+ Object.defineProperty(exports, "InputFile", { enumerable: true, get: function () { return types_js_1.InputFile; } });
24
+ var context_js_1 = require("./context.js");
25
+ Object.defineProperty(exports, "Context", { enumerable: true, get: function () { return context_js_1.Context; } });
26
+ // Convenience stuff, built-in plugins, and helpers
27
+ __exportStar(require("./convenience/constants.js"), exports);
28
+ __exportStar(require("./convenience/inline_query.js"), exports);
29
+ __exportStar(require("./convenience/input_media.js"), exports);
30
+ __exportStar(require("./convenience/keyboard.js"), exports);
31
+ __exportStar(require("./convenience/session.js"), exports);
32
+ __exportStar(require("./convenience/webhook.js"), exports);
33
+ // A little more advanced stuff
34
+ var composer_js_1 = require("./composer.js");
35
+ Object.defineProperty(exports, "Composer", { enumerable: true, get: function () { return composer_js_1.Composer; } });
36
+ var filter_js_1 = require("./filter.js");
37
+ Object.defineProperty(exports, "matchFilter", { enumerable: true, get: function () { return filter_js_1.matchFilter; } });
38
+ // Internal stuff for expert users
39
+ var api_js_1 = require("./core/api.js");
40
+ Object.defineProperty(exports, "Api", { enumerable: true, get: function () { return api_js_1.Api; } });
41
+ var error_js_1 = require("./core/error.js");
42
+ Object.defineProperty(exports, "GrammyError", { enumerable: true, get: function () { return error_js_1.GrammyError; } });
43
+ Object.defineProperty(exports, "HttpError", { enumerable: true, get: function () { return error_js_1.HttpError; } });
@@ -0,0 +1,16 @@
1
+ import { Agent as HttpAgent } from "http";
2
+ import { Agent as HttpsAgent } from "https";
3
+ import { Readable } from "stream";
4
+ export { debug } from "debug";
5
+ export declare const itrToStream: (itr: AsyncIterable<Uint8Array>) => Readable;
6
+ export declare function baseFetchConfig(apiRoot: string): {
7
+ compress: boolean;
8
+ agent: HttpsAgent;
9
+ } | {
10
+ agent: HttpAgent;
11
+ compress?: undefined;
12
+ } | {
13
+ compress?: undefined;
14
+ agent?: undefined;
15
+ };
16
+ export declare const defaultAdapter = "express";
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defaultAdapter = exports.itrToStream = exports.debug = void 0;
4
+ exports.baseFetchConfig = baseFetchConfig;
5
+ // === Needed imports
6
+ const http_1 = require("http");
7
+ const https_1 = require("https");
8
+ const stream_1 = require("stream");
9
+ // === Export debug
10
+ var debug_1 = require("debug");
11
+ Object.defineProperty(exports, "debug", { enumerable: true, get: function () { return debug_1.debug; } });
12
+ // === Export system-specific operations
13
+ // Turn an AsyncIterable<Uint8Array> into a stream
14
+ const itrToStream = (itr) => stream_1.Readable.from(itr, { objectMode: false });
15
+ exports.itrToStream = itrToStream;
16
+ // === Base configuration for `fetch` calls
17
+ const httpAgents = new Map();
18
+ const httpsAgents = new Map();
19
+ function getCached(map, key, otherwise) {
20
+ let value = map.get(key);
21
+ if (value === undefined) {
22
+ value = otherwise();
23
+ map.set(key, value);
24
+ }
25
+ return value;
26
+ }
27
+ function baseFetchConfig(apiRoot) {
28
+ if (apiRoot.startsWith("https:")) {
29
+ return {
30
+ compress: true,
31
+ agent: getCached(httpsAgents, apiRoot, () => new https_1.Agent({ keepAlive: true })),
32
+ };
33
+ }
34
+ else if (apiRoot.startsWith("http:")) {
35
+ return {
36
+ agent: getCached(httpAgents, apiRoot, () => new http_1.Agent({ keepAlive: true })),
37
+ };
38
+ }
39
+ else
40
+ return {};
41
+ }
42
+ // === Default webhook adapter
43
+ exports.defaultAdapter = "express";
@@ -0,0 +1,2 @@
1
+ export { AbortController, type AbortSignal } from "abort-controller";
2
+ export { default as fetch } from "node-fetch";
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fetch = exports.AbortController = void 0;
4
+ var abort_controller_1 = require("abort-controller");
5
+ Object.defineProperty(exports, "AbortController", { enumerable: true, get: function () { return abort_controller_1.AbortController; } });
6
+ var node_fetch_1 = require("node-fetch");
7
+ Object.defineProperty(exports, "fetch", { enumerable: true, get: function () { return node_fetch_1.default; } });
package/out/types.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "./types.node.js";
package/out/types.js ADDED
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./types.node.js"), exports);
@@ -0,0 +1,78 @@
1
+ import { type ApiMethods as ApiMethodsF, type InputMedia as InputMediaF, type InputMediaAnimation as InputMediaAnimationF, type InputMediaAudio as InputMediaAudioF, type InputMediaDocument as InputMediaDocumentF, type InputMediaPhoto as InputMediaPhotoF, type InputMediaVideo as InputMediaVideoF, type InputPaidMedia as InputPaidMediaF, type InputPaidMediaPhoto as InputPaidMediaPhotoF, type InputPaidMediaVideo as InputPaidMediaVideoF, type InputSticker as InputStickerF, type Opts as OptsF } from "@grammyjs/types";
2
+ import { type ReadStream } from "fs";
3
+ export * from "@grammyjs/types";
4
+ /** A value, or a potentially async function supplying that value */
5
+ type MaybeSupplier<T> = T | (() => T | Promise<T>);
6
+ /** Something that looks like a URL. */
7
+ interface URLLike {
8
+ /**
9
+ * Identifier of the resource. Must be in a format that can be parsed by the
10
+ * URL constructor.
11
+ */
12
+ url: string;
13
+ }
14
+ /**
15
+ * An `InputFile` wraps a number of different sources for [sending
16
+ * files](https://grammy.dev/guide/files#uploading-your-own-files).
17
+ *
18
+ * It corresponds to the `InputFile` type in the [Telegram Bot API
19
+ * Reference](https://core.telegram.org/bots/api#inputfile).
20
+ */
21
+ export declare class InputFile {
22
+ private consumed;
23
+ private readonly fileData;
24
+ /**
25
+ * Optional name of the constructed `InputFile` instance.
26
+ *
27
+ * Check out the
28
+ * [documentation](https://grammy.dev/guide/files#uploading-your-own-files)
29
+ * on sending files with `InputFile`.
30
+ */
31
+ readonly filename?: string;
32
+ /**
33
+ * Constructs an `InputFile` that can be used in the API to send files.
34
+ *
35
+ * @param file A path to a local file or a `Buffer` or a `fs.ReadStream` that specifies the file data
36
+ * @param filename Optional name of the file
37
+ */
38
+ constructor(file: MaybeSupplier<string | URL | URLLike | Uint8Array | ReadStream | Iterable<Uint8Array> | AsyncIterable<Uint8Array>>, filename?: string);
39
+ private guessFilename;
40
+ /**
41
+ * Internal method. Do not use.
42
+ *
43
+ * Converts this instance into a binary representation that can be sent to
44
+ * the Bot API server in the request body.
45
+ */
46
+ toRaw(): Promise<Uint8Array | Iterable<Uint8Array> | AsyncIterable<Uint8Array>>;
47
+ }
48
+ /** Wrapper type to bundle all methods of the Telegram API */
49
+ export type ApiMethods = ApiMethodsF<InputFile>;
50
+ /** Utility type providing the argument type for the given method name or `{}` if the method does not take any parameters */
51
+ export type Opts<M extends keyof ApiMethods> = OptsF<InputFile>[M];
52
+ /** This object describes a sticker to be added to a sticker set. */
53
+ export type InputSticker = InputStickerF<InputFile>;
54
+ /** This object represents the content of a media message to be sent. It should be one of
55
+ - InputMediaAnimation
56
+ - InputMediaDocument
57
+ - InputMediaAudio
58
+ - InputMediaPhoto
59
+ - InputMediaVideo */
60
+ export type InputMedia = InputMediaF<InputFile>;
61
+ /** Represents a photo to be sent. */
62
+ export type InputMediaPhoto = InputMediaPhotoF<InputFile>;
63
+ /** Represents a video to be sent. */
64
+ export type InputMediaVideo = InputMediaVideoF<InputFile>;
65
+ /** Represents an animation file (GIF or H.264/MPEG-4 AVC video without sound) to be sent. */
66
+ export type InputMediaAnimation = InputMediaAnimationF<InputFile>;
67
+ /** Represents an audio file to be treated as music to be sent. */
68
+ export type InputMediaAudio = InputMediaAudioF<InputFile>;
69
+ /** Represents a general file to be sent. */
70
+ export type InputMediaDocument = InputMediaDocumentF<InputFile>;
71
+ /** This object describes the paid media to be sent. Currently, it can be one of
72
+ - InputPaidMediaPhoto
73
+ - InputPaidMediaVideo */
74
+ export type InputPaidMedia = InputPaidMediaF<InputFile>;
75
+ /** The paid media to send is a photo. */
76
+ export type InputPaidMediaPhoto = InputPaidMediaPhotoF<InputFile>;
77
+ /** The paid media to send is a video. */
78
+ export type InputPaidMediaVideo = InputPaidMediaVideoF<InputFile>;