gramio 0.2.6 → 0.3.1

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,7 +7,6 @@ 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');
11
10
  var utils = require('./utils-BbVj3DtT.cjs');
12
11
  var middlewareIo = require('middleware-io');
13
12
  var keyboards = require('@gramio/keyboards');
@@ -79,44 +78,6 @@ class Composer {
79
78
  }
80
79
  }
81
80
 
82
- var __create$1 = Object.create;
83
- var __defProp$1 = Object.defineProperty;
84
- var __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor;
85
- var __knownSymbol$1 = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
86
- var __typeError$1 = (msg) => {
87
- throw TypeError(msg);
88
- };
89
- var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
90
- var __name$1 = (target, value) => __defProp$1(target, "name", { value, configurable: true });
91
- var __decoratorStart$1 = (base) => [, , , __create$1(null)];
92
- var __decoratorStrings$1 = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"];
93
- var __expectFn$1 = (fn) => fn !== void 0 && typeof fn !== "function" ? __typeError$1("Function expected") : fn;
94
- 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)) });
95
- var __decoratorMetadata$1 = (array, target) => __defNormalProp$1(target, __knownSymbol$1("metadata"), array[3]);
96
- var __runInitializers$1 = (array, flags, self, value) => {
97
- for (var i = 0, fns = array[flags >> 1], n = fns && fns.length; i < n; i++) fns[i].call(self) ;
98
- return value;
99
- };
100
- var __decorateElement$1 = (array, flags, name, decorators, target, extra) => {
101
- var it, done, ctx, k = flags & 7, p = false;
102
- var j = 0;
103
- var extraInitializers = array[j] || (array[j] = []);
104
- var desc = k && ((target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc$1(target , name));
105
- __name$1(target, name);
106
- for (var i = decorators.length - 1; i >= 0; i--) {
107
- ctx = __decoratorContext$1(k, name, done = {}, array[3], extraInitializers);
108
- it = (0, decorators[i])(target, ctx), done._ = 1;
109
- __expectFn$1(it) && (target = it);
110
- }
111
- return __decoratorMetadata$1(array, target), desc && __defProp$1(target, name, desc), p ? k ^ 4 ? extra : desc : target;
112
- };
113
- var _Plugin_decorators, _init$1;
114
- _Plugin_decorators = [inspectable.Inspectable({
115
- serialize: (plugin) => ({
116
- name: plugin._.name,
117
- dependencies: plugin._.dependencies
118
- })
119
- })];
120
81
  class Plugin {
121
82
  /**
122
83
  * @internal
@@ -291,9 +252,6 @@ class Plugin {
291
252
  return this;
292
253
  }
293
254
  }
294
- _init$1 = __decoratorStart$1();
295
- Plugin = __decorateElement$1(_init$1, 0, "Plugin", _Plugin_decorators, Plugin);
296
- __runInitializers$1(_init$1, 1, Plugin);
297
255
 
298
256
  class UpdateQueue {
299
257
  updateQueue = [];
@@ -348,12 +306,12 @@ class Updates {
348
306
  this.composer = new Composer(onError);
349
307
  this.queue = new UpdateQueue(this.handleUpdate.bind(this));
350
308
  }
351
- async handleUpdate(data) {
309
+ async handleUpdate(data, mode = "wait") {
352
310
  const updateType = Object.keys(data).at(1);
353
311
  const UpdateContext = contexts.contextsMappings[updateType];
354
312
  if (!UpdateContext) throw new Error(updateType);
355
313
  const updatePayload = data[updateType];
356
- if (!updatePayload) throw new Error("");
314
+ if (!updatePayload) throw new Error("Unsupported event??");
357
315
  try {
358
316
  let context = new UpdateContext({
359
317
  bot: this.bot,
@@ -375,7 +333,7 @@ class Updates {
375
333
  updateId: data.update_id
376
334
  });
377
335
  }
378
- return this.composer.composeWait(context);
336
+ return mode === "wait" ? this.composer.composeWait(context) : this.composer.compose(context);
379
337
  } catch (error) {
380
338
  throw new Error(`[UPDATES] Update type ${updateType} not supported.`);
381
339
  }
@@ -413,43 +371,8 @@ class Updates {
413
371
  }
414
372
  }
415
373
 
416
- var __create = Object.create;
417
- var __defProp = Object.defineProperty;
418
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
419
- var __knownSymbol = (name2, symbol) => (symbol = Symbol[name2]) ? symbol : Symbol.for("Symbol." + name2);
420
- var __typeError = (msg) => {
421
- throw TypeError(msg);
422
- };
423
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
424
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
425
- var __decoratorStart = (base) => [, , , __create(null)];
426
- var __decoratorStrings = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"];
427
- var __expectFn = (fn) => fn !== void 0 && typeof fn !== "function" ? __typeError("Function expected") : fn;
428
- var __decoratorContext = (kind, name2, done, metadata, fns) => ({ kind: __decoratorStrings[kind], name: name2, metadata, addInitializer: (fn) => done._ ? __typeError("Already initialized") : fns.push(__expectFn(fn || null)) });
429
- var __decoratorMetadata = (array, target) => __defNormalProp(target, __knownSymbol("metadata"), array[3]);
430
- var __runInitializers = (array, flags, self, value) => {
431
- for (var i = 0, fns = array[flags >> 1], n = fns && fns.length; i < n; i++) fns[i].call(self) ;
432
- return value;
433
- };
434
- var __decorateElement = (array, flags, name2, decorators, target, extra) => {
435
- var it, done, ctx, k = flags & 7, p = false;
436
- var j = 0;
437
- var extraInitializers = array[j] || (array[j] = []);
438
- var desc = k && ((target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc(target , name2));
439
- __name(target, name2);
440
- for (var i = decorators.length - 1; i >= 0; i--) {
441
- ctx = __decoratorContext(k, name2, done = {}, array[3], extraInitializers);
442
- it = (0, decorators[i])(target, ctx), done._ = 1;
443
- __expectFn(it) && (target = it);
444
- }
445
- return __decoratorMetadata(array, target), desc && __defProp(target, name2, desc), p ? k ^ 4 ? extra : desc : target;
446
- };
447
- var _Bot_decorators, _init;
448
374
  const $debugger = debug("gramio");
449
375
  const debug$api = $debugger.extend("api");
450
- _Bot_decorators = [inspectable.Inspectable({
451
- serialize: () => ({})
452
- })];
453
376
  class Bot {
454
377
  /** @deprecated use `~` instead*/
455
378
  _ = {
@@ -1142,9 +1065,6 @@ class Bot {
1142
1065
  });
1143
1066
  }
1144
1067
  }
