gramio 0.8.0 → 0.8.3

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/dist/index.cjs CHANGED
@@ -348,6 +348,10 @@ if (typeof Composer.prototype.registeredEvents !== "function") {
348
348
  {
349
349
  const originalExtend = Composer.prototype.extend;
350
350
  Composer.prototype.extend = function(other) {
351
+ if ("_" in other && !(other instanceof Promise)) {
352
+ if (!this["~"].__plugins) this["~"].__plugins = [];
353
+ this["~"].__plugins.push(other);
354
+ }
351
355
  const result = originalExtend.call(this, other);
352
356
  if (other["~"]?.commandsMeta) {
353
357
  if (!this["~"].commandsMeta) {
@@ -357,6 +361,10 @@ if (typeof Composer.prototype.registeredEvents !== "function") {
357
361
  this["~"].commandsMeta.set(cmd, meta);
358
362
  }
359
363
  }
364
+ if (other["~"]?.__plugins) {
365
+ if (!this["~"].__plugins) this["~"].__plugins = [];
366
+ this["~"].__plugins.push(...other["~"].__plugins);
367
+ }
360
368
  return result;
361
369
  };
362
370
  }
@@ -575,10 +583,39 @@ class Plugin {
575
583
  extend(pluginOrComposer) {
576
584
  if ("compose" in pluginOrComposer && "run" in pluginOrComposer && !("_" in pluginOrComposer)) {
577
585
  this._.composer.extend(pluginOrComposer);
586
+ return this;
587
+ }
588
+ const plugin = pluginOrComposer;
589
+ if (plugin._.composer["~"].middlewares.length) {
590
+ plugin._.composer.as("scoped");
591
+ this._.composer.extend(plugin._.composer);
592
+ } else if (Object.keys(plugin._.composer["~"].macros).length) {
593
+ Object.assign(this._.composer["~"].macros, plugin._.composer["~"].macros);
594
+ }
595
+ for (const [key, value] of Object.entries(plugin._.errorsDefinitions)) {
596
+ this._.errorsDefinitions[key] = value;
597
+ this._.composer["~"].errorsDefinitions[key] = value;
598
+ }
599
+ Object.assign(this._.decorators, plugin._.decorators);
600
+ this._.preRequests.push(...plugin._.preRequests);
601
+ this._.onResponses.push(...plugin._.onResponses);
602
+ this._.onResponseErrors.push(...plugin._.onResponseErrors);
603
+ this._.onApiCalls.push(...plugin._.onApiCalls);
604
+ this._.onErrors.push(...plugin._.onErrors);
605
+ this._.onStarts.push(...plugin._.onStarts);
606
+ this._.onStops.push(...plugin._.onStops);
607
+ this._.groups.push(...plugin._.groups);
608
+ for (const dep of plugin._.dependencies) {
609
+ if (!this._.dependencies.includes(dep)) {
610
+ this._.dependencies.push(dep);
611
+ }
578
612
  }
579
613
  return this;
580
614
  }
581
615
  }
616
+ for (const [name, fn] of Object.entries(methods)) {
617
+ Plugin.prototype[name] = fn;
618
+ }
582
619
 
583
620
  class Updates {
584
621
  bot;
@@ -1093,6 +1130,45 @@ class Bot {
1093
1130
  extend(pluginOrComposer) {
1094
1131
  if ("compose" in pluginOrComposer && "run" in pluginOrComposer && !("_" in pluginOrComposer)) {
1095
1132
  this.updates.composer.extend(pluginOrComposer);
1133
+ const trackedPlugins = pluginOrComposer["~"]?.__plugins;
1134
+ if (trackedPlugins) {
1135
+ for (const p of trackedPlugins) {
1136
+ this.decorate(p._.decorators);
1137
+ for (const value of p._.preRequests) {
1138
+ const [preRequest, updateName] = value;
1139
+ if (!updateName) this.preRequest(preRequest);
1140
+ else this.preRequest(updateName, preRequest);
1141
+ }
1142
+ for (const value of p._.onResponses) {
1143
+ const [onResponse, updateName] = value;
1144
+ if (!updateName) this.onResponse(onResponse);
1145
+ else this.onResponse(updateName, onResponse);
1146
+ }
1147
+ for (const value of p._.onResponseErrors) {
1148
+ const [onResponseError, updateName] = value;
1149
+ if (!updateName) this.onResponseError(onResponseError);
1150
+ else this.onResponseError(updateName, onResponseError);
1151
+ }
1152
+ for (const value of p._.onApiCalls) {
1153
+ const [onApiCall, methods] = value;
1154
+ if (!methods) this.onApiCall(onApiCall);
1155
+ else this.onApiCall(methods, onApiCall);
1156
+ }
1157
+ for (const handler of p._.groups) {
1158
+ this.group(handler);
1159
+ }
1160
+ for (const value of p._.onErrors) {
1161
+ this.onError(value);
1162
+ }
1163
+ for (const value of p._.onStarts) {
1164
+ this.onStart(value);
1165
+ }
1166
+ for (const value of p._.onStops) {
1167
+ this.onStop(value);
1168
+ }
1169
+ this.dependencies.push(p._.name);
1170
+ }
1171
+ }
1096
1172
  return this;
1097
1173
  }
1098
1174
  const plugin = pluginOrComposer;
@@ -1813,6 +1889,7 @@ exports.Composer = Composer;
1813
1889
  exports.OPT_IN_TYPES = OPT_IN_TYPES;
1814
1890
  exports.Plugin = Plugin;
1815
1891
  exports.Updates = Updates;
1892
+ exports._composerMethods = methods;
1816
1893
  exports.buildAllowedUpdates = buildAllowedUpdates;
1817
1894
  exports.detectOptInUpdates = detectOptInUpdates;
1818
1895
  exports.filters = filters;
package/dist/index.d.cts CHANGED
@@ -8,11 +8,11 @@ export * from '@gramio/files';
8
8
  export * from '@gramio/format';
9
9
  export * from '@gramio/keyboards';
10
10
  import * as _gramio_types from '@gramio/types';
11
- import { APIMethods, TelegramResponseParameters, TelegramAPIResponseError, TelegramReactionTypeEmojiEmoji, TelegramUser, APIMethodParams, APIMethodReturn, SetWebhookParams, TelegramUpdate, TelegramBotCommandScope, TelegramMessageEntity } from '@gramio/types';
11
+ import { APIMethods, TelegramResponseParameters, TelegramAPIResponseError, TelegramReactionTypeEmojiEmoji, TelegramUser, APIMethodParams, APIMethodReturn, TelegramBotCommandScope, SetWebhookParams, TelegramUpdate, TelegramMessageEntity } from '@gramio/types';
12
12
  export * from '@gramio/types';
13
13
  import * as _gramio_composer from '@gramio/composer';
14
- import { ComposerLike, MacroDefinitions, CommandMeta, EventContextOf, EventComposer, MacroDef, Next, EventQueue, HandlerOptions, DeriveFromOptions } from '@gramio/composer';
15
- export { CommandMeta, ContextCallback, DeriveFromOptions, EventComposer, EventQueue, HandlerOptions, MacroDef, MacroDefinitions, MacroDeriveType, MacroHooks, MacroOptionType, Middleware, Next, ScopeShorthand, WithCtx, buildFromOptions, compose, noopNext, skip, stop } from '@gramio/composer';
14
+ import { ComposerLike, MacroDefinitions, EventContextOf, EventComposer, MacroDef, Next, EventQueue, HandlerOptions, DeriveFromOptions } from '@gramio/composer';
15
+ export { ContextCallback, DeriveFromOptions, EventComposer, EventQueue, HandlerOptions, MacroDef, MacroDefinitions, MacroDeriveType, MacroHooks, MacroOptionType, Middleware, Next, WithCtx, buildFromOptions, compose, noopNext, skip, stop } from '@gramio/composer';
16
16
 
17
17
  /**
18
18
  * Telegram Bot API top-level update type name.
@@ -174,16 +174,50 @@ type Ctx<K extends keyof ContextsMapping<AnyBot>> = InstanceType<ContextsMapping
174
174
  type GramIOLike<T> = ComposerLike<T> & {
175
175
  "~": {
176
176
  macros: MacroDefinitions;
177
- commandsMeta: Map<string, CommandMeta>;
177
+ commandsMeta?: Map<string, unknown>;
178
178
  Derives?: Record<string, object>;
179
179
  };
180
180
  chosenInlineResult(trigger: any, handler: any, macroOptions?: any): T;
181
181
  };
182
+ declare const methods: {
183
+ reaction<TThis extends GramIOLike<TThis>>(this: TThis, trigger: MaybeArray<TelegramReactionTypeEmojiEmoji>, handler: (context: Ctx<"message_reaction"> & EventContextOf<TThis, "message_reaction">) => unknown, macroOptions?: Record<string, unknown>): TThis;
184
+ callbackQuery<TThis extends GramIOLike<TThis>, Trigger extends CallbackData | string | RegExp>(this: TThis, trigger: Trigger, handler: (context: Ctx<"callback_query"> & {
185
+ queryData: Trigger extends CallbackData ? ReturnType<Trigger["unpack"]> : Trigger extends RegExp ? RegExpMatchArray : never;
186
+ } & EventContextOf<TThis, "callback_query">) => unknown, macroOptions?: Record<string, unknown>): TThis;
187
+ chosenInlineResult<TThis extends GramIOLike<TThis>>(this: TThis, trigger: RegExp | string | ((context: Ctx<"chosen_inline_result">) => boolean), handler: (context: Ctx<"chosen_inline_result"> & {
188
+ args: RegExpMatchArray | null;
189
+ } & EventContextOf<TThis, "chosen_inline_result">) => unknown, macroOptions?: Record<string, unknown>): TThis;
190
+ inlineQuery<TThis extends GramIOLike<TThis>>(this: TThis, trigger: RegExp | string | ((context: Ctx<"inline_query">) => boolean), handler: (context: Ctx<"inline_query"> & {
191
+ args: RegExpMatchArray | null;
192
+ } & EventContextOf<TThis, "inline_query">) => unknown, options?: {
193
+ onResult?: (context: Ctx<"chosen_inline_result"> & {
194
+ args: RegExpMatchArray | null;
195
+ } & EventContextOf<TThis, "chosen_inline_result">) => unknown;
196
+ } & Record<string, unknown>): TThis;
197
+ hears<TThis extends GramIOLike<TThis>>(this: TThis, trigger: RegExp | MaybeArray<string> | ((context: Ctx<"message">) => boolean), handler: (context: Ctx<"message"> & {
198
+ args: RegExpMatchArray | null;
199
+ } & EventContextOf<TThis, "message">) => unknown, macroOptions?: Record<string, unknown>): TThis;
200
+ command<TThis extends GramIOLike<TThis>>(this: TThis, command: MaybeArray<string>, handlerOrMeta: ((context: Ctx<"message"> & {
201
+ args: string | null;
202
+ } & EventContextOf<TThis, "message">) => unknown) | CommandMeta, handlerOrOptions?: ((context: Ctx<"message"> & {
203
+ args: string | null;
204
+ } & EventContextOf<TThis, "message">) => unknown) | Record<string, unknown>, macroOptions?: Record<string, unknown>): TThis;
205
+ startParameter<TThis extends GramIOLike<TThis>>(this: TThis, parameter: RegExp | MaybeArray<string>, handler: Handler<Ctx<"message"> & {
206
+ rawStartPayload: string;
207
+ } & EventContextOf<TThis, "message">>, macroOptions?: Record<string, unknown>): TThis;
208
+ };
182
209
  /** Teach EventComposer about GramIO-specific overloads */
183
210
  declare module "@gramio/composer" {
184
211
  interface EventComposer<TBase, TEventMap, TIn, TOut, TExposed, TDerives, TMethods, TMacros> {
185
212
  extend<P extends AnyPlugin>(plugin: P): EventComposer<TBase, TEventMap, TIn, TOut & P["_"]["Derives"]["global"], TExposed, TDerives & Omit<P["_"]["Derives"], "global">, TMethods, TMacros & P["_"]["Macros"]>;
186
213
  registeredEvents(): Set<string>;
214
+ callbackQuery: (typeof methods)["callbackQuery"];
215
+ command: (typeof methods)["command"];
216
+ hears: (typeof methods)["hears"];
217
+ reaction: (typeof methods)["reaction"];
218
+ inlineQuery: (typeof methods)["inlineQuery"];
219
+ chosenInlineResult: (typeof methods)["chosenInlineResult"];
220
+ startParameter: (typeof methods)["startParameter"];
187
221
  }
188
222
  }
189
223
  declare const Composer: _gramio_composer.EventComposerConstructor<Context<AnyBot>, TelegramEventMap, {
@@ -348,7 +382,7 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
348
382
  reaction<TThis extends _gramio_composer.ComposerLike<TThis> & {
349
383
  "~": {
350
384
  macros: MacroDefinitions;
351
- commandsMeta: Map<string, _gramio_composer.CommandMeta>;
385
+ commandsMeta?: Map<string, unknown>;
352
386
  Derives?: Record<string, object>;
353
387
  };
354
388
  chosenInlineResult(trigger: any, handler: any, macroOptions?: any): TThis;
@@ -356,7 +390,7 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
356
390
  callbackQuery<TThis extends _gramio_composer.ComposerLike<TThis> & {
357
391
  "~": {
358
392
  macros: MacroDefinitions;
359
- commandsMeta: Map<string, _gramio_composer.CommandMeta>;
393
+ commandsMeta?: Map<string, unknown>;
360
394
  Derives?: Record<string, object>;
361
395
  };
362
396
  chosenInlineResult(trigger: any, handler: any, macroOptions?: any): TThis;
@@ -366,7 +400,7 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
366
400
  chosenInlineResult<TThis extends _gramio_composer.ComposerLike<TThis> & {
367
401
  "~": {
368
402
  macros: MacroDefinitions;
369
- commandsMeta: Map<string, _gramio_composer.CommandMeta>;
403
+ commandsMeta?: Map<string, unknown>;
370
404
  Derives?: Record<string, object>;
371
405
  };
372
406
  chosenInlineResult(trigger: any, handler: any, macroOptions?: any): TThis;
@@ -376,7 +410,7 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
376
410
  inlineQuery<TThis extends _gramio_composer.ComposerLike<TThis> & {
377
411
  "~": {
378
412
  macros: MacroDefinitions;
379
- commandsMeta: Map<string, _gramio_composer.CommandMeta>;
413
+ commandsMeta?: Map<string, unknown>;
380
414
  Derives?: Record<string, object>;
381
415
  };
382
416
  chosenInlineResult(trigger: any, handler: any, macroOptions?: any): TThis;
@@ -390,7 +424,7 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
390
424
  hears<TThis extends _gramio_composer.ComposerLike<TThis> & {
391
425
  "~": {
392
426
  macros: MacroDefinitions;
393
- commandsMeta: Map<string, _gramio_composer.CommandMeta>;
427
+ commandsMeta?: Map<string, unknown>;
394
428
  Derives?: Record<string, object>;
395
429
  };
396
430
  chosenInlineResult(trigger: any, handler: any, macroOptions?: any): TThis;
@@ -400,19 +434,19 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
400
434
  command<TThis extends _gramio_composer.ComposerLike<TThis> & {
401
435
  "~": {
402
436
  macros: MacroDefinitions;
403
- commandsMeta: Map<string, _gramio_composer.CommandMeta>;
437
+ commandsMeta?: Map<string, unknown>;
404
438
  Derives?: Record<string, object>;
405
439
  };
406
440
  chosenInlineResult(trigger: any, handler: any, macroOptions?: any): TThis;
407
441
  }>(this: TThis, command: MaybeArray<string>, handlerOrMeta: ((context: (_gramio_contexts.MessageContext<AnyBot> & _gramio_contexts.Require<_gramio_contexts.MessageContext<AnyBot>, "from">) & {
408
442
  args: string | null;
409
- } & _gramio_composer.EventContextOf<TThis, "message">) => unknown) | _gramio_composer.CommandMeta, handlerOrOptions?: ((context: (_gramio_contexts.MessageContext<AnyBot> & _gramio_contexts.Require<_gramio_contexts.MessageContext<AnyBot>, "from">) & {
443
+ } & _gramio_composer.EventContextOf<TThis, "message">) => unknown) | CommandMeta, handlerOrOptions?: ((context: (_gramio_contexts.MessageContext<AnyBot> & _gramio_contexts.Require<_gramio_contexts.MessageContext<AnyBot>, "from">) & {
410
444
  args: string | null;
411
445
  } & _gramio_composer.EventContextOf<TThis, "message">) => unknown) | Record<string, unknown>, macroOptions?: Record<string, unknown>): TThis;
412
446
  startParameter<TThis extends _gramio_composer.ComposerLike<TThis> & {
413
447
  "~": {
414
448
  macros: MacroDefinitions;
415
- commandsMeta: Map<string, _gramio_composer.CommandMeta>;
449
+ commandsMeta?: Map<string, unknown>;
416
450
  Derives?: Record<string, object>;
417
451
  };
418
452
  chosenInlineResult(trigger: any, handler: any, macroOptions?: any): TThis;
@@ -423,7 +457,7 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
423
457
  reaction<TThis extends _gramio_composer.ComposerLike<TThis> & {
424
458
  "~": {
425
459
  macros: MacroDefinitions;
426
- commandsMeta: Map<string, _gramio_composer.CommandMeta>;
460
+ commandsMeta?: Map<string, unknown>;
427
461
  Derives?: Record<string, object>;
428
462
  };
429
463
  chosenInlineResult(trigger: any, handler: any, macroOptions?: any): TThis;
@@ -431,7 +465,7 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
431
465
  callbackQuery<TThis extends _gramio_composer.ComposerLike<TThis> & {
432
466
  "~": {
433
467
  macros: MacroDefinitions;
434
- commandsMeta: Map<string, _gramio_composer.CommandMeta>;
468
+ commandsMeta?: Map<string, unknown>;
435
469
  Derives?: Record<string, object>;
436
470
  };
437
471
  chosenInlineResult(trigger: any, handler: any, macroOptions?: any): TThis;
@@ -441,7 +475,7 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
441
475
  chosenInlineResult<TThis extends _gramio_composer.ComposerLike<TThis> & {
442
476
  "~": {
443
477
  macros: MacroDefinitions;
444
- commandsMeta: Map<string, _gramio_composer.CommandMeta>;
478
+ commandsMeta?: Map<string, unknown>;
445
479
  Derives?: Record<string, object>;
446
480
  };
447
481
  chosenInlineResult(trigger: any, handler: any, macroOptions?: any): TThis;
@@ -451,7 +485,7 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
451
485
  inlineQuery<TThis extends _gramio_composer.ComposerLike<TThis> & {
452
486
  "~": {
453
487
  macros: MacroDefinitions;
454
- commandsMeta: Map<string, _gramio_composer.CommandMeta>;
488
+ commandsMeta?: Map<string, unknown>;
455
489
  Derives?: Record<string, object>;
456
490
  };
457
491
  chosenInlineResult(trigger: any, handler: any, macroOptions?: any): TThis;
@@ -465,7 +499,7 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
465
499
  hears<TThis extends _gramio_composer.ComposerLike<TThis> & {
466
500
  "~": {
467
501
  macros: MacroDefinitions;
468
- commandsMeta: Map<string, _gramio_composer.CommandMeta>;
502
+ commandsMeta?: Map<string, unknown>;
469
503
  Derives?: Record<string, object>;
470
504
  };
471
505
  chosenInlineResult(trigger: any, handler: any, macroOptions?: any): TThis;
@@ -475,19 +509,19 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
475
509
  command<TThis extends _gramio_composer.ComposerLike<TThis> & {
476
510
  "~": {
477
511
  macros: MacroDefinitions;
478
- commandsMeta: Map<string, _gramio_composer.CommandMeta>;
512
+ commandsMeta?: Map<string, unknown>;
479
513
  Derives?: Record<string, object>;
480
514
  };
481
515
  chosenInlineResult(trigger: any, handler: any, macroOptions?: any): TThis;
482
516
  }>(this: TThis, command: MaybeArray<string>, handlerOrMeta: ((context: (_gramio_contexts.MessageContext<AnyBot> & _gramio_contexts.Require<_gramio_contexts.MessageContext<AnyBot>, "from">) & {
483
517
  args: string | null;
484
- } & _gramio_composer.EventContextOf<TThis, "message">) => unknown) | _gramio_composer.CommandMeta, handlerOrOptions?: ((context: (_gramio_contexts.MessageContext<AnyBot> & _gramio_contexts.Require<_gramio_contexts.MessageContext<AnyBot>, "from">) & {
518
+ } & _gramio_composer.EventContextOf<TThis, "message">) => unknown) | CommandMeta, handlerOrOptions?: ((context: (_gramio_contexts.MessageContext<AnyBot> & _gramio_contexts.Require<_gramio_contexts.MessageContext<AnyBot>, "from">) & {
485
519
  args: string | null;
486
520
  } & _gramio_composer.EventContextOf<TThis, "message">) => unknown) | Record<string, unknown>, macroOptions?: Record<string, unknown>): TThis;
487
521
  startParameter<TThis extends _gramio_composer.ComposerLike<TThis> & {
488
522
  "~": {
489
523
  macros: MacroDefinitions;
490
- commandsMeta: Map<string, _gramio_composer.CommandMeta>;
524
+ commandsMeta?: Map<string, unknown>;
491
525
  Derives?: Record<string, object>;
492
526
  };
493
527
  chosenInlineResult(trigger: any, handler: any, macroOptions?: any): TThis;
@@ -523,7 +557,10 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
523
557
  decorators: Record<string, unknown>;
524
558
  };
525
559
  /** Expose composer internals so `composer.extend(plugin)` works via duck-typing */
526
- get "~"(): InstanceType<typeof Composer>["~"];
560
+ get "~"(): Omit<InstanceType<typeof Composer>["~"], "Out" | "Derives"> & {
561
+ Out: Derives["global"];
562
+ Derives: Omit<Derives, "global">;
563
+ };
527
564
  /** Create new Plugin. Please provide `name` */
528
565
  constructor(name: string, { dependencies }?: {
529
566
  dependencies?: string[];
@@ -695,9 +732,24 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
695
732
  extend<UExposed extends object, UDerives extends Record<string, object>>(composer: EventComposer<any, any, any, any, UExposed, UDerives>): Plugin<Errors, Derives & {
696
733
  global: UExposed;
697
734
  } & UDerives>;
698
- /**
699
- * ! ** At the moment, it can only pick up types** */
700
- extend<NewPlugin extends AnyPlugin>(plugin: MaybePromise<NewPlugin>): Plugin<Errors & NewPlugin["_"]["Errors"], Derives & NewPlugin["_"]["Derives"]>;
735
+ /** Extend plugin with another Plugin (merges middleware, hooks, decorators, error definitions, groups, and dependencies) */
736
+ extend<NewPlugin extends AnyPlugin>(plugin: MaybePromise<NewPlugin>): Plugin<Errors & NewPlugin["_"]["Errors"], Derives & NewPlugin["_"]["Derives"], Macros & NewPlugin["_"]["Macros"]>;
737
+ }
738
+ interface Plugin<Errors, Derives, Macros> {
739
+ /** Register callback query handler */
740
+ callbackQuery: (typeof methods)["callbackQuery"];
741
+ /** Register command handler */
742
+ command: (typeof methods)["command"];
743
+ /** Register text/caption pattern handler */
744
+ hears: (typeof methods)["hears"];
745
+ /** Register reaction handler */
746
+ reaction: (typeof methods)["reaction"];
747
+ /** Register inline query handler */
748
+ inlineQuery: (typeof methods)["inlineQuery"];
749
+ /** Register chosen inline result handler */
750
+ chosenInlineResult: (typeof methods)["chosenInlineResult"];
751
+ /** Register deep-link parameter handler */
752
+ startParameter: (typeof methods)["startParameter"];
701
753
  }
702
754
 
703
755
  /** Bot options that you can provide to {@link Bot} constructor */
@@ -1010,6 +1062,22 @@ interface PollingStartOptions {
1010
1062
  dropPendingUpdates?: boolean;
1011
1063
  deleteWebhookOnConflict?: boolean;
1012
1064
  }
1065
+ /** Shorthand strings for common BotCommandScope types */
1066
+ type ScopeShorthand = "default" | "all_private_chats" | "all_group_chats" | "all_chat_administrators";
1067
+ /**
1068
+ * Metadata for a bot command, used by `syncCommands()` to push
1069
+ * descriptions, localized names, and visibility scopes to the Telegram API.
1070
+ */
1071
+ interface CommandMeta {
1072
+ /** Command description shown in the Telegram menu (1-256 chars) */
1073
+ description: string;
1074
+ /** Localized descriptions keyed by IETF language tag */
1075
+ locales?: Record<string, string>;
1076
+ /** Where this command is visible. Default: `["default"]` */
1077
+ scopes?: (TelegramBotCommandScope | ScopeShorthand)[];
1078
+ /** Exclude this command from `syncCommands()`. The handler still works. @default false */
1079
+ hide?: boolean;
1080
+ }
1013
1081
  /** Minimal key-value storage interface compatible with `@gramio/storage` */
1014
1082
  interface SyncStorage {
1015
1083
  get(key: string): string | undefined | Promise<string | undefined>;
@@ -1487,7 +1555,7 @@ declare class Bot<Errors extends ErrorDefinitions = {}, Derives extends DeriveDe
1487
1555
  command<TOptions extends HandlerOptions<ContextType<typeof this, "message">, Macros> = {}>(command: MaybeArray<string>, handler: (context: ContextType<typeof this, "message"> & {
1488
1556
  args: string | null;
1489
1557
  } & DeriveFromOptions<Macros, TOptions>) => unknown, options?: TOptions): typeof this;
1490
- command<TOptions extends HandlerOptions<ContextType<typeof this, "message">, Macros> = {}>(command: MaybeArray<string>, meta: CommandMeta<TelegramBotCommandScope>, handler: (context: ContextType<typeof this, "message"> & {
1558
+ command<TOptions extends HandlerOptions<ContextType<typeof this, "message">, Macros> = {}>(command: MaybeArray<string>, meta: CommandMeta, handler: (context: ContextType<typeof this, "message"> & {
1491
1559
  args: string | null;
1492
1560
  } & DeriveFromOptions<Macros, TOptions>) => unknown, options?: TOptions): typeof this;
1493
1561
  /**
@@ -1928,5 +1996,5 @@ declare function webhookHandler<Framework extends keyof typeof frameworks>(bot:
1928
1996
  response: () => any;
1929
1997
  } ? (...args: Parameters<(typeof frameworks)[Framework]>) => ReturnType<ReturnType<(typeof frameworks)[Framework]>["response"]> : (...args: Parameters<(typeof frameworks)[Framework]>) => void;
1930
1998
 
1931
- export { AllowedUpdatesFilter, Bot, Composer, ErrorKind, Hooks, OPT_IN_TYPES, Plugin, TelegramError, Updates, buildAllowedUpdates, detectOptInUpdates, filters, mapEventToAllowedUpdates, webhookHandler };
1932
- export type { AllowedUpdateName, AllowedUpdates, AnyBot, AnyPlugin, BotOptions, BotStartOptions, BotStartOptionsLongPolling, BotStartOptionsWebhook, CallbackQueryShorthandContext, DeriveDefinitions, ErrorDefinitions, Filter, Handler, MaybePromise, MaybeSuppressedParams, MaybeSuppressedReturn, PollingStartOptions, Suppress, SuppressedAPIMethodParams, SuppressedAPIMethodReturn, SuppressedAPIMethods, SyncCommandsOptions, SyncStorage, WebhookHandlerOptions, WebhookHandlerOptionsShouldWait, WebhookHandlers };
1999
+ export { AllowedUpdatesFilter, Bot, Composer, ErrorKind, Hooks, OPT_IN_TYPES, Plugin, TelegramError, Updates, methods as _composerMethods, buildAllowedUpdates, detectOptInUpdates, filters, mapEventToAllowedUpdates, webhookHandler };
2000
+ export type { AllowedUpdateName, AllowedUpdates, AnyBot, AnyPlugin, BotOptions, BotStartOptions, BotStartOptionsLongPolling, BotStartOptionsWebhook, CallbackQueryShorthandContext, CommandMeta, DeriveDefinitions, ErrorDefinitions, Filter, Handler, MaybePromise, MaybeSuppressedParams, MaybeSuppressedReturn, PollingStartOptions, ScopeShorthand, Suppress, SuppressedAPIMethodParams, SuppressedAPIMethodReturn, SuppressedAPIMethods, SyncCommandsOptions, SyncStorage, WebhookHandlerOptions, WebhookHandlerOptionsShouldWait, WebhookHandlers };
package/dist/index.d.ts CHANGED
@@ -8,11 +8,11 @@ export * from '@gramio/files';
8
8
  export * from '@gramio/format';
9
9
  export * from '@gramio/keyboards';
10
10
  import * as _gramio_types from '@gramio/types';
11
- import { APIMethods, TelegramResponseParameters, TelegramAPIResponseError, TelegramReactionTypeEmojiEmoji, TelegramUser, APIMethodParams, APIMethodReturn, SetWebhookParams, TelegramUpdate, TelegramBotCommandScope, TelegramMessageEntity } from '@gramio/types';
11
+ import { APIMethods, TelegramResponseParameters, TelegramAPIResponseError, TelegramReactionTypeEmojiEmoji, TelegramUser, APIMethodParams, APIMethodReturn, TelegramBotCommandScope, SetWebhookParams, TelegramUpdate, TelegramMessageEntity } from '@gramio/types';
12
12
  export * from '@gramio/types';
13
13
  import * as _gramio_composer from '@gramio/composer';
14
- import { ComposerLike, MacroDefinitions, CommandMeta, EventContextOf, EventComposer, MacroDef, Next, EventQueue, HandlerOptions, DeriveFromOptions } from '@gramio/composer';
15
- export { CommandMeta, ContextCallback, DeriveFromOptions, EventComposer, EventQueue, HandlerOptions, MacroDef, MacroDefinitions, MacroDeriveType, MacroHooks, MacroOptionType, Middleware, Next, ScopeShorthand, WithCtx, buildFromOptions, compose, noopNext, skip, stop } from '@gramio/composer';
14
+ import { ComposerLike, MacroDefinitions, EventContextOf, EventComposer, MacroDef, Next, EventQueue, HandlerOptions, DeriveFromOptions } from '@gramio/composer';
15
+ export { ContextCallback, DeriveFromOptions, EventComposer, EventQueue, HandlerOptions, MacroDef, MacroDefinitions, MacroDeriveType, MacroHooks, MacroOptionType, Middleware, Next, WithCtx, buildFromOptions, compose, noopNext, skip, stop } from '@gramio/composer';
16
16
 
17
17
  /**
18
18
  * Telegram Bot API top-level update type name.
@@ -174,16 +174,50 @@ type Ctx<K extends keyof ContextsMapping<AnyBot>> = InstanceType<ContextsMapping
174
174
  type GramIOLike<T> = ComposerLike<T> & {
175
175
  "~": {
176
176
  macros: MacroDefinitions;
177
- commandsMeta: Map<string, CommandMeta>;
177
+ commandsMeta?: Map<string, unknown>;
178
178
  Derives?: Record<string, object>;
179
179
  };
180
180
  chosenInlineResult(trigger: any, handler: any, macroOptions?: any): T;
181
181
  };
182
+ declare const methods: {
183
+ reaction<TThis extends GramIOLike<TThis>>(this: TThis, trigger: MaybeArray<TelegramReactionTypeEmojiEmoji>, handler: (context: Ctx<"message_reaction"> & EventContextOf<TThis, "message_reaction">) => unknown, macroOptions?: Record<string, unknown>): TThis;
184
+ callbackQuery<TThis extends GramIOLike<TThis>, Trigger extends CallbackData | string | RegExp>(this: TThis, trigger: Trigger, handler: (context: Ctx<"callback_query"> & {
185
+ queryData: Trigger extends CallbackData ? ReturnType<Trigger["unpack"]> : Trigger extends RegExp ? RegExpMatchArray : never;
186
+ } & EventContextOf<TThis, "callback_query">) => unknown, macroOptions?: Record<string, unknown>): TThis;
187
+ chosenInlineResult<TThis extends GramIOLike<TThis>>(this: TThis, trigger: RegExp | string | ((context: Ctx<"chosen_inline_result">) => boolean), handler: (context: Ctx<"chosen_inline_result"> & {
188
+ args: RegExpMatchArray | null;
189
+ } & EventContextOf<TThis, "chosen_inline_result">) => unknown, macroOptions?: Record<string, unknown>): TThis;
190
+ inlineQuery<TThis extends GramIOLike<TThis>>(this: TThis, trigger: RegExp | string | ((context: Ctx<"inline_query">) => boolean), handler: (context: Ctx<"inline_query"> & {
191
+ args: RegExpMatchArray | null;
192
+ } & EventContextOf<TThis, "inline_query">) => unknown, options?: {
193
+ onResult?: (context: Ctx<"chosen_inline_result"> & {
194
+ args: RegExpMatchArray | null;
195
+ } & EventContextOf<TThis, "chosen_inline_result">) => unknown;
196
+ } & Record<string, unknown>): TThis;
197
+ hears<TThis extends GramIOLike<TThis>>(this: TThis, trigger: RegExp | MaybeArray<string> | ((context: Ctx<"message">) => boolean), handler: (context: Ctx<"message"> & {
198
+ args: RegExpMatchArray | null;
199
+ } & EventContextOf<TThis, "message">) => unknown, macroOptions?: Record<string, unknown>): TThis;
200
+ command<TThis extends GramIOLike<TThis>>(this: TThis, command: MaybeArray<string>, handlerOrMeta: ((context: Ctx<"message"> & {
201
+ args: string | null;
202
+ } & EventContextOf<TThis, "message">) => unknown) | CommandMeta, handlerOrOptions?: ((context: Ctx<"message"> & {
203
+ args: string | null;
204
+ } & EventContextOf<TThis, "message">) => unknown) | Record<string, unknown>, macroOptions?: Record<string, unknown>): TThis;
205
+ startParameter<TThis extends GramIOLike<TThis>>(this: TThis, parameter: RegExp | MaybeArray<string>, handler: Handler<Ctx<"message"> & {
206
+ rawStartPayload: string;
207
+ } & EventContextOf<TThis, "message">>, macroOptions?: Record<string, unknown>): TThis;
208
+ };
182
209
  /** Teach EventComposer about GramIO-specific overloads */
183
210
  declare module "@gramio/composer" {
184
211
  interface EventComposer<TBase, TEventMap, TIn, TOut, TExposed, TDerives, TMethods, TMacros> {
185
212
  extend<P extends AnyPlugin>(plugin: P): EventComposer<TBase, TEventMap, TIn, TOut & P["_"]["Derives"]["global"], TExposed, TDerives & Omit<P["_"]["Derives"], "global">, TMethods, TMacros & P["_"]["Macros"]>;
186
213
  registeredEvents(): Set<string>;
214
+ callbackQuery: (typeof methods)["callbackQuery"];
215
+ command: (typeof methods)["command"];
216
+ hears: (typeof methods)["hears"];
217
+ reaction: (typeof methods)["reaction"];
218
+ inlineQuery: (typeof methods)["inlineQuery"];
219
+ chosenInlineResult: (typeof methods)["chosenInlineResult"];
220
+ startParameter: (typeof methods)["startParameter"];
187
221
  }
188
222
  }
189
223
  declare const Composer: _gramio_composer.EventComposerConstructor<Context<AnyBot>, TelegramEventMap, {
@@ -348,7 +382,7 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
348
382
  reaction<TThis extends _gramio_composer.ComposerLike<TThis> & {
349
383
  "~": {
350
384
  macros: MacroDefinitions;
351
- commandsMeta: Map<string, _gramio_composer.CommandMeta>;
385
+ commandsMeta?: Map<string, unknown>;
352
386
  Derives?: Record<string, object>;
353
387
  };
354
388
  chosenInlineResult(trigger: any, handler: any, macroOptions?: any): TThis;
@@ -356,7 +390,7 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
356
390
  callbackQuery<TThis extends _gramio_composer.ComposerLike<TThis> & {
357
391
  "~": {
358
392
  macros: MacroDefinitions;
359
- commandsMeta: Map<string, _gramio_composer.CommandMeta>;
393
+ commandsMeta?: Map<string, unknown>;
360
394
  Derives?: Record<string, object>;
361
395
  };
362
396
  chosenInlineResult(trigger: any, handler: any, macroOptions?: any): TThis;
@@ -366,7 +400,7 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
366
400
  chosenInlineResult<TThis extends _gramio_composer.ComposerLike<TThis> & {
367
401
  "~": {
368
402
  macros: MacroDefinitions;
369
- commandsMeta: Map<string, _gramio_composer.CommandMeta>;
403
+ commandsMeta?: Map<string, unknown>;
370
404
  Derives?: Record<string, object>;
371
405
  };
372
406
  chosenInlineResult(trigger: any, handler: any, macroOptions?: any): TThis;
@@ -376,7 +410,7 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
376
410
  inlineQuery<TThis extends _gramio_composer.ComposerLike<TThis> & {
377
411
  "~": {
378
412
  macros: MacroDefinitions;
379
- commandsMeta: Map<string, _gramio_composer.CommandMeta>;
413
+ commandsMeta?: Map<string, unknown>;
380
414
  Derives?: Record<string, object>;
381
415
  };
382
416
  chosenInlineResult(trigger: any, handler: any, macroOptions?: any): TThis;
@@ -390,7 +424,7 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
390
424
  hears<TThis extends _gramio_composer.ComposerLike<TThis> & {
391
425
  "~": {
392
426
  macros: MacroDefinitions;
393
- commandsMeta: Map<string, _gramio_composer.CommandMeta>;
427
+ commandsMeta?: Map<string, unknown>;
394
428
  Derives?: Record<string, object>;
395
429
  };
396
430
  chosenInlineResult(trigger: any, handler: any, macroOptions?: any): TThis;
@@ -400,19 +434,19 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
400
434
  command<TThis extends _gramio_composer.ComposerLike<TThis> & {
401
435
  "~": {
402
436
  macros: MacroDefinitions;
403
- commandsMeta: Map<string, _gramio_composer.CommandMeta>;
437
+ commandsMeta?: Map<string, unknown>;
404
438
  Derives?: Record<string, object>;
405
439
  };
406
440
  chosenInlineResult(trigger: any, handler: any, macroOptions?: any): TThis;
407
441
  }>(this: TThis, command: MaybeArray<string>, handlerOrMeta: ((context: (_gramio_contexts.MessageContext<AnyBot> & _gramio_contexts.Require<_gramio_contexts.MessageContext<AnyBot>, "from">) & {
408
442
  args: string | null;
409
- } & _gramio_composer.EventContextOf<TThis, "message">) => unknown) | _gramio_composer.CommandMeta, handlerOrOptions?: ((context: (_gramio_contexts.MessageContext<AnyBot> & _gramio_contexts.Require<_gramio_contexts.MessageContext<AnyBot>, "from">) & {
443
+ } & _gramio_composer.EventContextOf<TThis, "message">) => unknown) | CommandMeta, handlerOrOptions?: ((context: (_gramio_contexts.MessageContext<AnyBot> & _gramio_contexts.Require<_gramio_contexts.MessageContext<AnyBot>, "from">) & {
410
444
  args: string | null;
411
445
  } & _gramio_composer.EventContextOf<TThis, "message">) => unknown) | Record<string, unknown>, macroOptions?: Record<string, unknown>): TThis;
412
446
  startParameter<TThis extends _gramio_composer.ComposerLike<TThis> & {
413
447
  "~": {
414
448
  macros: MacroDefinitions;
415
- commandsMeta: Map<string, _gramio_composer.CommandMeta>;
449
+ commandsMeta?: Map<string, unknown>;
416
450
  Derives?: Record<string, object>;
417
451
  };
418
452
  chosenInlineResult(trigger: any, handler: any, macroOptions?: any): TThis;
@@ -423,7 +457,7 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
423
457
  reaction<TThis extends _gramio_composer.ComposerLike<TThis> & {
424
458
  "~": {
425
459
  macros: MacroDefinitions;
426
- commandsMeta: Map<string, _gramio_composer.CommandMeta>;
460
+ commandsMeta?: Map<string, unknown>;
427
461
  Derives?: Record<string, object>;
428
462
  };
429
463
  chosenInlineResult(trigger: any, handler: any, macroOptions?: any): TThis;
@@ -431,7 +465,7 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
431
465
  callbackQuery<TThis extends _gramio_composer.ComposerLike<TThis> & {
432
466
  "~": {
433
467
  macros: MacroDefinitions;
434
- commandsMeta: Map<string, _gramio_composer.CommandMeta>;
468
+ commandsMeta?: Map<string, unknown>;
435
469
  Derives?: Record<string, object>;
436
470
  };
437
471
  chosenInlineResult(trigger: any, handler: any, macroOptions?: any): TThis;
@@ -441,7 +475,7 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
441
475
  chosenInlineResult<TThis extends _gramio_composer.ComposerLike<TThis> & {
442
476
  "~": {
443
477
  macros: MacroDefinitions;
444
- commandsMeta: Map<string, _gramio_composer.CommandMeta>;
478
+ commandsMeta?: Map<string, unknown>;
445
479
  Derives?: Record<string, object>;
446
480
  };
447
481
  chosenInlineResult(trigger: any, handler: any, macroOptions?: any): TThis;
@@ -451,7 +485,7 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
451
485
  inlineQuery<TThis extends _gramio_composer.ComposerLike<TThis> & {
452
486
  "~": {
453
487
  macros: MacroDefinitions;
454
- commandsMeta: Map<string, _gramio_composer.CommandMeta>;
488
+ commandsMeta?: Map<string, unknown>;
455
489
  Derives?: Record<string, object>;
456
490
  };
457
491
  chosenInlineResult(trigger: any, handler: any, macroOptions?: any): TThis;
@@ -465,7 +499,7 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
465
499
  hears<TThis extends _gramio_composer.ComposerLike<TThis> & {
466
500
  "~": {
467
501
  macros: MacroDefinitions;
468
- commandsMeta: Map<string, _gramio_composer.CommandMeta>;
502
+ commandsMeta?: Map<string, unknown>;
469
503
  Derives?: Record<string, object>;
470
504
  };
471
505
  chosenInlineResult(trigger: any, handler: any, macroOptions?: any): TThis;
@@ -475,19 +509,19 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
475
509
  command<TThis extends _gramio_composer.ComposerLike<TThis> & {
476
510
  "~": {
477
511
  macros: MacroDefinitions;
478
- commandsMeta: Map<string, _gramio_composer.CommandMeta>;
512
+ commandsMeta?: Map<string, unknown>;
479
513
  Derives?: Record<string, object>;
480
514
  };
481
515
  chosenInlineResult(trigger: any, handler: any, macroOptions?: any): TThis;
482
516
  }>(this: TThis, command: MaybeArray<string>, handlerOrMeta: ((context: (_gramio_contexts.MessageContext<AnyBot> & _gramio_contexts.Require<_gramio_contexts.MessageContext<AnyBot>, "from">) & {
483
517
  args: string | null;
484
- } & _gramio_composer.EventContextOf<TThis, "message">) => unknown) | _gramio_composer.CommandMeta, handlerOrOptions?: ((context: (_gramio_contexts.MessageContext<AnyBot> & _gramio_contexts.Require<_gramio_contexts.MessageContext<AnyBot>, "from">) & {
518
+ } & _gramio_composer.EventContextOf<TThis, "message">) => unknown) | CommandMeta, handlerOrOptions?: ((context: (_gramio_contexts.MessageContext<AnyBot> & _gramio_contexts.Require<_gramio_contexts.MessageContext<AnyBot>, "from">) & {
485
519
  args: string | null;
486
520
  } & _gramio_composer.EventContextOf<TThis, "message">) => unknown) | Record<string, unknown>, macroOptions?: Record<string, unknown>): TThis;
487
521
  startParameter<TThis extends _gramio_composer.ComposerLike<TThis> & {
488
522
  "~": {
489
523
  macros: MacroDefinitions;
490
- commandsMeta: Map<string, _gramio_composer.CommandMeta>;
524
+ commandsMeta?: Map<string, unknown>;
491
525
  Derives?: Record<string, object>;
492
526
  };
493
527
  chosenInlineResult(trigger: any, handler: any, macroOptions?: any): TThis;
@@ -523,7 +557,10 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
523
557
  decorators: Record<string, unknown>;
524
558
  };
525
559
  /** Expose composer internals so `composer.extend(plugin)` works via duck-typing */
526
- get "~"(): InstanceType<typeof Composer>["~"];
560
+ get "~"(): Omit<InstanceType<typeof Composer>["~"], "Out" | "Derives"> & {
561
+ Out: Derives["global"];
562
+ Derives: Omit<Derives, "global">;
563
+ };
527
564
  /** Create new Plugin. Please provide `name` */
528
565
  constructor(name: string, { dependencies }?: {
529
566
  dependencies?: string[];
@@ -695,9 +732,24 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
695
732
  extend<UExposed extends object, UDerives extends Record<string, object>>(composer: EventComposer<any, any, any, any, UExposed, UDerives>): Plugin<Errors, Derives & {
696
733
  global: UExposed;
697
734
  } & UDerives>;
698
- /**
699
- * ! ** At the moment, it can only pick up types** */
700
- extend<NewPlugin extends AnyPlugin>(plugin: MaybePromise<NewPlugin>): Plugin<Errors & NewPlugin["_"]["Errors"], Derives & NewPlugin["_"]["Derives"]>;
735
+ /** Extend plugin with another Plugin (merges middleware, hooks, decorators, error definitions, groups, and dependencies) */
736
+ extend<NewPlugin extends AnyPlugin>(plugin: MaybePromise<NewPlugin>): Plugin<Errors & NewPlugin["_"]["Errors"], Derives & NewPlugin["_"]["Derives"], Macros & NewPlugin["_"]["Macros"]>;
737
+ }
738
+ interface Plugin<Errors, Derives, Macros> {
739
+ /** Register callback query handler */
740
+ callbackQuery: (typeof methods)["callbackQuery"];
741
+ /** Register command handler */
742
+ command: (typeof methods)["command"];
743
+ /** Register text/caption pattern handler */
744
+ hears: (typeof methods)["hears"];
745
+ /** Register reaction handler */
746
+ reaction: (typeof methods)["reaction"];
747
+ /** Register inline query handler */
748
+ inlineQuery: (typeof methods)["inlineQuery"];
749
+ /** Register chosen inline result handler */
750
+ chosenInlineResult: (typeof methods)["chosenInlineResult"];
751
+ /** Register deep-link parameter handler */
752
+ startParameter: (typeof methods)["startParameter"];
701
753
  }
702
754
 
703
755
  /** Bot options that you can provide to {@link Bot} constructor */
@@ -1010,6 +1062,22 @@ interface PollingStartOptions {
1010
1062
  dropPendingUpdates?: boolean;
1011
1063
  deleteWebhookOnConflict?: boolean;
1012
1064
  }
1065
+ /** Shorthand strings for common BotCommandScope types */
1066
+ type ScopeShorthand = "default" | "all_private_chats" | "all_group_chats" | "all_chat_administrators";
1067
+ /**
1068
+ * Metadata for a bot command, used by `syncCommands()` to push
1069
+ * descriptions, localized names, and visibility scopes to the Telegram API.
1070
+ */
1071
+ interface CommandMeta {
1072
+ /** Command description shown in the Telegram menu (1-256 chars) */
1073
+ description: string;
1074
+ /** Localized descriptions keyed by IETF language tag */
1075
+ locales?: Record<string, string>;
1076
+ /** Where this command is visible. Default: `["default"]` */
1077
+ scopes?: (TelegramBotCommandScope | ScopeShorthand)[];
1078
+ /** Exclude this command from `syncCommands()`. The handler still works. @default false */
1079
+ hide?: boolean;
1080
+ }
1013
1081
  /** Minimal key-value storage interface compatible with `@gramio/storage` */
1014
1082
  interface SyncStorage {
1015
1083
  get(key: string): string | undefined | Promise<string | undefined>;
@@ -1487,7 +1555,7 @@ declare class Bot<Errors extends ErrorDefinitions = {}, Derives extends DeriveDe
1487
1555
  command<TOptions extends HandlerOptions<ContextType<typeof this, "message">, Macros> = {}>(command: MaybeArray<string>, handler: (context: ContextType<typeof this, "message"> & {
1488
1556
  args: string | null;
1489
1557
  } & DeriveFromOptions<Macros, TOptions>) => unknown, options?: TOptions): typeof this;
1490
- command<TOptions extends HandlerOptions<ContextType<typeof this, "message">, Macros> = {}>(command: MaybeArray<string>, meta: CommandMeta<TelegramBotCommandScope>, handler: (context: ContextType<typeof this, "message"> & {
1558
+ command<TOptions extends HandlerOptions<ContextType<typeof this, "message">, Macros> = {}>(command: MaybeArray<string>, meta: CommandMeta, handler: (context: ContextType<typeof this, "message"> & {
1491
1559
  args: string | null;
1492
1560
  } & DeriveFromOptions<Macros, TOptions>) => unknown, options?: TOptions): typeof this;
1493
1561
  /**
@@ -1928,5 +1996,5 @@ declare function webhookHandler<Framework extends keyof typeof frameworks>(bot:
1928
1996
  response: () => any;
1929
1997
  } ? (...args: Parameters<(typeof frameworks)[Framework]>) => ReturnType<ReturnType<(typeof frameworks)[Framework]>["response"]> : (...args: Parameters<(typeof frameworks)[Framework]>) => void;
1930
1998
 
1931
- export { AllowedUpdatesFilter, Bot, Composer, ErrorKind, Hooks, OPT_IN_TYPES, Plugin, TelegramError, Updates, buildAllowedUpdates, detectOptInUpdates, filters, mapEventToAllowedUpdates, webhookHandler };
1932
- export type { AllowedUpdateName, AllowedUpdates, AnyBot, AnyPlugin, BotOptions, BotStartOptions, BotStartOptionsLongPolling, BotStartOptionsWebhook, CallbackQueryShorthandContext, DeriveDefinitions, ErrorDefinitions, Filter, Handler, MaybePromise, MaybeSuppressedParams, MaybeSuppressedReturn, PollingStartOptions, Suppress, SuppressedAPIMethodParams, SuppressedAPIMethodReturn, SuppressedAPIMethods, SyncCommandsOptions, SyncStorage, WebhookHandlerOptions, WebhookHandlerOptionsShouldWait, WebhookHandlers };
1999
+ export { AllowedUpdatesFilter, Bot, Composer, ErrorKind, Hooks, OPT_IN_TYPES, Plugin, TelegramError, Updates, methods as _composerMethods, buildAllowedUpdates, detectOptInUpdates, filters, mapEventToAllowedUpdates, webhookHandler };
2000
+ export type { AllowedUpdateName, AllowedUpdates, AnyBot, AnyPlugin, BotOptions, BotStartOptions, BotStartOptionsLongPolling, BotStartOptionsWebhook, CallbackQueryShorthandContext, CommandMeta, DeriveDefinitions, ErrorDefinitions, Filter, Handler, MaybePromise, MaybeSuppressedParams, MaybeSuppressedReturn, PollingStartOptions, ScopeShorthand, Suppress, SuppressedAPIMethodParams, SuppressedAPIMethodReturn, SuppressedAPIMethods, SyncCommandsOptions, SyncStorage, WebhookHandlerOptions, WebhookHandlerOptionsShouldWait, WebhookHandlers };
package/dist/index.js CHANGED
@@ -350,6 +350,10 @@ if (typeof Composer.prototype.registeredEvents !== "function") {
350
350
  {
351
351
  const originalExtend = Composer.prototype.extend;
352
352
  Composer.prototype.extend = function(other) {
353
+ if ("_" in other && !(other instanceof Promise)) {
354
+ if (!this["~"].__plugins) this["~"].__plugins = [];
355
+ this["~"].__plugins.push(other);
356
+ }
353
357
  const result = originalExtend.call(this, other);
354
358
  if (other["~"]?.commandsMeta) {
355
359
  if (!this["~"].commandsMeta) {
@@ -359,6 +363,10 @@ if (typeof Composer.prototype.registeredEvents !== "function") {
359
363
  this["~"].commandsMeta.set(cmd, meta);
360
364
  }
361
365
  }
366
+ if (other["~"]?.__plugins) {
367
+ if (!this["~"].__plugins) this["~"].__plugins = [];
368
+ this["~"].__plugins.push(...other["~"].__plugins);
369
+ }
362
370
  return result;
363
371
  };
364
372
  }
@@ -577,10 +585,39 @@ class Plugin {
577
585
  extend(pluginOrComposer) {
578
586
  if ("compose" in pluginOrComposer && "run" in pluginOrComposer && !("_" in pluginOrComposer)) {
579
587
  this._.composer.extend(pluginOrComposer);
588
+ return this;
589
+ }
590
+ const plugin = pluginOrComposer;
591
+ if (plugin._.composer["~"].middlewares.length) {
592
+ plugin._.composer.as("scoped");
593
+ this._.composer.extend(plugin._.composer);
594
+ } else if (Object.keys(plugin._.composer["~"].macros).length) {
595
+ Object.assign(this._.composer["~"].macros, plugin._.composer["~"].macros);
596
+ }
597
+ for (const [key, value] of Object.entries(plugin._.errorsDefinitions)) {
598
+ this._.errorsDefinitions[key] = value;
599
+ this._.composer["~"].errorsDefinitions[key] = value;
600
+ }
601
+ Object.assign(this._.decorators, plugin._.decorators);
602
+ this._.preRequests.push(...plugin._.preRequests);
603
+ this._.onResponses.push(...plugin._.onResponses);
604
+ this._.onResponseErrors.push(...plugin._.onResponseErrors);
605
+ this._.onApiCalls.push(...plugin._.onApiCalls);
606
+ this._.onErrors.push(...plugin._.onErrors);
607
+ this._.onStarts.push(...plugin._.onStarts);
608
+ this._.onStops.push(...plugin._.onStops);
609
+ this._.groups.push(...plugin._.groups);
610
+ for (const dep of plugin._.dependencies) {
611
+ if (!this._.dependencies.includes(dep)) {
612
+ this._.dependencies.push(dep);
613
+ }
580
614
  }
581
615
  return this;
582
616
  }
583
617
  }
618
+ for (const [name, fn] of Object.entries(methods)) {
619
+ Plugin.prototype[name] = fn;
620
+ }
584
621
 
585
622
  class Updates {
586
623
  bot;
@@ -1095,6 +1132,45 @@ class Bot {
1095
1132
  extend(pluginOrComposer) {
1096
1133
  if ("compose" in pluginOrComposer && "run" in pluginOrComposer && !("_" in pluginOrComposer)) {
1097
1134
  this.updates.composer.extend(pluginOrComposer);
1135
+ const trackedPlugins = pluginOrComposer["~"]?.__plugins;
1136
+ if (trackedPlugins) {
1137
+ for (const p of trackedPlugins) {
1138
+ this.decorate(p._.decorators);
1139
+ for (const value of p._.preRequests) {
1140
+ const [preRequest, updateName] = value;
1141
+ if (!updateName) this.preRequest(preRequest);
1142
+ else this.preRequest(updateName, preRequest);
1143
+ }
1144
+ for (const value of p._.onResponses) {
1145
+ const [onResponse, updateName] = value;
1146
+ if (!updateName) this.onResponse(onResponse);
1147
+ else this.onResponse(updateName, onResponse);
1148
+ }
1149
+ for (const value of p._.onResponseErrors) {
1150
+ const [onResponseError, updateName] = value;
1151
+ if (!updateName) this.onResponseError(onResponseError);
1152
+ else this.onResponseError(updateName, onResponseError);
1153
+ }
1154
+ for (const value of p._.onApiCalls) {
1155
+ const [onApiCall, methods] = value;
1156
+ if (!methods) this.onApiCall(onApiCall);
1157
+ else this.onApiCall(methods, onApiCall);
1158
+ }
1159
+ for (const handler of p._.groups) {
1160
+ this.group(handler);
1161
+ }
1162
+ for (const value of p._.onErrors) {
1163
+ this.onError(value);
1164
+ }
1165
+ for (const value of p._.onStarts) {
1166
+ this.onStart(value);
1167
+ }
1168
+ for (const value of p._.onStops) {
1169
+ this.onStop(value);
1170
+ }
1171
+ this.dependencies.push(p._.name);
1172
+ }
1173
+ }
1098
1174
  return this;
1099
1175
  }
1100
1176
  const plugin = pluginOrComposer;
@@ -1783,4 +1859,4 @@ function webhookHandler(bot, framework, secretTokenOrOptions) {
1783
1859
 
1784
1860
  Symbol.metadata ??= Symbol("Symbol.metadata");
1785
1861
 
1786
- export { AllowedUpdatesFilter, Bot, Composer, ErrorKind, OPT_IN_TYPES, Plugin, TelegramError, Updates, buildAllowedUpdates, detectOptInUpdates, filters, mapEventToAllowedUpdates, webhookHandler };
1862
+ export { AllowedUpdatesFilter, Bot, Composer, ErrorKind, OPT_IN_TYPES, Plugin, TelegramError, Updates, methods as _composerMethods, buildAllowedUpdates, detectOptInUpdates, filters, mapEventToAllowedUpdates, webhookHandler };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "gramio",
3
3
  "type": "module",
4
- "version": "0.8.0",
4
+ "version": "0.8.3",
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",
@@ -65,8 +65,8 @@
65
65
  },
66
66
  "dependencies": {
67
67
  "@gramio/callback-data": "^0.1.0",
68
- "@gramio/composer": "^0.4.0",
69
- "@gramio/contexts": "^0.5.0",
68
+ "@gramio/composer": "0.4.1",
69
+ "@gramio/contexts": "0.5.1",
70
70
  "@gramio/files": "^0.3.2",
71
71
  "@gramio/format": "^0.5.0",
72
72
  "@gramio/keyboards": "^1.3.1",