gramio 0.8.1 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +79 -1
- package/dist/index.d.cts +61 -5
- package/dist/index.d.ts +61 -5
- package/dist/index.js +79 -2
- package/package.json +8 -8
package/dist/index.cjs
CHANGED
|
@@ -34,7 +34,8 @@ const ALL_NAMES = [
|
|
|
34
34
|
"chat_member",
|
|
35
35
|
"chat_join_request",
|
|
36
36
|
"chat_boost",
|
|
37
|
-
"removed_chat_boost"
|
|
37
|
+
"removed_chat_boost",
|
|
38
|
+
"managed_bot"
|
|
38
39
|
];
|
|
39
40
|
const MESSAGE_PARENT_TYPES = [
|
|
40
41
|
"message",
|
|
@@ -348,6 +349,10 @@ if (typeof Composer.prototype.registeredEvents !== "function") {
|
|
|
348
349
|
{
|
|
349
350
|
const originalExtend = Composer.prototype.extend;
|
|
350
351
|
Composer.prototype.extend = function(other) {
|
|
352
|
+
if ("_" in other && !(other instanceof Promise)) {
|
|
353
|
+
if (!this["~"].__plugins) this["~"].__plugins = [];
|
|
354
|
+
this["~"].__plugins.push(other);
|
|
355
|
+
}
|
|
351
356
|
const result = originalExtend.call(this, other);
|
|
352
357
|
if (other["~"]?.commandsMeta) {
|
|
353
358
|
if (!this["~"].commandsMeta) {
|
|
@@ -357,6 +362,10 @@ if (typeof Composer.prototype.registeredEvents !== "function") {
|
|
|
357
362
|
this["~"].commandsMeta.set(cmd, meta);
|
|
358
363
|
}
|
|
359
364
|
}
|
|
365
|
+
if (other["~"]?.__plugins) {
|
|
366
|
+
if (!this["~"].__plugins) this["~"].__plugins = [];
|
|
367
|
+
this["~"].__plugins.push(...other["~"].__plugins);
|
|
368
|
+
}
|
|
360
369
|
return result;
|
|
361
370
|
};
|
|
362
371
|
}
|
|
@@ -575,10 +584,39 @@ class Plugin {
|
|
|
575
584
|
extend(pluginOrComposer) {
|
|
576
585
|
if ("compose" in pluginOrComposer && "run" in pluginOrComposer && !("_" in pluginOrComposer)) {
|
|
577
586
|
this._.composer.extend(pluginOrComposer);
|
|
587
|
+
return this;
|
|
588
|
+
}
|
|
589
|
+
const plugin = pluginOrComposer;
|
|
590
|
+
if (plugin._.composer["~"].middlewares.length) {
|
|
591
|
+
plugin._.composer.as("scoped");
|
|
592
|
+
this._.composer.extend(plugin._.composer);
|
|
593
|
+
} else if (Object.keys(plugin._.composer["~"].macros).length) {
|
|
594
|
+
Object.assign(this._.composer["~"].macros, plugin._.composer["~"].macros);
|
|
595
|
+
}
|
|
596
|
+
for (const [key, value] of Object.entries(plugin._.errorsDefinitions)) {
|
|
597
|
+
this._.errorsDefinitions[key] = value;
|
|
598
|
+
this._.composer["~"].errorsDefinitions[key] = value;
|
|
599
|
+
}
|
|
600
|
+
Object.assign(this._.decorators, plugin._.decorators);
|
|
601
|
+
this._.preRequests.push(...plugin._.preRequests);
|
|
602
|
+
this._.onResponses.push(...plugin._.onResponses);
|
|
603
|
+
this._.onResponseErrors.push(...plugin._.onResponseErrors);
|
|
604
|
+
this._.onApiCalls.push(...plugin._.onApiCalls);
|
|
605
|
+
this._.onErrors.push(...plugin._.onErrors);
|
|
606
|
+
this._.onStarts.push(...plugin._.onStarts);
|
|
607
|
+
this._.onStops.push(...plugin._.onStops);
|
|
608
|
+
this._.groups.push(...plugin._.groups);
|
|
609
|
+
for (const dep of plugin._.dependencies) {
|
|
610
|
+
if (!this._.dependencies.includes(dep)) {
|
|
611
|
+
this._.dependencies.push(dep);
|
|
612
|
+
}
|
|
578
613
|
}
|
|
579
614
|
return this;
|
|
580
615
|
}
|
|
581
616
|
}
|
|
617
|
+
for (const [name, fn] of Object.entries(methods)) {
|
|
618
|
+
Plugin.prototype[name] = fn;
|
|
619
|
+
}
|
|
582
620
|
|
|
583
621
|
class Updates {
|
|
584
622
|
bot;
|
|
@@ -1093,6 +1131,45 @@ class Bot {
|
|
|
1093
1131
|
extend(pluginOrComposer) {
|
|
1094
1132
|
if ("compose" in pluginOrComposer && "run" in pluginOrComposer && !("_" in pluginOrComposer)) {
|
|
1095
1133
|
this.updates.composer.extend(pluginOrComposer);
|
|
1134
|
+
const trackedPlugins = pluginOrComposer["~"]?.__plugins;
|
|
1135
|
+
if (trackedPlugins) {
|
|
1136
|
+
for (const p of trackedPlugins) {
|
|
1137
|
+
this.decorate(p._.decorators);
|
|
1138
|
+
for (const value of p._.preRequests) {
|
|
1139
|
+
const [preRequest, updateName] = value;
|
|
1140
|
+
if (!updateName) this.preRequest(preRequest);
|
|
1141
|
+
else this.preRequest(updateName, preRequest);
|
|
1142
|
+
}
|
|
1143
|
+
for (const value of p._.onResponses) {
|
|
1144
|
+
const [onResponse, updateName] = value;
|
|
1145
|
+
if (!updateName) this.onResponse(onResponse);
|
|
1146
|
+
else this.onResponse(updateName, onResponse);
|
|
1147
|
+
}
|
|
1148
|
+
for (const value of p._.onResponseErrors) {
|
|
1149
|
+
const [onResponseError, updateName] = value;
|
|
1150
|
+
if (!updateName) this.onResponseError(onResponseError);
|
|
1151
|
+
else this.onResponseError(updateName, onResponseError);
|
|
1152
|
+
}
|
|
1153
|
+
for (const value of p._.onApiCalls) {
|
|
1154
|
+
const [onApiCall, methods] = value;
|
|
1155
|
+
if (!methods) this.onApiCall(onApiCall);
|
|
1156
|
+
else this.onApiCall(methods, onApiCall);
|
|
1157
|
+
}
|
|
1158
|
+
for (const handler of p._.groups) {
|
|
1159
|
+
this.group(handler);
|
|
1160
|
+
}
|
|
1161
|
+
for (const value of p._.onErrors) {
|
|
1162
|
+
this.onError(value);
|
|
1163
|
+
}
|
|
1164
|
+
for (const value of p._.onStarts) {
|
|
1165
|
+
this.onStart(value);
|
|
1166
|
+
}
|
|
1167
|
+
for (const value of p._.onStops) {
|
|
1168
|
+
this.onStop(value);
|
|
1169
|
+
}
|
|
1170
|
+
this.dependencies.push(p._.name);
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1096
1173
|
return this;
|
|
1097
1174
|
}
|
|
1098
1175
|
const plugin = pluginOrComposer;
|
|
@@ -1813,6 +1890,7 @@ exports.Composer = Composer;
|
|
|
1813
1890
|
exports.OPT_IN_TYPES = OPT_IN_TYPES;
|
|
1814
1891
|
exports.Plugin = Plugin;
|
|
1815
1892
|
exports.Updates = Updates;
|
|
1893
|
+
exports._composerMethods = methods;
|
|
1816
1894
|
exports.buildAllowedUpdates = buildAllowedUpdates;
|
|
1817
1895
|
exports.detectOptInUpdates = detectOptInUpdates;
|
|
1818
1896
|
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, {
|
|
@@ -282,6 +316,8 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
|
|
|
282
316
|
invoice: _gramio_contexts.InvoiceContext<AnyBot>;
|
|
283
317
|
left_chat_member: _gramio_contexts.LeftChatMemberContext<AnyBot>;
|
|
284
318
|
location: _gramio_contexts.LocationContext<AnyBot>;
|
|
319
|
+
managed_bot: _gramio_contexts.ManagedBotContext<AnyBot>;
|
|
320
|
+
managed_bot_created: _gramio_contexts.ManagedBotCreatedContext<AnyBot>;
|
|
285
321
|
message_auto_delete_timer_changed: _gramio_contexts.MessageAutoDeleteTimerChangedContext<AnyBot>;
|
|
286
322
|
message: _gramio_contexts.MessageContext<AnyBot> & _gramio_contexts.Require<_gramio_contexts.MessageContext<AnyBot>, "from">;
|
|
287
323
|
channel_post: _gramio_contexts.MessageContext<AnyBot>;
|
|
@@ -299,6 +335,8 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
|
|
|
299
335
|
passport_data: _gramio_contexts.PassportDataContext<AnyBot>;
|
|
300
336
|
pinned_message: _gramio_contexts.PinnedMessageContext<AnyBot>;
|
|
301
337
|
poll_answer: _gramio_contexts.PollAnswerContext<AnyBot>;
|
|
338
|
+
poll_option_added: _gramio_contexts.PollOptionAddedContext<AnyBot>;
|
|
339
|
+
poll_option_deleted: _gramio_contexts.PollOptionDeletedContext<AnyBot>;
|
|
302
340
|
poll: _gramio_contexts.PollContext<AnyBot>;
|
|
303
341
|
pre_checkout_query: _gramio_contexts.PreCheckoutQueryContext<AnyBot>;
|
|
304
342
|
proximity_alert_triggered: _gramio_contexts.ProximityAlertTriggeredContext<AnyBot>;
|
|
@@ -523,7 +561,10 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
|
|
|
523
561
|
decorators: Record<string, unknown>;
|
|
524
562
|
};
|
|
525
563
|
/** Expose composer internals so `composer.extend(plugin)` works via duck-typing */
|
|
526
|
-
get "~"(): InstanceType<typeof Composer>["~"]
|
|
564
|
+
get "~"(): Omit<InstanceType<typeof Composer>["~"], "Out" | "Derives"> & {
|
|
565
|
+
Out: Derives["global"];
|
|
566
|
+
Derives: Omit<Derives, "global">;
|
|
567
|
+
};
|
|
527
568
|
/** Create new Plugin. Please provide `name` */
|
|
528
569
|
constructor(name: string, { dependencies }?: {
|
|
529
570
|
dependencies?: string[];
|
|
@@ -695,9 +736,24 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
|
|
|
695
736
|
extend<UExposed extends object, UDerives extends Record<string, object>>(composer: EventComposer<any, any, any, any, UExposed, UDerives>): Plugin<Errors, Derives & {
|
|
696
737
|
global: UExposed;
|
|
697
738
|
} & UDerives>;
|
|
698
|
-
/**
|
|
699
|
-
|
|
700
|
-
|
|
739
|
+
/** Extend plugin with another Plugin (merges middleware, hooks, decorators, error definitions, groups, and dependencies) */
|
|
740
|
+
extend<NewPlugin extends AnyPlugin>(plugin: MaybePromise<NewPlugin>): Plugin<Errors & NewPlugin["_"]["Errors"], Derives & NewPlugin["_"]["Derives"], Macros & NewPlugin["_"]["Macros"]>;
|
|
741
|
+
}
|
|
742
|
+
interface Plugin<Errors, Derives, Macros> {
|
|
743
|
+
/** Register callback query handler */
|
|
744
|
+
callbackQuery: (typeof methods)["callbackQuery"];
|
|
745
|
+
/** Register command handler */
|
|
746
|
+
command: (typeof methods)["command"];
|
|
747
|
+
/** Register text/caption pattern handler */
|
|
748
|
+
hears: (typeof methods)["hears"];
|
|
749
|
+
/** Register reaction handler */
|
|
750
|
+
reaction: (typeof methods)["reaction"];
|
|
751
|
+
/** Register inline query handler */
|
|
752
|
+
inlineQuery: (typeof methods)["inlineQuery"];
|
|
753
|
+
/** Register chosen inline result handler */
|
|
754
|
+
chosenInlineResult: (typeof methods)["chosenInlineResult"];
|
|
755
|
+
/** Register deep-link parameter handler */
|
|
756
|
+
startParameter: (typeof methods)["startParameter"];
|
|
701
757
|
}
|
|
702
758
|
|
|
703
759
|
/** Bot options that you can provide to {@link Bot} constructor */
|
|
@@ -1944,5 +2000,5 @@ declare function webhookHandler<Framework extends keyof typeof frameworks>(bot:
|
|
|
1944
2000
|
response: () => any;
|
|
1945
2001
|
} ? (...args: Parameters<(typeof frameworks)[Framework]>) => ReturnType<ReturnType<(typeof frameworks)[Framework]>["response"]> : (...args: Parameters<(typeof frameworks)[Framework]>) => void;
|
|
1946
2002
|
|
|
1947
|
-
export { AllowedUpdatesFilter, Bot, Composer, ErrorKind, Hooks, OPT_IN_TYPES, Plugin, TelegramError, Updates, buildAllowedUpdates, detectOptInUpdates, filters, mapEventToAllowedUpdates, webhookHandler };
|
|
2003
|
+
export { AllowedUpdatesFilter, Bot, Composer, ErrorKind, Hooks, OPT_IN_TYPES, Plugin, TelegramError, Updates, methods as _composerMethods, buildAllowedUpdates, detectOptInUpdates, filters, mapEventToAllowedUpdates, webhookHandler };
|
|
1948
2004
|
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, {
|
|
@@ -282,6 +316,8 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
|
|
|
282
316
|
invoice: _gramio_contexts.InvoiceContext<AnyBot>;
|
|
283
317
|
left_chat_member: _gramio_contexts.LeftChatMemberContext<AnyBot>;
|
|
284
318
|
location: _gramio_contexts.LocationContext<AnyBot>;
|
|
319
|
+
managed_bot: _gramio_contexts.ManagedBotContext<AnyBot>;
|
|
320
|
+
managed_bot_created: _gramio_contexts.ManagedBotCreatedContext<AnyBot>;
|
|
285
321
|
message_auto_delete_timer_changed: _gramio_contexts.MessageAutoDeleteTimerChangedContext<AnyBot>;
|
|
286
322
|
message: _gramio_contexts.MessageContext<AnyBot> & _gramio_contexts.Require<_gramio_contexts.MessageContext<AnyBot>, "from">;
|
|
287
323
|
channel_post: _gramio_contexts.MessageContext<AnyBot>;
|
|
@@ -299,6 +335,8 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
|
|
|
299
335
|
passport_data: _gramio_contexts.PassportDataContext<AnyBot>;
|
|
300
336
|
pinned_message: _gramio_contexts.PinnedMessageContext<AnyBot>;
|
|
301
337
|
poll_answer: _gramio_contexts.PollAnswerContext<AnyBot>;
|
|
338
|
+
poll_option_added: _gramio_contexts.PollOptionAddedContext<AnyBot>;
|
|
339
|
+
poll_option_deleted: _gramio_contexts.PollOptionDeletedContext<AnyBot>;
|
|
302
340
|
poll: _gramio_contexts.PollContext<AnyBot>;
|
|
303
341
|
pre_checkout_query: _gramio_contexts.PreCheckoutQueryContext<AnyBot>;
|
|
304
342
|
proximity_alert_triggered: _gramio_contexts.ProximityAlertTriggeredContext<AnyBot>;
|
|
@@ -523,7 +561,10 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
|
|
|
523
561
|
decorators: Record<string, unknown>;
|
|
524
562
|
};
|
|
525
563
|
/** Expose composer internals so `composer.extend(plugin)` works via duck-typing */
|
|
526
|
-
get "~"(): InstanceType<typeof Composer>["~"]
|
|
564
|
+
get "~"(): Omit<InstanceType<typeof Composer>["~"], "Out" | "Derives"> & {
|
|
565
|
+
Out: Derives["global"];
|
|
566
|
+
Derives: Omit<Derives, "global">;
|
|
567
|
+
};
|
|
527
568
|
/** Create new Plugin. Please provide `name` */
|
|
528
569
|
constructor(name: string, { dependencies }?: {
|
|
529
570
|
dependencies?: string[];
|
|
@@ -695,9 +736,24 @@ declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extends Deriv
|
|
|
695
736
|
extend<UExposed extends object, UDerives extends Record<string, object>>(composer: EventComposer<any, any, any, any, UExposed, UDerives>): Plugin<Errors, Derives & {
|
|
696
737
|
global: UExposed;
|
|
697
738
|
} & UDerives>;
|
|
698
|
-
/**
|
|
699
|
-
|
|
700
|
-
|
|
739
|
+
/** Extend plugin with another Plugin (merges middleware, hooks, decorators, error definitions, groups, and dependencies) */
|
|
740
|
+
extend<NewPlugin extends AnyPlugin>(plugin: MaybePromise<NewPlugin>): Plugin<Errors & NewPlugin["_"]["Errors"], Derives & NewPlugin["_"]["Derives"], Macros & NewPlugin["_"]["Macros"]>;
|
|
741
|
+
}
|
|
742
|
+
interface Plugin<Errors, Derives, Macros> {
|
|
743
|
+
/** Register callback query handler */
|
|
744
|
+
callbackQuery: (typeof methods)["callbackQuery"];
|
|
745
|
+
/** Register command handler */
|
|
746
|
+
command: (typeof methods)["command"];
|
|
747
|
+
/** Register text/caption pattern handler */
|
|
748
|
+
hears: (typeof methods)["hears"];
|
|
749
|
+
/** Register reaction handler */
|
|
750
|
+
reaction: (typeof methods)["reaction"];
|
|
751
|
+
/** Register inline query handler */
|
|
752
|
+
inlineQuery: (typeof methods)["inlineQuery"];
|
|
753
|
+
/** Register chosen inline result handler */
|
|
754
|
+
chosenInlineResult: (typeof methods)["chosenInlineResult"];
|
|
755
|
+
/** Register deep-link parameter handler */
|
|
756
|
+
startParameter: (typeof methods)["startParameter"];
|
|
701
757
|
}
|
|
702
758
|
|
|
703
759
|
/** Bot options that you can provide to {@link Bot} constructor */
|
|
@@ -1944,5 +2000,5 @@ declare function webhookHandler<Framework extends keyof typeof frameworks>(bot:
|
|
|
1944
2000
|
response: () => any;
|
|
1945
2001
|
} ? (...args: Parameters<(typeof frameworks)[Framework]>) => ReturnType<ReturnType<(typeof frameworks)[Framework]>["response"]> : (...args: Parameters<(typeof frameworks)[Framework]>) => void;
|
|
1946
2002
|
|
|
1947
|
-
export { AllowedUpdatesFilter, Bot, Composer, ErrorKind, Hooks, OPT_IN_TYPES, Plugin, TelegramError, Updates, buildAllowedUpdates, detectOptInUpdates, filters, mapEventToAllowedUpdates, webhookHandler };
|
|
2003
|
+
export { AllowedUpdatesFilter, Bot, Composer, ErrorKind, Hooks, OPT_IN_TYPES, Plugin, TelegramError, Updates, methods as _composerMethods, buildAllowedUpdates, detectOptInUpdates, filters, mapEventToAllowedUpdates, webhookHandler };
|
|
1948
2004
|
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
|
@@ -36,7 +36,8 @@ const ALL_NAMES = [
|
|
|
36
36
|
"chat_member",
|
|
37
37
|
"chat_join_request",
|
|
38
38
|
"chat_boost",
|
|
39
|
-
"removed_chat_boost"
|
|
39
|
+
"removed_chat_boost",
|
|
40
|
+
"managed_bot"
|
|
40
41
|
];
|
|
41
42
|
const MESSAGE_PARENT_TYPES = [
|
|
42
43
|
"message",
|
|
@@ -350,6 +351,10 @@ if (typeof Composer.prototype.registeredEvents !== "function") {
|
|
|
350
351
|
{
|
|
351
352
|
const originalExtend = Composer.prototype.extend;
|
|
352
353
|
Composer.prototype.extend = function(other) {
|
|
354
|
+
if ("_" in other && !(other instanceof Promise)) {
|
|
355
|
+
if (!this["~"].__plugins) this["~"].__plugins = [];
|
|
356
|
+
this["~"].__plugins.push(other);
|
|
357
|
+
}
|
|
353
358
|
const result = originalExtend.call(this, other);
|
|
354
359
|
if (other["~"]?.commandsMeta) {
|
|
355
360
|
if (!this["~"].commandsMeta) {
|
|
@@ -359,6 +364,10 @@ if (typeof Composer.prototype.registeredEvents !== "function") {
|
|
|
359
364
|
this["~"].commandsMeta.set(cmd, meta);
|
|
360
365
|
}
|
|
361
366
|
}
|
|
367
|
+
if (other["~"]?.__plugins) {
|
|
368
|
+
if (!this["~"].__plugins) this["~"].__plugins = [];
|
|
369
|
+
this["~"].__plugins.push(...other["~"].__plugins);
|
|
370
|
+
}
|
|
362
371
|
return result;
|
|
363
372
|
};
|
|
364
373
|
}
|
|
@@ -577,10 +586,39 @@ class Plugin {
|
|
|
577
586
|
extend(pluginOrComposer) {
|
|
578
587
|
if ("compose" in pluginOrComposer && "run" in pluginOrComposer && !("_" in pluginOrComposer)) {
|
|
579
588
|
this._.composer.extend(pluginOrComposer);
|
|
589
|
+
return this;
|
|
590
|
+
}
|
|
591
|
+
const plugin = pluginOrComposer;
|
|
592
|
+
if (plugin._.composer["~"].middlewares.length) {
|
|
593
|
+
plugin._.composer.as("scoped");
|
|
594
|
+
this._.composer.extend(plugin._.composer);
|
|
595
|
+
} else if (Object.keys(plugin._.composer["~"].macros).length) {
|
|
596
|
+
Object.assign(this._.composer["~"].macros, plugin._.composer["~"].macros);
|
|
597
|
+
}
|
|
598
|
+
for (const [key, value] of Object.entries(plugin._.errorsDefinitions)) {
|
|
599
|
+
this._.errorsDefinitions[key] = value;
|
|
600
|
+
this._.composer["~"].errorsDefinitions[key] = value;
|
|
601
|
+
}
|
|
602
|
+
Object.assign(this._.decorators, plugin._.decorators);
|
|
603
|
+
this._.preRequests.push(...plugin._.preRequests);
|
|
604
|
+
this._.onResponses.push(...plugin._.onResponses);
|
|
605
|
+
this._.onResponseErrors.push(...plugin._.onResponseErrors);
|
|
606
|
+
this._.onApiCalls.push(...plugin._.onApiCalls);
|
|
607
|
+
this._.onErrors.push(...plugin._.onErrors);
|
|
608
|
+
this._.onStarts.push(...plugin._.onStarts);
|
|
609
|
+
this._.onStops.push(...plugin._.onStops);
|
|
610
|
+
this._.groups.push(...plugin._.groups);
|
|
611
|
+
for (const dep of plugin._.dependencies) {
|
|
612
|
+
if (!this._.dependencies.includes(dep)) {
|
|
613
|
+
this._.dependencies.push(dep);
|
|
614
|
+
}
|
|
580
615
|
}
|
|
581
616
|
return this;
|
|
582
617
|
}
|
|
583
618
|
}
|
|
619
|
+
for (const [name, fn] of Object.entries(methods)) {
|
|
620
|
+
Plugin.prototype[name] = fn;
|
|
621
|
+
}
|
|
584
622
|
|
|
585
623
|
class Updates {
|
|
586
624
|
bot;
|
|
@@ -1095,6 +1133,45 @@ class Bot {
|
|
|
1095
1133
|
extend(pluginOrComposer) {
|
|
1096
1134
|
if ("compose" in pluginOrComposer && "run" in pluginOrComposer && !("_" in pluginOrComposer)) {
|
|
1097
1135
|
this.updates.composer.extend(pluginOrComposer);
|
|
1136
|
+
const trackedPlugins = pluginOrComposer["~"]?.__plugins;
|
|
1137
|
+
if (trackedPlugins) {
|
|
1138
|
+
for (const p of trackedPlugins) {
|
|
1139
|
+
this.decorate(p._.decorators);
|
|
1140
|
+
for (const value of p._.preRequests) {
|
|
1141
|
+
const [preRequest, updateName] = value;
|
|
1142
|
+
if (!updateName) this.preRequest(preRequest);
|
|
1143
|
+
else this.preRequest(updateName, preRequest);
|
|
1144
|
+
}
|
|
1145
|
+
for (const value of p._.onResponses) {
|
|
1146
|
+
const [onResponse, updateName] = value;
|
|
1147
|
+
if (!updateName) this.onResponse(onResponse);
|
|
1148
|
+
else this.onResponse(updateName, onResponse);
|
|
1149
|
+
}
|
|
1150
|
+
for (const value of p._.onResponseErrors) {
|
|
1151
|
+
const [onResponseError, updateName] = value;
|
|
1152
|
+
if (!updateName) this.onResponseError(onResponseError);
|
|
1153
|
+
else this.onResponseError(updateName, onResponseError);
|
|
1154
|
+
}
|
|
1155
|
+
for (const value of p._.onApiCalls) {
|
|
1156
|
+
const [onApiCall, methods] = value;
|
|
1157
|
+
if (!methods) this.onApiCall(onApiCall);
|
|
1158
|
+
else this.onApiCall(methods, onApiCall);
|
|
1159
|
+
}
|
|
1160
|
+
for (const handler of p._.groups) {
|
|
1161
|
+
this.group(handler);
|
|
1162
|
+
}
|
|
1163
|
+
for (const value of p._.onErrors) {
|
|
1164
|
+
this.onError(value);
|
|
1165
|
+
}
|
|
1166
|
+
for (const value of p._.onStarts) {
|
|
1167
|
+
this.onStart(value);
|
|
1168
|
+
}
|
|
1169
|
+
for (const value of p._.onStops) {
|
|
1170
|
+
this.onStop(value);
|
|
1171
|
+
}
|
|
1172
|
+
this.dependencies.push(p._.name);
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1098
1175
|
return this;
|
|
1099
1176
|
}
|
|
1100
1177
|
const plugin = pluginOrComposer;
|
|
@@ -1783,4 +1860,4 @@ function webhookHandler(bot, framework, secretTokenOrOptions) {
|
|
|
1783
1860
|
|
|
1784
1861
|
Symbol.metadata ??= Symbol("Symbol.metadata");
|
|
1785
1862
|
|
|
1786
|
-
export { AllowedUpdatesFilter, Bot, Composer, ErrorKind, OPT_IN_TYPES, Plugin, TelegramError, Updates, buildAllowedUpdates, detectOptInUpdates, filters, mapEventToAllowedUpdates, webhookHandler };
|
|
1863
|
+
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.
|
|
4
|
+
"version": "0.9.0",
|
|
5
5
|
"description": "Powerful, extensible and really type-safe Telegram Bot API framework",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
7
7
|
"module": "dist/index.js",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"license": "MIT",
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@biomejs/biome": "2.4.4",
|
|
59
|
-
"@gramio/test": "^0.
|
|
59
|
+
"@gramio/test": "^0.5.0",
|
|
60
60
|
"@types/bun": "^1.3.9",
|
|
61
61
|
"@types/debug": "^4.1.12",
|
|
62
62
|
"expect-type": "^1.3.0",
|
|
@@ -65,12 +65,12 @@
|
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
67
|
"@gramio/callback-data": "^0.1.0",
|
|
68
|
-
"@gramio/composer": "0.4.1",
|
|
69
|
-
"@gramio/contexts": "^0.
|
|
70
|
-
"@gramio/files": "^0.
|
|
71
|
-
"@gramio/format": "^0.
|
|
72
|
-
"@gramio/keyboards": "^1.
|
|
73
|
-
"@gramio/types": "^9.
|
|
68
|
+
"@gramio/composer": "^0.4.1",
|
|
69
|
+
"@gramio/contexts": "^0.6.1",
|
|
70
|
+
"@gramio/files": "^0.4.0",
|
|
71
|
+
"@gramio/format": "^0.7.0",
|
|
72
|
+
"@gramio/keyboards": "^1.4.0",
|
|
73
|
+
"@gramio/types": "^9.6.1",
|
|
74
74
|
"debug": "^4.4.3"
|
|
75
75
|
},
|
|
76
76
|
"files": [
|