1145
- _init = __decoratorStart();
1146
- Bot = __decorateElement(_init, 0, "Bot", _Bot_decorators, Bot);
1147
- __runInitializers(_init, 1, Bot);
1148
1068
 
1149
1069
  const SECRET_TOKEN_HEADER = "X-Telegram-Bot-Api-Secret-Token";
1150
1070
  const WRONG_TOKEN_ERROR = "secret token is invalid";
package/dist/index.d.cts CHANGED
@@ -198,10 +198,10 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
198
198
  * })
199
199
  * ```
200
200
  */
201
- derive<Handler extends Hooks.Derive<Context<AnyBot> & Derives["global"]>>(handler: Handler): Plugin<Errors, Derives & {
201
+ derive<Handler extends Hooks.Derive<Context<BotLike> & Derives["global"]>>(handler: Handler): Plugin<Errors, Derives & {
202
202
  global: Awaited<ReturnType<Handler>>;
203
203
  }>;
204
- derive<Update extends UpdateName, Handler extends Hooks.Derive<ContextType<AnyBot, Update> & Derives["global"] & Derives[Update]>>(updateName: MaybeArray<Update>, handler: Handler): Plugin<Errors, Derives & {
204
+ derive<Update extends UpdateName, Handler extends Hooks.Derive<ContextType<BotLike, Update> & Derives["global"] & Derives[Update]>>(updateName: MaybeArray<Update>, handler: Handler): Plugin<Errors, Derives & {
205
205
  [K in Update]: Awaited<ReturnType<Handler>>;
206
206
  }>;
207
207
  decorate<Value extends Record<string, any>>(value: Value): Plugin<Errors, Derives & {
@@ -215,9 +215,9 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
215
215
  };
216
216
  }>;
217
217
  /** Register handler to one or many Updates */
218
- on<T extends UpdateName>(updateName: MaybeArray<T>, handler: Handler<ContextType<AnyBot, T> & Derives["global"] & Derives[T]>): this;
218
+ on<T extends UpdateName>(updateName: MaybeArray<T>, handler: Handler<ContextType<BotLike, T> & Derives["global"] & Derives[T]>): this;
219
219
  /** Register handler to any Updates */
220
- use(handler: Handler<Context<AnyBot> & Derives["global"]>): this;
220
+ use(handler: Handler<Context<BotLike> & Derives["global"]>): this;
221
221
  /**
222
222
  * This hook called before sending a request to Telegram Bot API (allows us to impact the sent parameters).
223
223
  *
@@ -305,8 +305,8 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
305
305
  * })
306
306
  * ```
