gramio 0.2.5 → 0.3.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/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  <div align="center">
4
4
 
5
- [![Bot API](https://img.shields.io/badge/Bot%20API-8.2-blue?logo=telegram&style=flat&labelColor=000&color=3b82f6)](https://core.telegram.org/bots/api)
5
+ [![Bot API](https://img.shields.io/badge/Bot%20API-9.0-blue?logo=telegram&style=flat&labelColor=000&color=3b82f6)](https://core.telegram.org/bots/api)
6
6
  [![npm](https://img.shields.io/npm/v/gramio?logo=npm&style=flat&labelColor=000&color=3b82f6)](https://www.npmjs.org/package/gramio)
7
7
  [![npm downloads](https://img.shields.io/npm/dw/gramio?logo=npm&style=flat&labelColor=000&color=3b82f6)](https://www.npmjs.org/package/gramio)
8
8
  [![JSR](https://jsr.io/badges/@gramio/core)](https://jsr.io/@gramio/core)
package/dist/index.cjs CHANGED
@@ -7,32 +7,10 @@ var contexts = require('@gramio/contexts');
7
7
  var files = require('@gramio/files');
8
8
  var format = require('@gramio/format');
9
9
  var debug = require('debug');
10
- var inspectable = require('inspectable');
10
+ var utils = require('./utils-BbVj3DtT.cjs');
11
11
  var middlewareIo = require('middleware-io');
12
12
  var keyboards = require('@gramio/keyboards');
13
13
 
14
- const ErrorKind = Symbol("ErrorKind");
15
- class TelegramError extends Error {
16
- /** Name of the API Method */
17
- method;
18
- /** Params that were sent */
19
- params;
20
- /** See {@link TelegramAPIResponseError.error_code}*/
21
- code;
22
- /** Describes why a request was unsuccessful. */
23
- payload;
24
- /** Construct new TelegramError */
25
- constructor(error, method, params) {
26
- super(error.description);
27
- this.name = method;
28
- this.method = method;
29
- this.params = params;
30
- this.code = error.error_code;
31
- if (error.parameters) this.payload = error.parameters;
32
- }
33
- }
34
- TelegramError.constructor[ErrorKind] = "TELEGRAM";
35
-
36
14
  class Composer {
37
15
  composer = middlewareIo.Composer.builder();
38
16
  length = 0;
@@ -100,44 +78,6 @@ class Composer {
100
78
  }
101
79
  }
102
80
 
103
- var __create$1 = Object.create;
104
- var __defProp$1 = Object.defineProperty;
105
- var __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor;
106
- var __knownSymbol$1 = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
107
- var __typeError$1 = (msg) => {
108
- throw TypeError(msg);
109
- };
110
- var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
111
- var __name$1 = (target, value) => __defProp$1(target, "name", { value, configurable: true });
112
- var __decoratorStart$1 = (base) => [, , , __create$1(null)];
113
- var __decoratorStrings$1 = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"];
114
- var __expectFn$1 = (fn) => fn !== void 0 && typeof fn !== "function" ? __typeError$1("Function expected") : fn;
115
- var __decoratorContext$1 = (kind, name, done, metadata, fns) => ({ kind: __decoratorStrings$1[kind], name, metadata, addInitializer: (fn) => done._ ? __typeError$1("Already initialized") : fns.push(__expectFn$1(fn || null)) });
116
- var __decoratorMetadata$1 = (array, target) => __defNormalProp$1(target, __knownSymbol$1("metadata"), array[3]);
117
- var __runInitializers$1 = (array, flags, self, value) => {
118
- for (var i = 0, fns = array[flags >> 1], n = fns && fns.length; i < n; i++) fns[i].call(self) ;
119
- return value;
120
- };
121
- var __decorateElement$1 = (array, flags, name, decorators, target, extra) => {
122
- var it, done, ctx, k = flags & 7, p = false;
123
- var j = 0;
124
- var extraInitializers = array[j] || (array[j] = []);
125
- var desc = k && ((target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc$1(target , name));
126
- __name$1(target, name);
127
- for (var i = decorators.length - 1; i >= 0; i--) {
128
- ctx = __decoratorContext$1(k, name, done = {}, array[3], extraInitializers);
129
- it = (0, decorators[i])(target, ctx), done._ = 1;
130
- __expectFn$1(it) && (target = it);
131
- }
132
- return __decoratorMetadata$1(array, target), desc && __defProp$1(target, name, desc), p ? k ^ 4 ? extra : desc : target;
133
- };
134
- var _Plugin_decorators, _init$1;
135
- _Plugin_decorators = [inspectable.Inspectable({
136
- serialize: (plugin) => ({
137
- name: plugin._.name,
138
- dependencies: plugin._.dependencies
139
- })
140
- })];
141
81
  class Plugin {
142
82
  /**
143
83
  * @internal
@@ -197,7 +137,7 @@ class Plugin {
197
137
  * Register custom class-error in plugin
198
138
  **/
199
139
  error(kind, error) {
200
- error[ErrorKind] = kind;
140
+ error[utils.ErrorKind] = kind;
201
141
  this._.errorsDefinitions[kind] = error;
202
142
  return this;
203
143
  }
@@ -312,28 +252,6 @@ class Plugin {
312
252
  return this;
313
253
  }
314
254
  }
315
- _init$1 = __decoratorStart$1();
316
- Plugin = __decorateElement$1(_init$1, 0, "Plugin", _Plugin_decorators, Plugin);
317
- __runInitializers$1(_init$1, 1, Plugin);
318
-
319
- const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
320
- function convertToString(value) {
321
- const typeOfValue = typeof value;
322
- if (typeOfValue === "string") return value;
323
- if (typeOfValue === "object") return JSON.stringify(value);
324
- return String(value);
325
- }
326
- function simplifyObject(obj) {
327
- const result = {};
328
- for (const [key, value] of Object.entries(obj)) {
329
- const typeOfValue = typeof value;
330
- if (value === void 0 || value === null || typeOfValue === "function")
331
- continue;
332
- result[key] = convertToString(value);
333
- }
334
- return result;
335
- }
336
- const IS_BUN = typeof Bun !== "undefined";
337
255
 
338
256
  class UpdateQueue {
339
257
  updateQueue = [];
@@ -372,7 +290,7 @@ class UpdateQueue {
372
290
  this.onIdlePromise = new Promise((resolve) => {
373
291
  this.onIdleResolver = resolve;
374
292
  });
375
- await Promise.race([this.onIdlePromise, sleep(timeout)]);
293
+ await Promise.race([this.onIdlePromise, utils.sleep(timeout)]);
376
294
  this.isActive = false;
377
295
  }
378
296
  }
@@ -442,9 +360,9 @@ class Updates {
442
360
  }
443
361
  } catch (error) {
444
362
  console.error("Error received when fetching updates", error);
445
- if (error instanceof TelegramError && error.payload?.retry_after) {
446
- await sleep(error.payload.retry_after * 1e3);
447
- } else await sleep(this.bot.options.api.retryGetUpdatesWait ?? 1e3);
363
+ if (error instanceof utils.TelegramError && error.payload?.retry_after) {
364
+ await utils.sleep(error.payload.retry_after * 1e3);
365
+ } else await utils.sleep(this.bot.options.api.retryGetUpdatesWait ?? 1e3);
448
366
  }
449
367
  }
450
368
  }
@@ -453,43 +371,8 @@ class Updates {
453
371
  }
454
372
  }
455
373
 
456
- var __create = Object.create;
457
- var __defProp = Object.defineProperty;
458
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
459
- var __knownSymbol = (name2, symbol) => (symbol = Symbol[name2]) ? symbol : Symbol.for("Symbol." + name2);
460
- var __typeError = (msg) => {
461
- throw TypeError(msg);
462
- };
463
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
464
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
465
- var __decoratorStart = (base) => [, , , __create(null)];
466
- var __decoratorStrings = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"];
467
- var __expectFn = (fn) => fn !== void 0 && typeof fn !== "function" ? __typeError("Function expected") : fn;
468
- var __decoratorContext = (kind, name2, done, metadata, fns) => ({ kind: __decoratorStrings[kind], name: name2, metadata, addInitializer: (fn) => done._ ? __typeError("Already initialized") : fns.push(__expectFn(fn || null)) });
469
- var __decoratorMetadata = (array, target) => __defNormalProp(target, __knownSymbol("metadata"), array[3]);
470
- var __runInitializers = (array, flags, self, value) => {
471
- for (var i = 0, fns = array[flags >> 1], n = fns && fns.length; i < n; i++) fns[i].call(self) ;
472
- return value;
473
- };
474
- var __decorateElement = (array, flags, name2, decorators, target, extra) => {
475
- var it, done, ctx, k = flags & 7, p = false;
476
- var j = 0;
477
- var extraInitializers = array[j] || (array[j] = []);
478
- var desc = k && ((target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc(target , name2));
479
- __name(target, name2);
480
- for (var i = decorators.length - 1; i >= 0; i--) {
481
- ctx = __decoratorContext(k, name2, done = {}, array[3], extraInitializers);
482
- it = (0, decorators[i])(target, ctx), done._ = 1;
483
- __expectFn(it) && (target = it);
484
- }
485
- return __decoratorMetadata(array, target), desc && __defProp(target, name2, desc), p ? k ^ 4 ? extra : desc : target;
486
- };
487
- var _Bot_decorators, _init;
488
374
  const $debugger = debug("gramio");
489
375
  const debug$api = $debugger.extend("api");
490
- _Bot_decorators = [inspectable.Inspectable({
491
- serialize: () => ({})
492
- })];
493
376
  class Bot {
494
377
  /** @deprecated use `~` instead*/
495
378
  _ = {
@@ -529,7 +412,7 @@ class Bot {
529
412
  lazyloadPlugins = [];
530
413
  dependencies = [];
531
414
  errorsDefinitions = {
532
- TELEGRAM: TelegramError
415
+ TELEGRAM: utils.TelegramError
533
416
  };
534
417
  errorHandler(context, error) {
535
418
  if (!this.hooks.onError.length)
@@ -537,7 +420,7 @@ class Bot {
537
420
  return this.runImmutableHooks("onError", {
538
421
  context,
539
422
  //@ts-expect-error ErrorKind exists if user register error-class with .error("kind", SomeError);
540
- kind: error.constructor[ErrorKind] ?? "UNKNOWN",
423
+ kind: error.constructor[utils.ErrorKind] ?? "UNKNOWN",
541
424
  error
542
425
  });
543
426
  }
@@ -609,7 +492,7 @@ class Bot {
609
492
  );
610
493
  params = context.params;
611
494
  if (params && files.isMediaUpload(method, params)) {
612
- if (IS_BUN) {
495
+ if (utils.IS_BUN) {
613
496
  const formData = await files.convertJsonToFormData(method, params);
614
497
  reqOptions.body = formData;
615
498
  } else {
@@ -618,7 +501,7 @@ class Bot {
618
501
  params
619
502
  );
620
503
  reqOptions.body = formData;
621
- const simplifiedParams = simplifyObject(paramsWithoutFiles);
504
+ const simplifiedParams = utils.simplifyObject(paramsWithoutFiles);
622
505
  url += `?${new URLSearchParams(simplifiedParams).toString()}`;
623
506
  }
624
507
  } else {
@@ -630,7 +513,7 @@ class Bot {
630
513
  const data = await response.json();
631
514
  debug$api$method("response: %j", data);
632
515
  if (!data.ok) {
633
- const err = new TelegramError(data, method, params);
516
+ const err = new utils.TelegramError(data, method, params);
634
517
  this.runImmutableHooks("onResponseError", err, this.api);
635
518
  if (!params?.suppress) throw err;
636
519
  return err;
@@ -701,7 +584,7 @@ class Bot {
701
584
  * ```
702
585
  */
703
586
  error(kind, error) {
704
- error[ErrorKind] = kind;
587
+ error[utils.ErrorKind] = kind;
705
588
  this.errorsDefinitions[kind] = error;
706
589
  return this;
707
590
  }
@@ -1103,7 +986,7 @@ class Bot {
1103
986
  const info = await this.api.getMe({
1104
987
  suppress: true
1105
988
  });
1106
- if (info instanceof TelegramError) {
989
+ if (info instanceof utils.TelegramError) {
1107
990
  if (info.code === 404)
1108
991
  info.message = "The bot token is incorrect. Check it in BotFather.";
1109
992
  throw info;
@@ -1132,10 +1015,12 @@ class Bot {
1132
1015
  } = {}) {
1133
1016
  await this.init();
1134
1017
  if (!webhook) {
1135
- await this.api.deleteWebhook({
1136
- drop_pending_updates: dropPendingUpdates
1137
- // suppress: true,
1138
- });
1018
+ await utils.withRetries(
1019
+ () => this.api.deleteWebhook({
1020
+ drop_pending_updates: dropPendingUpdates
1021
+ // suppress: true,
1022
+ })
1023
+ );
1139
1024
  this.updates.startPolling({
1140
1025
  allowed_updates: allowedUpdates
1141
1026
  });
@@ -1148,12 +1033,14 @@ class Bot {
1148
1033
  return this.info;
1149
1034
  }
1150
1035
  if (this.updates.isStarted) this.updates.stopPolling();
1151
- await this.api.setWebhook({
1152
- ...webhook,
1153
- drop_pending_updates: dropPendingUpdates,
1154
- allowed_updates: allowedUpdates
1155
- // suppress: true,
1156
- });
1036
+ await utils.withRetries(
1037
+ async () => this.api.setWebhook({
1038
+ ...webhook,
1039
+ drop_pending_updates: dropPendingUpdates,
1040
+ allowed_updates: allowedUpdates
1041
+ // suppress: true,
1042
+ })
1043
+ );
1157
1044
  this.runImmutableHooks("onStart", {
1158
1045
  plugins: this.dependencies,
1159
1046
  // biome-ignore lint/style/noNonNullAssertion: bot.init() guarantees this.info
@@ -1178,9 +1065,6 @@ class Bot {
1178
1065
  });
1179
1066
  }
1180
1067
  }
1181
- _init = __decoratorStart();
1182
- Bot = __decorateElement(_init, 0, "Bot", _Bot_decorators, Bot);
1183
- __runInitializers(_init, 1, Bot);
1184
1068
 
1185
1069
  const SECRET_TOKEN_HEADER = "X-Telegram-Bot-Api-Secret-Token";
1186
1070
  const WRONG_TOKEN_ERROR = "secret token is invalid";
@@ -1257,11 +1141,11 @@ function webhookHandler(bot, framework, secretToken) {
1257
1141
 
1258
1142
  Symbol.metadata ??= Symbol("Symbol.metadata");
1259
1143
 
1144
+ exports.ErrorKind = utils.ErrorKind;
1145
+ exports.TelegramError = utils.TelegramError;
1260
1146
  exports.Bot = Bot;
1261
1147
  exports.Composer = Composer;
1262
- exports.ErrorKind = ErrorKind;
1263
1148
  exports.Plugin = Plugin;
1264
- exports.TelegramError = TelegramError;
1265
1149
  exports.Updates = Updates;
1266
1150
  exports.webhookHandler = webhookHandler;
1267
1151
  Object.keys(callbackData).forEach(function (k) {
package/dist/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { CallbackData } from '@gramio/callback-data';
2
2
  export * from '@gramio/callback-data';
3
- import { Context, UpdateName, MaybeArray, ContextType, Attachment } from '@gramio/contexts';
3
+ import { Context, UpdateName, MaybeArray, ContextType, BotLike, Attachment } from '@gramio/contexts';
4
4
  export * from '@gramio/contexts';
5
5
  import { APIMethods, TelegramResponseParameters, TelegramAPIResponseError, TelegramUser, APIMethodParams, APIMethodReturn, TelegramUpdate, TelegramReactionTypeEmojiEmoji, SetMyCommandsParams, TelegramBotCommand } from '@gramio/types';
6
6
  export * from '@gramio/types';
@@ -556,6 +556,9 @@ type FilterDefinitions = Record<string, (...args: any[]) => (context: Context<Bo
556
556
  type AnyBot = Bot<any, any>;
557
557
  /** Type of Bot that accepts any generics */
558
558
  type AnyPlugin = Plugin<any, any>;
559
+ type CallbackQueryShorthandContext<BotType extends BotLike, Trigger extends CallbackData | string | RegExp> = Omit<ContextType<BotType, "callback_query">, "data"> & BotType["__Derives"]["global"] & BotType["__Derives"]["callback_query"] & {
560
+ queryData: Trigger extends CallbackData ? ReturnType<Trigger["unpack"]> : Trigger extends RegExp ? RegExpMatchArray : never;
561
+ };
559
562
 
560
563
  declare class UpdateQueue<Data = TelegramUpdate> {
561
564
  private updateQueue;
@@ -710,7 +713,7 @@ declare class Bot<Errors extends ErrorDefinitions = {}, Derives extends DeriveDe
710
713
  * })
711
714
  * ```
712
715
  */
713
- onError<T extends UpdateName>(updateName: MaybeArray<T>, handler: Hooks.OnError<Errors, ContextType<typeof this, T> & Derives["global"] & Derives[T]>): this;
716
+ onError<T extends UpdateName>(updateName: MaybeArray<T>, handler: Hooks.OnError<Errors, ContextType<typeof this, T>>): this;
714
717
  onError(handler: Hooks.OnError<Errors, Context<typeof this> & Derives["global"]>): this;
715
718
  /**
716
719
  * Derive some data to handlers
@@ -819,7 +822,7 @@ declare class Bot<Errors extends ErrorDefinitions = {}, Derives extends DeriveDe
819
822
  onResponseError<Methods extends keyof APIMethods, Handler extends Hooks.OnResponseError<Methods>>(methods: MaybeArray<Methods>, handler: Handler): this;
820
823
  onResponseError(handler: Hooks.OnResponseError): this;
821
824
  /** Register handler to one or many Updates */
822
- on<T extends UpdateName>(updateName: MaybeArray<T>, handler: Handler<ContextType<typeof this, T> & Derives["global"] & Derives[T]>): this;
825
+ on<T extends UpdateName>(updateName: MaybeArray<T>, handler: Handler<ContextType<typeof this, T>>): this;
823
826
  /** Register handler to any Updates */
824
827
  use(handler: Handler<Context<typeof this> & Derives["global"]>): this;
825
828
  /**
@@ -864,7 +867,7 @@ declare class Bot<Errors extends ErrorDefinitions = {}, Derives extends DeriveDe
864
867
  * });
865
868
  * ```
866
869
  * */
867
- reaction(trigger: MaybeArray<TelegramReactionTypeEmojiEmoji>, handler: (context: ContextType<typeof this, "message_reaction"> & Derives["global"] & Derives["message_reaction"]) => unknown): this;
870
+ reaction(trigger: MaybeArray<TelegramReactionTypeEmojiEmoji>, handler: (context: ContextType<typeof this, "message_reaction">) => unknown): this;
868
871
  /**
869
872
  * Register handler to `callback_query` event
870
873
  *
@@ -888,11 +891,9 @@ declare class Bot<Errors extends ErrorDefinitions = {}, Derives extends DeriveDe
888
891
  * });
889
892
  * ```
890
893
  */
891
- callbackQuery<Trigger extends CallbackData | string | RegExp>(trigger: Trigger, handler: (context: Omit<ContextType<typeof this, "callback_query">, "data"> & Derives["global"] & Derives["callback_query"] & {
892
- queryData: Trigger extends CallbackData ? ReturnType<Trigger["unpack"]> : Trigger extends RegExp ? RegExpMatchArray : never;
893
- }) => unknown): this;
894
+ callbackQuery<Trigger extends CallbackData | string | RegExp>(trigger: Trigger, handler: (context: CallbackQueryShorthandContext<typeof this, Trigger>) => unknown): this;
894
895
  /** Register handler to `chosen_inline_result` update */
895
- chosenInlineResult<Ctx = ContextType<typeof this, "chosen_inline_result"> & Derives["global"] & Derives["chosen_inline_result"]>(trigger: RegExp | string | ((context: Ctx) => boolean), handler: (context: Ctx & {
896
+ chosenInlineResult<Ctx = ContextType<typeof this, "chosen_inline_result">>(trigger: RegExp | string | ((context: Ctx) => boolean), handler: (context: Ctx & {
896
897
  args: RegExpMatchArray | null;
897
898
  }) => unknown): this;
898
899
  /**
@@ -930,10 +931,10 @@ declare class Bot<Errors extends ErrorDefinitions = {}, Derives extends DeriveDe
930
931
  * );
931
932
  * ```
932
933
  * */
933
- inlineQuery<Ctx = ContextType<typeof this, "inline_query"> & Derives["global"] & Derives["inline_query"]>(trigger: RegExp | string | ((context: Ctx) => boolean), handler: (context: Ctx & {
934
+ inlineQuery<Ctx = ContextType<typeof this, "inline_query">>(trigger: RegExp | string | ((context: Ctx) => boolean), handler: (context: Ctx & {
934
935
  args: RegExpMatchArray | null;
935
936
  }) => unknown, options?: {
936
- onResult?: (context: ContextType<Bot, "chosen_inline_result"> & Derives["global"] & Derives["chosen_inline_result"] & {
937
+ onResult?: (context: ContextType<Bot, "chosen_inline_result"> & {
937
938
  args: RegExpMatchArray | null;
938
939
  }) => unknown;
939
940
  }): this;
@@ -944,7 +945,7 @@ declare class Bot<Errors extends ErrorDefinitions = {}, Derives extends DeriveDe
944
945
  * if (context.args) await context.send(`Params ${context.args[1]}`);
945
946
  * });
946
947
  */
947
- hears<Ctx = ContextType<typeof this, "message"> & Derives["global"] & Derives["message"], Trigger extends RegExp | string | ((context: Ctx) => boolean) = RegExp | string | ((context: Ctx) => boolean)>(trigger: Trigger, handler: (context: Ctx & {
948
+ hears<Ctx = ContextType<typeof this, "message">, Trigger extends RegExp | string | ((context: Ctx) => boolean) = RegExp | string | ((context: Ctx) => boolean)>(trigger: Trigger, handler: (context: Ctx & {
948
949
  args: RegExpMatchArray | null;
949
950
  }) => unknown): this;
950
951
  /**
@@ -954,7 +955,7 @@ declare class Bot<Errors extends ErrorDefinitions = {}, Derives extends DeriveDe
954
955
  * return context.send(`You message is /start ${context.args}`);
955
956
  * });
956
957
  */
957
- command(command: string, handler: (context: ContextType<typeof this, "message"> & Derives["global"] & Derives["message"] & {
958
+ command(command: string, handler: (context: ContextType<typeof this, "message"> & {
958
959
  args: string | null;
959
960
  }) => unknown, options?: Omit<SetMyCommandsParams, "commands"> & Omit<TelegramBotCommand, "command">): this;
960
961
  /** Currently not isolated!!! */
@@ -1068,4 +1069,4 @@ declare function webhookHandler<Framework extends keyof typeof frameworks>(bot:
1068
1069
  response: () => any;
1069
1070
  } ? (...args: Parameters<(typeof frameworks)[Framework]>) => ReturnType<ReturnType<(typeof frameworks)[Framework]>["response"]> : (...args: Parameters<(typeof frameworks)[Framework]>) => void;
1070
1071
 
1071
- export { type AnyBot, type AnyPlugin, Bot, type BotOptions, Composer, type DeriveDefinitions, type ErrorDefinitions, ErrorKind, type FilterDefinitions, type Handler, Hooks, type MaybePromise, type MaybeSuppressedParams, type MaybeSuppressedReturn, Plugin, type Suppress, type SuppressedAPIMethodParams, type SuppressedAPIMethodReturn, type SuppressedAPIMethods, TelegramError, Updates, type WebhookHandlers, webhookHandler };
1072
+ export { type AnyBot, type AnyPlugin, Bot, type BotOptions, type CallbackQueryShorthandContext, Composer, type DeriveDefinitions, type ErrorDefinitions, ErrorKind, type FilterDefinitions, type Handler, Hooks, type MaybePromise, type MaybeSuppressedParams, type MaybeSuppressedReturn, Plugin, type Suppress, type SuppressedAPIMethodParams, type SuppressedAPIMethodReturn, type SuppressedAPIMethods, TelegramError, Updates, type WebhookHandlers, webhookHandler };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { CallbackData } from '@gramio/callback-data';
2
2
  export * from '@gramio/callback-data';
3
- import { Context, UpdateName, MaybeArray, ContextType, Attachment } from '@gramio/contexts';
3
+ import { Context, UpdateName, MaybeArray, ContextType, BotLike, Attachment } from '@gramio/contexts';
4
4
  export * from '@gramio/contexts';
5
5
  import { APIMethods, TelegramResponseParameters, TelegramAPIResponseError, TelegramUser, APIMethodParams, APIMethodReturn, TelegramUpdate, TelegramReactionTypeEmojiEmoji, SetMyCommandsParams, TelegramBotCommand } from '@gramio/types';
6
6
  export * from '@gramio/types';
@@ -556,6 +556,9 @@ type FilterDefinitions = Record<string, (...args: any[]) => (context: Context<Bo
556
556
  type AnyBot = Bot<any, any>;
557
557
  /** Type of Bot that accepts any generics */
558
558
  type AnyPlugin = Plugin<any, any>;
559
+ type CallbackQueryShorthandContext<BotType extends BotLike, Trigger extends CallbackData | string | RegExp> = Omit<ContextType<BotType, "callback_query">, "data"> & BotType["__Derives"]["global"] & BotType["__Derives"]["callback_query"] & {
560
+ queryData: Trigger extends CallbackData ? ReturnType<Trigger["unpack"]> : Trigger extends RegExp ? RegExpMatchArray : never;
561
+ };
559
562
 
560
563
  declare class UpdateQueue<Data = TelegramUpdate> {
561
564
  private updateQueue;
@@ -710,7 +713,7 @@ declare class Bot<Errors extends ErrorDefinitions = {}, Derives extends DeriveDe
710
713
  * })
711
714
  * ```
712
715
  */
713
- onError<T extends UpdateName>(updateName: MaybeArray<T>, handler: Hooks.OnError<Errors, ContextType<typeof this, T> & Derives["global"] & Derives[T]>): this;
716
+ onError<T extends UpdateName>(updateName: MaybeArray<T>, handler: Hooks.OnError<Errors, ContextType<typeof this, T>>): this;
714
717
  onError(handler: Hooks.OnError<Errors, Context<typeof this> & Derives["global"]>): this;
715
718
  /**
716
719
  * Derive some data to handlers
@@ -819,7 +822,7 @@ declare class Bot<Errors extends ErrorDefinitions = {}, Derives extends DeriveDe
819
822
  onResponseError<Methods extends keyof APIMethods, Handler extends Hooks.OnResponseError<Methods>>(methods: MaybeArray<Methods>, handler: Handler): this;
820
823
  onResponseError(handler: Hooks.OnResponseError): this;
821
824
  /** Register handler to one or many Updates */
822
- on<T extends UpdateName>(updateName: MaybeArray<T>, handler: Handler<ContextType<typeof this, T> & Derives["global"] & Derives[T]>): this;
825
+ on<T extends UpdateName>(updateName: MaybeArray<T>, handler: Handler<ContextType<typeof this, T>>): this;
823
826
  /** Register handler to any Updates */
824
827
  use(handler: Handler<Context<typeof this> & Derives["global"]>): this;
825
828
  /**
@@ -864,7 +867,7 @@ declare class Bot<Errors extends ErrorDefinitions = {}, Derives extends DeriveDe
864
867
  * });
865
868
  * ```
866
869
  * */
867
- reaction(trigger: MaybeArray<TelegramReactionTypeEmojiEmoji>, handler: (context: ContextType<typeof this, "message_reaction"> & Derives["global"] & Derives["message_reaction"]) => unknown): this;
870
+ reaction(trigger: MaybeArray<TelegramReactionTypeEmojiEmoji>, handler: (context: ContextType<typeof this, "message_reaction">) => unknown): this;
868
871
  /**
869
872
  * Register handler to `callback_query` event
870
873
  *
@@ -888,11 +891,9 @@ declare class Bot<Errors extends ErrorDefinitions = {}, Derives extends DeriveDe
888
891
  * });
889
892
  * ```
890
893
  */
891
- callbackQuery<Trigger extends CallbackData | string | RegExp>(trigger: Trigger, handler: (context: Omit<ContextType<typeof this, "callback_query">, "data"> & Derives["global"] & Derives["callback_query"] & {
892
- queryData: Trigger extends CallbackData ? ReturnType<Trigger["unpack"]> : Trigger extends RegExp ? RegExpMatchArray : never;
893
- }) => unknown): this;
894
+ callbackQuery<Trigger extends CallbackData | string | RegExp>(trigger: Trigger, handler: (context: CallbackQueryShorthandContext<typeof this, Trigger>) => unknown): this;
894
895
  /** Register handler to `chosen_inline_result` update */
895
- chosenInlineResult<Ctx = ContextType<typeof this, "chosen_inline_result"> & Derives["global"] & Derives["chosen_inline_result"]>(trigger: RegExp | string | ((context: Ctx) => boolean), handler: (context: Ctx & {
896
+ chosenInlineResult<Ctx = ContextType<typeof this, "chosen_inline_result">>(trigger: RegExp | string | ((context: Ctx) => boolean), handler: (context: Ctx & {
896
897
  args: RegExpMatchArray | null;
897
898
  }) => unknown): this;
898
899
  /**
@@ -930,10 +931,10 @@ declare class Bot<Errors extends ErrorDefinitions = {}, Derives extends DeriveDe
930
931
  * );
931
932
  * ```
932
933
  * */
933
- inlineQuery<Ctx = ContextType<typeof this, "inline_query"> & Derives["global"] & Derives["inline_query"]>(trigger: RegExp | string | ((context: Ctx) => boolean), handler: (context: Ctx & {
934
+ inlineQuery<Ctx = ContextType<typeof this, "inline_query">>(trigger: RegExp | string | ((context: Ctx) => boolean), handler: (context: Ctx & {
934
935
  args: RegExpMatchArray | null;
935
936
  }) => unknown, options?: {
936
- onResult?: (context: ContextType<Bot, "chosen_inline_result"> & Derives["global"] & Derives["chosen_inline_result"] & {
937
+ onResult?: (context: ContextType<Bot, "chosen_inline_result"> & {
937
938
  args: RegExpMatchArray | null;
938
939
  }) => unknown;
939
940
  }): this;
@@ -944,7 +945,7 @@ declare class Bot<Errors extends ErrorDefinitions = {}, Derives extends DeriveDe
944
945
  * if (context.args) await context.send(`Params ${context.args[1]}`);
945
946
  * });
946
947
  */
947
- hears<Ctx = ContextType<typeof this, "message"> & Derives["global"] & Derives["message"], Trigger extends RegExp | string | ((context: Ctx) => boolean) = RegExp | string | ((context: Ctx) => boolean)>(trigger: Trigger, handler: (context: Ctx & {
948
+ hears<Ctx = ContextType<typeof this, "message">, Trigger extends RegExp | string | ((context: Ctx) => boolean) = RegExp | string | ((context: Ctx) => boolean)>(trigger: Trigger, handler: (context: Ctx & {
948
949
  args: RegExpMatchArray | null;
949
950
  }) => unknown): this;
950
951
  /**
@@ -954,7 +955,7 @@ declare class Bot<Errors extends ErrorDefinitions = {}, Derives extends DeriveDe
954
955
  * return context.send(`You message is /start ${context.args}`);
955
956
  * });
956
957
  */
957
- command(command: string, handler: (context: ContextType<typeof this, "message"> & Derives["global"] & Derives["message"] & {
958
+ command(command: string, handler: (context: ContextType<typeof this, "message"> & {
958
959
  args: string | null;
959
960
  }) => unknown, options?: Omit<SetMyCommandsParams, "commands"> & Omit<TelegramBotCommand, "command">): this;
960
961
  /** Currently not isolated!!! */
@@ -1068,4 +1069,4 @@ declare function webhookHandler<Framework extends keyof typeof frameworks>(bot:
1068
1069
  response: () => any;
1069
1070
  } ? (...args: Parameters<(typeof frameworks)[Framework]>) => ReturnType<ReturnType<(typeof frameworks)[Framework]>["response"]> : (...args: Parameters<(typeof frameworks)[Framework]>) => void;
1070
1071
 
1071
- export { type AnyBot, type AnyPlugin, Bot, type BotOptions, Composer, type DeriveDefinitions, type ErrorDefinitions, ErrorKind, type FilterDefinitions, type Handler, Hooks, type MaybePromise, type MaybeSuppressedParams, type MaybeSuppressedReturn, Plugin, type Suppress, type SuppressedAPIMethodParams, type SuppressedAPIMethodReturn, type SuppressedAPIMethods, TelegramError, Updates, type WebhookHandlers, webhookHandler };
1072
+ export { type AnyBot, type AnyPlugin, Bot, type BotOptions, type CallbackQueryShorthandContext, Composer, type DeriveDefinitions, type ErrorDefinitions, ErrorKind, type FilterDefinitions, type Handler, Hooks, type MaybePromise, type MaybeSuppressedParams, type MaybeSuppressedReturn, Plugin, type Suppress, type SuppressedAPIMethodParams, type SuppressedAPIMethodReturn, type SuppressedAPIMethods, TelegramError, Updates, type WebhookHandlers, webhookHandler };
package/dist/index.js CHANGED
@@ -9,32 +9,10 @@ export * from '@gramio/files';
9
9
  import { FormattableMap } from '@gramio/format';
10
10
  export * from '@gramio/format';
11
11
  import debug from 'debug';
12
- import { Inspectable } from 'inspectable';
12
+ import { E as ErrorKind, s as sleep, T as TelegramError, I as IS_BUN, a as simplifyObject, w as withRetries } from './utils-DTFsIb2X.js';
13
13
  import { Composer as Composer$1, noopNext } from 'middleware-io';
14
14
  export * from '@gramio/keyboards';
15
15
 
16
- const ErrorKind = Symbol("ErrorKind");
17
- class TelegramError extends Error {
18
- /** Name of the API Method */
19
- method;
20
- /** Params that were sent */
21
- params;
22
- /** See {@link TelegramAPIResponseError.error_code}*/
23
- code;
24
- /** Describes why a request was unsuccessful. */
25
- payload;
26
- /** Construct new TelegramError */
27
- constructor(error, method, params) {
28
- super(error.description);
29
- this.name = method;
30
- this.method = method;
31
- this.params = params;
32
- this.code = error.error_code;
33
- if (error.parameters) this.payload = error.parameters;
34
- }
35
- }
36
- TelegramError.constructor[ErrorKind] = "TELEGRAM";
37
-
38
16
  class Composer {
39
17
  composer = Composer$1.builder();
40
18
  length = 0;
@@ -102,44 +80,6 @@ class Composer {
102
80
  }
103
81
  }
104
82
 
105
- var __create$1 = Object.create;
106
- var __defProp$1 = Object.defineProperty;
107
- var __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor;
108
- var __knownSymbol$1 = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
109
- var __typeError$1 = (msg) => {
110
- throw TypeError(msg);
111
- };
112
- var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
113
- var __name$1 = (target, value) => __defProp$1(target, "name", { value, configurable: true });
114
- var __decoratorStart$1 = (base) => [, , , __create$1(null)];
115
- var __decoratorStrings$1 = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"];
116
- var __expectFn$1 = (fn) => fn !== void 0 && typeof fn !== "function" ? __typeError$1("Function expected") : fn;
117
- var __decoratorContext$1 = (kind, name, done, metadata, fns) => ({ kind: __decoratorStrings$1[kind], name, metadata, addInitializer: (fn) => done._ ? __typeError$1("Already initialized") : fns.push(__expectFn$1(fn || null)) });
118
- var __decoratorMetadata$1 = (array, target) => __defNormalProp$1(target, __knownSymbol$1("metadata"), array[3]);
119
- var __runInitializers$1 = (array, flags, self, value) => {
120
- for (var i = 0, fns = array[flags >> 1], n = fns && fns.length; i < n; i++) fns[i].call(self) ;
121
- return value;
122
- };
123
- var __decorateElement$1 = (array, flags, name, decorators, target, extra) => {
124
- var it, done, ctx, k = flags & 7, p = false;
125
- var j = 0;
126
- var extraInitializers = array[j] || (array[j] = []);
127
- var desc = k && ((target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc$1(target , name));
128
- __name$1(target, name);
129
- for (var i = decorators.length - 1; i >= 0; i--) {
130
- ctx = __decoratorContext$1(k, name, done = {}, array[3], extraInitializers);
131
- it = (0, decorators[i])(target, ctx), done._ = 1;
132
- __expectFn$1(it) && (target = it);
133
- }
134
- return __decoratorMetadata$1(array, target), desc && __defProp$1(target, name, desc), p ? k ^ 4 ? extra : desc : target;
135
- };
136
- var _Plugin_decorators, _init$1;
137
- _Plugin_decorators = [Inspectable({
138
- serialize: (plugin) => ({
139
- name: plugin._.name,
140
- dependencies: plugin._.dependencies
141
- })
142
- })];
143
83
  class Plugin {
144
84
  /**
145
85
  * @internal
@@ -314,28 +254,6 @@ class Plugin {
314
254
  return this;
315
255
  }
316
256
  }
317
- _init$1 = __decoratorStart$1();
318
- Plugin = __decorateElement$1(_init$1, 0, "Plugin", _Plugin_decorators, Plugin);
319
- __runInitializers$1(_init$1, 1, Plugin);
320
-
321
- const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
322
- function convertToString(value) {
323
- const typeOfValue = typeof value;
324
- if (typeOfValue === "string") return value;
325
- if (typeOfValue === "object") return JSON.stringify(value);
326
- return String(value);
327
- }
328
- function simplifyObject(obj) {
329
- const result = {};
330
- for (const [key, value] of Object.entries(obj)) {
331
- const typeOfValue = typeof value;
332
- if (value === void 0 || value === null || typeOfValue === "function")
333
- continue;
334
- result[key] = convertToString(value);
335
- }
336
- return result;
337
- }
338
- const IS_BUN = typeof Bun !== "undefined";
339
257
 
340
258
  class UpdateQueue {
341
259
  updateQueue = [];
@@ -455,43 +373,8 @@ class Updates {
455
373
  }
456
374
  }
457
375
 
458
- var __create = Object.create;
459
- var __defProp = Object.defineProperty;
460
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
461
- var __knownSymbol = (name2, symbol) => (symbol = Symbol[name2]) ? symbol : Symbol.for("Symbol." + name2);
462
- var __typeError = (msg) => {
463
- throw TypeError(msg);
464
- };
465
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
466
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
467
- var __decoratorStart = (base) => [, , , __create(null)];
468
- var __decoratorStrings = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"];
469
- var __expectFn = (fn) => fn !== void 0 && typeof fn !== "function" ? __typeError("Function expected") : fn;
470
- var __decoratorContext = (kind, name2, done, metadata, fns) => ({ kind: __decoratorStrings[kind], name: name2, metadata, addInitializer: (fn) => done._ ? __typeError("Already initialized") : fns.push(__expectFn(fn || null)) });
471
- var __decoratorMetadata = (array, target) => __defNormalProp(target, __knownSymbol("metadata"), array[3]);
472
- var __runInitializers = (array, flags, self, value) => {
473
- for (var i = 0, fns = array[flags >> 1], n = fns && fns.length; i < n; i++) fns[i].call(self) ;
474
- return value;
475
- };
476
- var __decorateElement = (array, flags, name2, decorators, target, extra) => {
477
- var it, done, ctx, k = flags & 7, p = false;
478
- var j = 0;
479
- var extraInitializers = array[j] || (array[j] = []);
480
- var desc = k && ((target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc(target , name2));
481
- __name(target, name2);
482
- for (var i = decorators.length - 1; i >= 0; i--) {
483
- ctx = __decoratorContext(k, name2, done = {}, array[3], extraInitializers);
484
- it = (0, decorators[i])(target, ctx), done._ = 1;
485
- __expectFn(it) && (target = it);
486
- }
487
- return __decoratorMetadata(array, target), desc && __defProp(target, name2, desc), p ? k ^ 4 ? extra : desc : target;
488
- };
489
- var _Bot_decorators, _init;
490
376
  const $debugger = debug("gramio");
491
377
  const debug$api = $debugger.extend("api");
492
- _Bot_decorators = [Inspectable({
493
- serialize: () => ({})
494
- })];
495
378
  class Bot {
496
379
  /** @deprecated use `~` instead*/
497
380
  _ = {
@@ -1134,10 +1017,12 @@ class Bot {
1134
1017
  } = {}) {
1135
1018
  await this.init();
1136
1019
  if (!webhook) {
1137
- await this.api.deleteWebhook({
1138
- drop_pending_updates: dropPendingUpdates
1139
- // suppress: true,
1140
- });
1020
+ await withRetries(
1021
+ () => this.api.deleteWebhook({
1022
+ drop_pending_updates: dropPendingUpdates
1023
+ // suppress: true,
1024
+ })
1025
+ );
1141
1026
  this.updates.startPolling({
1142
1027
  allowed_updates: allowedUpdates
1143
1028
  });
@@ -1150,12 +1035,14 @@ class Bot {
1150
1035
  return this.info;
1151
1036
  }
1152
1037
  if (this.updates.isStarted) this.updates.stopPolling();
1153
- await this.api.setWebhook({
1154
- ...webhook,
1155
- drop_pending_updates: dropPendingUpdates,
1156
- allowed_updates: allowedUpdates
1157
- // suppress: true,
1158
- });
1038
+ await withRetries(
1039
+ async () => this.api.setWebhook({
1040
+ ...webhook,
1041
+ drop_pending_updates: dropPendingUpdates,
1042
+ allowed_updates: allowedUpdates
1043
+ // suppress: true,
1044
+ })
1045
+ );
1159
1046
  this.runImmutableHooks("onStart", {
1160
1047
  plugins: this.dependencies,
1161
1048
  // biome-ignore lint/style/noNonNullAssertion: bot.init() guarantees this.info
@@ -1180,9 +1067,6 @@ class Bot {
1180
1067
  });
1181
1068
  }
1182
1069
  }
1183
- _init = __decoratorStart();
1184
- Bot = __decorateElement(_init, 0, "Bot", _Bot_decorators, Bot);
1185
- __runInitializers(_init, 1, Bot);
1186
1070
 
1187
1071
  const SECRET_TOKEN_HEADER = "X-Telegram-Bot-Api-Secret-Token";
1188
1072
  const WRONG_TOKEN_ERROR = "secret token is invalid";
@@ -0,0 +1,72 @@
1
+ 'use strict';
2
+
3
+ const ErrorKind = Symbol("ErrorKind");
4
+ class TelegramError extends Error {
5
+ /** Name of the API Method */
6
+ method;
7
+ /** Params that were sent */
8
+ params;
9
+ /** See {@link TelegramAPIResponseError.error_code}*/
10
+ code;
11
+ /** Describes why a request was unsuccessful. */
12
+ payload;
13
+ /** Construct new TelegramError */
14
+ constructor(error, method, params) {
15
+ super(error.description);
16
+ this.name = method;
17
+ this.method = method;
18
+ this.params = params;
19
+ this.code = error.error_code;
20
+ if (error.parameters) this.payload = error.parameters;
21
+ }
22
+ }
23
+ TelegramError.constructor[ErrorKind] = "TELEGRAM";
24
+
25
+ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
26
+ function convertToString(value) {
27
+ const typeOfValue = typeof value;
28
+ if (typeOfValue === "string") return value;
29
+ if (typeOfValue === "object") return JSON.stringify(value);
30
+ return String(value);
31
+ }
32
+ function simplifyObject(obj) {
33
+ const result = {};
34
+ for (const [key, value] of Object.entries(obj)) {
35
+ const typeOfValue = typeof value;
36
+ if (value === void 0 || value === null || typeOfValue === "function")
37
+ continue;
38
+ result[key] = convertToString(value);
39
+ }
40
+ return result;
41
+ }
42
+ const IS_BUN = typeof Bun !== "undefined";
43
+
44
+ async function suppressError(fn) {
45
+ try {
46
+ return [await fn(), false];
47
+ } catch (error) {
48
+ return [error, true];
49
+ }
50
+ }
51
+ async function withRetries(resultPromise) {
52
+ let [result, isFromCatch] = await suppressError(resultPromise);
53
+ while (result instanceof TelegramError) {
54
+ const retryAfter = result.payload?.retry_after;
55
+ if (retryAfter) {
56
+ await sleep(retryAfter * 1e3);
57
+ [result, isFromCatch] = await suppressError(resultPromise);
58
+ } else {
59
+ if (isFromCatch) throw result;
60
+ return result;
61
+ }
62
+ }
63
+ if (result instanceof Error && isFromCatch) throw result;
64
+ return result;
65
+ }
66
+
67
+ exports.ErrorKind = ErrorKind;
68
+ exports.IS_BUN = IS_BUN;
69
+ exports.TelegramError = TelegramError;
70
+ exports.simplifyObject = simplifyObject;
71
+ exports.sleep = sleep;
72
+ exports.withRetries = withRetries;
@@ -0,0 +1,65 @@
1
+ const ErrorKind = Symbol("ErrorKind");
2
+ class TelegramError extends Error {
3
+ /** Name of the API Method */
4
+ method;
5
+ /** Params that were sent */
6
+ params;
7
+ /** See {@link TelegramAPIResponseError.error_code}*/
8
+ code;
9
+ /** Describes why a request was unsuccessful. */
10
+ payload;
11
+ /** Construct new TelegramError */
12
+ constructor(error, method, params) {
13
+ super(error.description);
14
+ this.name = method;
15
+ this.method = method;
16
+ this.params = params;
17
+ this.code = error.error_code;
18
+ if (error.parameters) this.payload = error.parameters;
19
+ }
20
+ }
21
+ TelegramError.constructor[ErrorKind] = "TELEGRAM";
22
+
23
+ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
24
+ function convertToString(value) {
25
+ const typeOfValue = typeof value;
26
+ if (typeOfValue === "string") return value;
27
+ if (typeOfValue === "object") return JSON.stringify(value);
28
+ return String(value);
29
+ }
30
+ function simplifyObject(obj) {
31
+ const result = {};
32
+ for (const [key, value] of Object.entries(obj)) {
33
+ const typeOfValue = typeof value;
34
+ if (value === void 0 || value === null || typeOfValue === "function")
35
+ continue;
36
+ result[key] = convertToString(value);
37
+ }
38
+ return result;
39
+ }
40
+ const IS_BUN = typeof Bun !== "undefined";
41
+
42
+ async function suppressError(fn) {
43
+ try {
44
+ return [await fn(), false];
45
+ } catch (error) {
46
+ return [error, true];
47
+ }
48
+ }
49
+ async function withRetries(resultPromise) {
50
+ let [result, isFromCatch] = await suppressError(resultPromise);
51
+ while (result instanceof TelegramError) {
52
+ const retryAfter = result.payload?.retry_after;
53
+ if (retryAfter) {
54
+ await sleep(retryAfter * 1e3);
55
+ [result, isFromCatch] = await suppressError(resultPromise);
56
+ } else {
57
+ if (isFromCatch) throw result;
58
+ return result;
59
+ }
60
+ }
61
+ if (result instanceof Error && isFromCatch) throw result;
62
+ return result;
63
+ }
64
+
65
+ export { ErrorKind as E, IS_BUN as I, TelegramError as T, simplifyObject as a, sleep as s, withRetries as w };
package/dist/utils.cjs ADDED
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ var utils = require('./utils-BbVj3DtT.cjs');
4
+
5
+
6
+
7
+ exports.withRetries = utils.withRetries;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @module
3
+ *
4
+ * Pack of useful utilities for Telegram Bot API and GramIO
5
+ */
6
+ declare function withRetries<Result>(resultPromise: () => Promise<Result>): Promise<Result>;
7
+
8
+ export { withRetries };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @module
3
+ *
4
+ * Pack of useful utilities for Telegram Bot API and GramIO
5
+ */
6
+ declare function withRetries<Result>(resultPromise: () => Promise<Result>): Promise<Result>;
7
+
8
+ export { withRetries };
package/dist/utils.js ADDED
@@ -0,0 +1 @@
1
+ export { w as withRetries } from './utils-DTFsIb2X.js';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "gramio",
3
3
  "type": "module",
4
- "version": "0.2.5",
4
+ "version": "0.3.0",
5
5
  "description": "Powerful, extensible and really type-safe Telegram Bot API framework",
6
6
  "main": "dist/index.cjs",
7
7
  "module": "dist/index.js",
@@ -16,6 +16,16 @@
16
16
  "types": "./dist/index.d.cts",
17
17
  "default": "./dist/index.cjs"
18
18
  }
19
+ },
20
+ "./utils": {
21
+ "import": {
22
+ "types": "./dist/utils.d.ts",
23
+ "default": "./dist/utils.js"
24
+ },
25
+ "require": {
26
+ "types": "./dist/utils.d.cts",
27
+ "default": "./dist/utils.cjs"
28
+ }
19
29
  }
20
30
  },
21
31
  "keywords": [
@@ -27,7 +37,12 @@
27
37
  "types",
28
38
  "client",
29
39
  "webhook",
30
- "long-polling"
40
+ "long-polling",
41
+ "files",
42
+ "plugins",
43
+ "format",
44
+ "contexts",
45
+ "files"
31
46
  ],
32
47
  "scripts": {
33
48
  "type": "tsc --noEmit",
@@ -41,20 +56,19 @@
41
56
  "license": "MIT",
42
57
  "devDependencies": {
43
58
  "@biomejs/biome": "1.9.4",
44
- "@types/bun": "^1.2.5",
59
+ "@types/bun": "^1.2.9",
45
60
  "@types/debug": "^4.1.12",
46
- "pkgroll": "^2.11.2",
47
- "typescript": "^5.8.2"
61
+ "pkgroll": "^2.12.1",
62
+ "typescript": "^5.8.3"
48
63
  },
49
64
  "dependencies": {
50
65
  "@gramio/callback-data": "^0.0.3",
51
- "@gramio/contexts": "^0.1.4",
52
- "@gramio/files": "^0.2.0",
53
- "@gramio/format": "^0.1.5",
54
- "@gramio/keyboards": "^1.1.0",
55
- "@gramio/types": "^8.3.3",
66
+ "@gramio/contexts": "^0.2.0",
67
+ "@gramio/files": "^0.3.0",
68
+ "@gramio/format": "^0.2.0",
69
+ "@gramio/keyboards": "^1.2.1",
70
+ "@gramio/types": "^9.0.1",
56
71
  "debug": "^4.4.0",
57
- "inspectable": "^3.0.2",
58
72
  "middleware-io": "^2.8.1"
59
73
  },
60
74
  "files": ["dist"]