gramio 0.8.1 → 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 +77 -0
- package/dist/index.d.cts +57 -5
- package/dist/index.d.ts +57 -5
- package/dist/index.js +77 -1
- package/package.json +2 -2
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
|
@@ -179,11 +179,45 @@ type GramIOLike<T> = ComposerLike<T> & {
|
|
|
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, {
|
|
@@ -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
|
-
|
|
700
|
-
|
|
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 */
|
|
@@ -1944,5 +1996,5 @@ declare function webhookHandler<Framework extends keyof typeof frameworks>(bot:
|
|
|
1944
1996
|
response: () => any;
|
|
1945
1997
|
} ? (...args: Parameters<(typeof frameworks)[Framework]>) => ReturnType<ReturnType<(typeof frameworks)[Framework]>["response"]> : (...args: Parameters<(typeof frameworks)[Framework]>) => void;
|
|
1946
1998
|
|
|
1947
|
-
export { AllowedUpdatesFilter, Bot, Composer, ErrorKind, Hooks, OPT_IN_TYPES, Plugin, TelegramError, Updates, buildAllowedUpdates, detectOptInUpdates, filters, mapEventToAllowedUpdates, webhookHandler };
|
|
1999
|
+
export { AllowedUpdatesFilter, Bot, Composer, ErrorKind, Hooks, OPT_IN_TYPES, Plugin, TelegramError, Updates, methods as _composerMethods, buildAllowedUpdates, detectOptInUpdates, filters, mapEventToAllowedUpdates, webhookHandler };
|
|
1948
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
|
@@ -179,11 +179,45 @@ type GramIOLike<T> = ComposerLike<T> & {
|
|
|
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, {
|
|
@@ -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
|
-
|
|
700
|
-
|
|
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 */
|
|
@@ -1944,5 +1996,5 @@ declare function webhookHandler<Framework extends keyof typeof frameworks>(bot:
|
|
|
1944
1996
|
response: () => any;
|
|
1945
1997
|
} ? (...args: Parameters<(typeof frameworks)[Framework]>) => ReturnType<ReturnType<(typeof frameworks)[Framework]>["response"]> : (...args: Parameters<(typeof frameworks)[Framework]>) => void;
|
|
1946
1998
|
|
|
1947
|
-
export { AllowedUpdatesFilter, Bot, Composer, ErrorKind, Hooks, OPT_IN_TYPES, Plugin, TelegramError, Updates, buildAllowedUpdates, detectOptInUpdates, filters, mapEventToAllowedUpdates, webhookHandler };
|
|
1999
|
+
export { AllowedUpdatesFilter, Bot, Composer, ErrorKind, Hooks, OPT_IN_TYPES, Plugin, TelegramError, Updates, methods as _composerMethods, buildAllowedUpdates, detectOptInUpdates, filters, mapEventToAllowedUpdates, webhookHandler };
|
|
1948
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.
|
|
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",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"dependencies": {
|
|
67
67
|
"@gramio/callback-data": "^0.1.0",
|
|
68
68
|
"@gramio/composer": "0.4.1",
|
|
69
|
-
"@gramio/contexts": "
|
|
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",
|