307
307
  */
308
- onError<T extends UpdateName>(updateName: MaybeArray<T>, handler: Hooks.OnError<Errors, ContextType<Bot, T> & Derives["global"] & Derives[T]>): this;
309
- onError(handler: Hooks.OnError<Errors, Context<AnyBot> & Derives["global"]>): this;
308
+ onError<T extends UpdateName>(updateName: MaybeArray<T>, handler: Hooks.OnError<Errors, ContextType<BotLike, T> & Derives["global"] & Derives[T]>): this;
309
+ onError(handler: Hooks.OnError<Errors, Context<BotLike> & Derives["global"]>): this;
310
310
  /**
311
311
  * ! ** At the moment, it can only pick up types** */
312
312
  extend<NewPlugin extends AnyPlugin>(plugin: MaybePromise<NewPlugin>): Plugin<Errors & NewPlugin["_"]["Errors"], Derives & NewPlugin["_"]["Derives"]>;
@@ -580,7 +580,7 @@ declare class Updates {
580
580
  composer: Composer;
581
581
  queue: UpdateQueue<TelegramUpdate>;
582
582
  constructor(bot: AnyBot, onError: CaughtMiddlewareHandler<Context<any>>);
583
- handleUpdate(data: TelegramUpdate): Promise<unknown>;
583
+ handleUpdate(data: TelegramUpdate, mode?: "wait" | "lazy"): Promise<unknown>;
584
584
  /** @deprecated use bot.start instead @internal */
585
585
  startPolling(params?: APIMethodParams<"getUpdates">): void;
586
586
  startFetchLoop(params?: APIMethodParams<"getUpdates">): Promise<void>;
@@ -713,7 +713,7 @@ declare class Bot<Errors extends ErrorDefinitions = {}, Derives extends DeriveDe
713
713
  * })
714
714
  * ```
715
715
  */
716
- 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;
717
717
  onError(handler: Hooks.OnError<Errors, Context<typeof this> & Derives["global"]>): this;
718
718
  /**
719
719
  * Derive some data to handlers
@@ -822,7 +822,7 @@ declare class Bot<Errors extends ErrorDefinitions = {}, Derives extends DeriveDe
822
822
  onResponseError<Methods extends keyof APIMethods, Handler extends Hooks.OnResponseError<Methods>>(methods: MaybeArray<Methods>, handler: Handler): this;
823
823
  onResponseError(handler: Hooks.OnResponseError): this;
824
824
  /** Register handler to one or many Updates */
825
- 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;
826
826
  /** Register handler to any Updates */
827
827
  use(handler: Handler<Context<typeof this> & Derives["global"]>): this;
828
828
  /**
@@ -867,7 +867,7 @@ declare class Bot<Errors extends ErrorDefinitions = {}, Derives extends DeriveDe
867
867
  * });
868
868
  * ```
869
869
  * */
870
- 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;
871
871
  /**
872
872
  * Register handler to `callback_query` event
873
873
  *
@@ -893,7 +893,7 @@ declare class Bot<Errors extends ErrorDefinitions = {}, Derives extends DeriveDe
893
893
  */
894
894
  callbackQuery<Trigger extends CallbackData | string | RegExp>(trigger: Trigger, handler: (context: CallbackQueryShorthandContext<typeof this, Trigger>) => unknown): this;
895
895
  /** Register handler to `chosen_inline_result` update */
896
- 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 & {
897
897
  args: RegExpMatchArray | null;
898
898
  }) => unknown): this;
899
899
  /**
@@ -931,10 +931,10 @@ declare class Bot<Errors extends ErrorDefinitions = {}, Derives extends DeriveDe
931
931
  * );
932
932
  * ```
933
933
  * */
934
- 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 & {
935
935
  args: RegExpMatchArray | null;
936
936
  }) => unknown, options?: {
937
- onResult?: (context: ContextType<Bot, "chosen_inline_result"> & Derives["global"] & Derives["chosen_inline_result"] & {
937
+ onResult?: (context: ContextType<Bot, "chosen_inline_result"> & {
938
938
  args: RegExpMatchArray | null;
939
939
  }) => unknown;
940
940
  }): this;
@@ -945,7 +945,7 @@ declare class Bot<Errors extends ErrorDefinitions = {}, Derives extends DeriveDe
945
945
  * if (context.args) await context.send(`Params ${context.args[1]}`);
946
946
  * });
947
947
  */
948
- 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 & {
949
949
  args: RegExpMatchArray | null;
950
950
  }) => unknown): this;
951
951
  /**
@@ -955,7 +955,7 @@ declare class Bot<Errors extends ErrorDefinitions = {}, Derives extends DeriveDe
955
955
  * return context.send(`You message is /start ${context.args}`);
956
956
  * });
957
957
  */
958
- command(command: string, handler: (context: ContextType<typeof this, "message"> & Derives["global"] & Derives["message"] & {
958
+ command(command: string, handler: (context: ContextType<typeof this, "message"> & {
959
959
  args: string | null;
960
960
  }) => unknown, options?: Omit<SetMyCommandsParams, "commands"> & Omit<TelegramBotCommand, "command">): this;
961
961
  /** Currently not isolated!!! */
package/dist/index.d.ts CHANGED
@@ -198,10 +198,10 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
198
198
  * })
199
199
  * ```
200
200
  */
201
- derive<Handler extends Hooks.Derive<Context<AnyBot> & Derives["global"]>>(handler: Handler): Plugin<Errors, Derives & {
201
+ derive<Handler extends Hooks.Derive<Context<BotLike> & Derives["global"]>>(handler: Handler): Plugin<Errors, Derives & {
202
202
  global: Awaited<ReturnType<Handler>>;
203
203
  }>;
204
- derive<Update extends UpdateName, Handler extends Hooks.Derive<ContextType<AnyBot, Update> & Derives["global"] & Derives[Update]>>(updateName: MaybeArray<Update>, handler: Handler): Plugin<Errors, Derives & {
204
+ derive<Update extends UpdateName, Handler extends Hooks.Derive<ContextType<BotLike, Update> & Derives["global"] & Derives[Update]>>(updateName: MaybeArray<Update>, handler: Handler): Plugin<Errors, Derives & {
205
205
  [K in Update]: Awaited<ReturnType<Handler>>;
206
206
  }>;
207
207
  decorate<Value extends Record<string, any>>(value: Value): Plugin<Errors, Derives & {
@@ -215,9 +215,9 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
215
215
  };
216
216
  }>;
217
217
  /** Register handler to one or many Updates */
218
- on<T extends UpdateName>(updateName: MaybeArray<T>, handler: Handler<ContextType<AnyBot, T> & Derives["global"] & Derives[T]>): this;
218
+ on<T extends UpdateName>(updateName: MaybeArray<T>, handler: Handler<ContextType<BotLike, T> & Derives["global"] & Derives[T]>): this;
219
219
  /** Register handler to any Updates */
220
- use(handler: Handler<Context<AnyBot> & Derives["global"]>): this;
220
+ use(handler: Handler<Context<BotLike> & Derives["global"]>): this;
221
221
  /**
222
222
  * This hook called before sending a request to Telegram Bot API (allows us to impact the sent parameters).
223
223
  *
@@ -305,8 +305,8 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
305
305
  * })
306
306
  * ```
307
307
  */
308
- onError<T extends UpdateName>(updateName: MaybeArray<T>, handler: Hooks.OnError<Errors, ContextType<Bot, T> & Derives["global"] & Derives[T]>): this;
309
- onError(handler: Hooks.OnError<Errors, Context<AnyBot> & Derives["global"]>): this;
308
+ onError<T extends UpdateName>(updateName: MaybeArray<T>, handler: Hooks.OnError<Errors, ContextType<BotLike, T> & Derives["global"] & Derives[T]>): this;
309
+ onError(handler: Hooks.OnError<Errors, Context<BotLike> & Derives["global"]>): this;
310
310
  /**
311
311
  * ! ** At the moment, it can only pick up types** */
312
312
  extend<NewPlugin extends AnyPlugin>(plugin: MaybePromise<NewPlugin>): Plugin<Errors & NewPlugin["_"]["Errors"], Derives & NewPlugin["_"]["Derives"]>;
@@ -580,7 +580,7 @@ declare class Updates {
580
580
  composer: Composer;
581
581
  queue: UpdateQueue<TelegramUpdate>;
582
582
  constructor(bot: AnyBot, onError: CaughtMiddlewareHandler<Context<any>>);
583
- handleUpdate(data: TelegramUpdate): Promise<unknown>;
583
+ handleUpdate(data: TelegramUpdate, mode?: "wait" | "lazy"): Promise<unknown>;
584
584
  /** @deprecated use bot.start instead @internal */
585
585
  startPolling(params?: APIMethodParams<"getUpdates">): void;
586
586
  startFetchLoop(params?: APIMethodParams<"getUpdates">): Promise<void>;
@@ -713,7 +713,7 @@ declare class Bot<Errors extends ErrorDefinitions = {}, Derives extends DeriveDe
713
713
  * })
714
714
  * ```
715
715
  */
716
- 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;
717
717
  onError(handler: Hooks.OnError<Errors, Context<typeof this> & Derives["global"]>): this;
718
718
  /**
719
719
  * Derive some data to handlers
@@ -822,7 +822,7 @@ declare class Bot<Errors extends ErrorDefinitions = {}, Derives extends DeriveDe
822
822
  onResponseError<Methods extends keyof APIMethods, Handler extends Hooks.OnResponseError<Methods>>(methods: MaybeArray<Methods>, handler: Handler): this;
823
823
  onResponseError(handler: Hooks.OnResponseError): this;
824
824
  /** Register handler to one or many Updates */
825
- 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;
826
826
  /** Register handler to any Updates */
827
827
  use(handler: Handler<Context<typeof this> & Derives["global"]>): this;
828
828
  /**
@@ -867,7 +867,7 @@ declare class Bot<Errors extends ErrorDefinitions = {}, Derives extends DeriveDe
867
867
  * });
868
868
  * ```
869
869
  * */
870
- 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;
871
871
  /**
872
872
  * Register handler to `callback_query` event
873
873
  *
@@ -893,7 +893,7 @@ declare class Bot<Errors extends ErrorDefinitions = {}, Derives extends DeriveDe
893
893
  */
894
894
  callbackQuery<Trigger extends CallbackData | string | RegExp>(trigger: Trigger, handler: (context: CallbackQueryShorthandContext<typeof this, Trigger>) => unknown): this;
895
895
  /** Register handler to `chosen_inline_result` update */
896
- 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 & {
897
897
  args: RegExpMatchArray | null;
898
898
  }) => unknown): this;
899
899
  /**
@@ -931,10 +931,10 @@ declare class Bot<Errors extends ErrorDefinitions = {}, Derives extends DeriveDe
931
931
  * );
932
932
  * ```
933
933
  * */
934
- 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 & {
935
935
  args: RegExpMatchArray | null;
936
936
  }) => unknown, options?: {
937
- onResult?: (context: ContextType<Bot, "chosen_inline_result"> & Derives["global"] & Derives["chosen_inline_result"] & {
937
+ onResult?: (context: ContextType<Bot, "chosen_inline_result"> & {
938
938
  args: RegExpMatchArray | null;
939
939
  }) => unknown;
940
940
  }): this;
@@ -945,7 +945,7 @@ declare class Bot<Errors extends ErrorDefinitions = {}, Derives extends DeriveDe
945
945
  * if (context.args) await context.send(`Params ${context.args[1]}`);
946
946
  * });
947
947
  */
948
- 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 & {
949
949
  args: RegExpMatchArray | null;
950
950
  }) => unknown): this;
951
951
  /**
@@ -955,7 +955,7 @@ declare class Bot<Errors extends ErrorDefinitions = {}, Derives extends DeriveDe
955
955
  * return context.send(`You message is /start ${context.args}`);
956
956
  * });
957
957
  */
958
- command(command: string, handler: (context: ContextType<typeof this, "message"> & Derives["global"] & Derives["message"] & {
958
+ command(command: string, handler: (context: ContextType<typeof this, "message"> & {
959
959
  args: string | null;
960
960
  }) => unknown, options?: Omit<SetMyCommandsParams, "commands"> & Omit<TelegramBotCommand, "command">): this;
961
961
  /** Currently not isolated!!! */
package/dist/index.js CHANGED
@@ -9,7 +9,6 @@ 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';
13
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';
14
13
  import { Composer as Composer$1, noopNext } from 'middleware-io';
15
14
  export * from '@gramio/keyboards';
@@ -81,44 +80,6 @@ class Composer {
81
80
  }
82
81
  }
83
82
 
84
- var __create$1 = Object.create;
85
- var __defProp$1 = Object.defineProperty;
86
- var __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor;
87
- var __knownSymbol$1 = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
88
- var __typeError$1 = (msg) => {
89
- throw TypeError(msg);
90
- };
91
- var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
92
- var __name$1 = (target, value) => __defProp$1(target, "name", { value, configurable: true });
93
- var __decoratorStart$1 = (base) => [, , , __create$1(null)];
94
- var __decoratorStrings$1 = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"];
95
- var __expectFn$1 = (fn) => fn !== void 0 && typeof fn !== "function" ? __typeError$1("Function expected") : fn;
96
- 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)) });
97
- var __decoratorMetadata$1 = (array, target) => __defNormalProp$1(target, __knownSymbol$1("metadata"), array[3]);
98
- var __runInitializers$1 = (array, flags, self, value) => {
99
- for (var i = 0, fns = array[flags >> 1], n = fns && fns.length; i < n; i++) fns[i].call(self) ;
100
- return value;
101
- };
102
- var __decorateElement$1 = (array, flags, name, decorators, target, extra) => {
103
- var it, done, ctx, k = flags & 7, p = false;
104
- var j = 0;
105
- var extraInitializers = array[j] || (array[j] = []);
106
- var desc = k && ((target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc$1(target , name));
107
- __name$1(target, name);
108
- for (var i = decorators.length - 1; i >= 0; i--) {
109
- ctx = __decoratorContext$1(k, name, done = {}, array[3], extraInitializers);
110
- it = (0, decorators[i])(target, ctx), done._ = 1;
111
- __expectFn$1(it) && (target = it);
112
- }
113
- return __decoratorMetadata$1(array, target), desc && __defProp$1(target, name, desc), p ? k ^ 4 ? extra : desc : target;
114
- };
115
- var _Plugin_decorators, _init$1;
116
- _Plugin_decorators = [Inspectable({
117
- serialize: (plugin) => ({
118
- name: plugin._.name,
119
- dependencies: plugin._.dependencies
120
- })
121
- })];
122
83
  class Plugin {
123
84
  /**
124
85
  * @internal
@@ -293,9 +254,6 @@ class Plugin {
293
254
  return this;
294
255
  }
295
256
  }
296
- _init$1 = __decoratorStart$1();
297
- Plugin = __decorateElement$1(_init$1, 0, "Plugin", _Plugin_decorators, Plugin);
298
- __runInitializers$1(_init$1, 1, Plugin);
299
257
 
300
258
  class UpdateQueue {
301
259
  updateQueue = [];
@@ -350,12 +308,12 @@ class Updates {
350
308
  this.composer = new Composer(onError);
351
309
  this.queue = new UpdateQueue(this.handleUpdate.bind(this));
352
310
  }
353
- async handleUpdate(data) {
311
+ async handleUpdate(data, mode = "wait") {
354
312
  const updateType = Object.keys(data).at(1);
355
313
  const UpdateContext = contextsMappings[updateType];
356
314
  if (!UpdateContext) throw new Error(updateType);
357
315
  const updatePayload = data[updateType];
358
- if (!updatePayload) throw new Error("");
316
+ if (!updatePayload) throw new Error("Unsupported event??");
359
317
  try {
360
318
  let context = new UpdateContext({
361
319
  bot: this.bot,
@@ -377,7 +335,7 @@ class Updates {
377
335
  updateId: data.update_id
378
336
  });
379
337
  }
380
- return this.composer.composeWait(context);
338
+ return mode === "wait" ? this.composer.composeWait(context) : this.composer.compose(context);
381
339
  } catch (error) {
382
340
  throw new Error(`[UPDATES] Update type ${updateType} not supported.`);
383
341
  }
@@ -415,43 +373,8 @@ class Updates {
415
373
  }
416
374
  }
417
375
 
418
- var __create = Object.create;
419
- var __defProp = Object.defineProperty;
420
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
421
- var __knownSymbol = (name2, symbol) => (symbol = Symbol[name2]) ? symbol : Symbol.for("Symbol." + name2);
422
- var __typeError = (msg) => {
423
- throw TypeError(msg);
424
- };
425
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
426
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
427
- var __decoratorStart = (base) => [, , , __create(null)];
428
- var __decoratorStrings = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"];
429
- var __expectFn = (fn) => fn !== void 0 && typeof fn !== "function" ? __typeError("Function expected") : fn;
430
- var __decoratorContext = (kind, name2, done, metadata, fns) => ({ kind: __decoratorStrings[kind], name: name2, metadata, addInitializer: (fn) => done._ ? __typeError("Already initialized") : fns.push(__expectFn(fn || null)) });
431
- var __decoratorMetadata = (array, target) => __defNormalProp(target, __knownSymbol("metadata"), array[3]);
432
- var __runInitializers = (array, flags, self, value) => {
433
- for (var i = 0, fns = array[flags >> 1], n = fns && fns.length; i < n; i++) fns[i].call(self) ;
434
- return value;
435
- };
436
- var __decorateElement = (array, flags, name2, decorators, target, extra) => {
437
- var it, done, ctx, k = flags & 7, p = false;
438
- var j = 0;
439
- var extraInitializers = array[j] || (array[j] = []);
440
- var desc = k && ((target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc(target , name2));
441
- __name(target, name2);
442
- for (var i = decorators.length - 1; i >= 0; i--) {
443
- ctx = __decoratorContext(k, name2, done = {}, array[3], extraInitializers);
444
- it = (0, decorators[i])(target, ctx), done._ = 1;
445
- __expectFn(it) && (target = it);
446
- }
447
- return __decoratorMetadata(array, target), desc && __defProp(target, name2, desc), p ? k ^ 4 ? extra : desc : target;
448
- };
449
- var _Bot_decorators, _init;
450
376
  const $debugger = debug("gramio");
451
377
  const debug$api = $debugger.extend("api");
452
- _Bot_decorators = [Inspectable({
453
- serialize: () => ({})
454
- })];
455
378
  class Bot {
456
379
  /** @deprecated use `~` instead*/
457
380
  _ = {
@@ -1144,9 +1067,6 @@ class Bot {
1144
1067
  });
1145
1068
  }
1146
1069
  }
1147
- _init = __decoratorStart();
1148
- Bot = __decorateElement(_init, 0, "Bot", _Bot_decorators, Bot);
1149
- __runInitializers(_init, 1, Bot);
1150
1070
 
1151
1071
  const SECRET_TOKEN_HEADER = "X-Telegram-Bot-Api-Secret-Token";
1152
1072
  const WRONG_TOKEN_ERROR = "secret token is invalid";
package/dist/utils.d.cts CHANGED
@@ -3,6 +3,6 @@
3
3
  *
4
4
  * Pack of useful utilities for Telegram Bot API and GramIO
5
5
  */
6
- declare function withRetries<Result extends Promise<unknown>>(resultPromise: () => Result): Promise<Result>;
6
+ declare function withRetries<Result>(resultPromise: () => Promise<Result>): Promise<Result>;
7
7
 
8
8
  export { withRetries };
package/dist/utils.d.ts CHANGED
@@ -3,6 +3,6 @@
3
3
  *
4
4
  * Pack of useful utilities for Telegram Bot API and GramIO
5
5
  */
6
- declare function withRetries<Result extends Promise<unknown>>(resultPromise: () => Result): Promise<Result>;
6
+ declare function withRetries<Result>(resultPromise: () => Promise<Result>): Promise<Result>;
7
7
 
8
8
  export { withRetries };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "gramio",
3
3
  "type": "module",
4
- "version": "0.2.6",
4
+ "version": "0.3.1",
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",
@@ -37,7 +37,12 @@
37
37
  "types",
38
38
  "client",
39
39
  "webhook",
40
- "long-polling"
40
+ "long-polling",
41
+ "files",
42
+ "plugins",
43
+ "format",
44
+ "contexts",
45
+ "files"
41
46
  ],
42
47
  "scripts": {
43
48
  "type": "tsc --noEmit",
@@ -51,20 +56,20 @@
51
56
  "license": "MIT",
52
57
  "devDependencies": {
53
58
  "@biomejs/biome": "1.9.4",
54
- "@types/bun": "^1.2.8",
59
+ "@types/bun": "^1.2.10",
55
60
  "@types/debug": "^4.1.12",
61
+ "expect-type": "^1.2.1",
56
62
  "pkgroll": "^2.12.1",
57
63
  "typescript": "^5.8.3"
58
64
  },
59
65
  "dependencies": {
60
66
  "@gramio/callback-data": "^0.0.3",
61
- "@gramio/contexts": "^0.1.5",
62
- "@gramio/files": "^0.2.0",
63
- "@gramio/format": "^0.1.5",
64
- "@gramio/keyboards": "^1.1.0",
65
- "@gramio/types": "^8.3.3",
67
+ "@gramio/contexts": "^0.2.5",
68
+ "@gramio/files": "^0.3.0",
69
+ "@gramio/format": "^0.2.0",
70
+ "@gramio/keyboards": "^1.2.1",
71
+ "@gramio/types": "^9.0.1",
66
72
  "debug": "^4.4.0",
67
- "inspectable": "^3.0.2",
68
73
  "middleware-io": "^2.8.1"
69
74
  },
70
75
  "files": ["dist"]