gramio 0.0.23 → 0.0.24
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/bot.d.ts +5 -2
- package/dist/bot.js +20 -2
- package/dist/types.d.ts +5 -0
- package/package.json +2 -2
package/dist/bot.d.ts
CHANGED
|
@@ -79,7 +79,7 @@ export declare class Bot<Errors extends ErrorDefinitions = {}, Derives extends D
|
|
|
79
79
|
extend<NewPlugin extends Plugin<any, any>>(plugin: MaybePromise<NewPlugin>): Bot<Errors & NewPlugin["Errors"], Derives & NewPlugin["Derives"]>;
|
|
80
80
|
reaction(trigger: MaybeArray<TelegramReactionTypeEmojiEmoji>, handler: (context: ContextType<typeof this, "message_reaction"> & Derives["global"] & Derives["message_reaction"]) => unknown): this;
|
|
81
81
|
callbackQuery<Trigger extends CallbackData | string | RegExp>(trigger: Trigger, handler: (context: Omit<ContextType<typeof this, "callback_query">, "data"> & Derives["global"] & Derives["callback_query"] & {
|
|
82
|
-
|
|
82
|
+
queryData: Trigger extends CallbackData ? ReturnType<Trigger["unpack"]> : RegExpMatchArray | null;
|
|
83
83
|
}) => unknown): this;
|
|
84
84
|
hears<Ctx = ContextType<typeof this, "message"> & Derives["global"] & Derives["message"]>(trigger: RegExp | string | ((context: Ctx) => boolean), handler: (context: Ctx & {
|
|
85
85
|
args: RegExpMatchArray | null;
|
|
@@ -89,9 +89,12 @@ export declare class Bot<Errors extends ErrorDefinitions = {}, Derives extends D
|
|
|
89
89
|
}) => unknown, options?: Omit<SetMyCommandsParams, "commands"> & Omit<TelegramBotCommand, "command">): this;
|
|
90
90
|
/** Currently not isolated!!! */
|
|
91
91
|
group(grouped: (bot: typeof this) => Bot<any, any>): Bot<any, any>;
|
|
92
|
+
init(): Promise<void>;
|
|
92
93
|
start({ webhook, dropPendingUpdates, allowedUpdates, }?: {
|
|
93
94
|
webhook?: Omit<APIMethodParams<"setWebhook">, "drop_pending_updates" | "allowed_updates">;
|
|
94
95
|
dropPendingUpdates?: boolean;
|
|
95
96
|
allowedUpdates?: NonNullable<APIMethodParams<"getUpdates">>["allowed_updates"];
|
|
96
|
-
}): Promise<TelegramUser>;
|
|
97
|
+
}): Promise<TelegramUser | undefined>;
|
|
98
|
+
/** Currently does not implement graceful shutdown */
|
|
99
|
+
stop(): Promise<void>;
|
|
97
100
|
}
|
package/dist/bot.js
CHANGED
|
@@ -84,6 +84,7 @@ let Bot = (() => {
|
|
|
84
84
|
preRequest: [],
|
|
85
85
|
onError: [],
|
|
86
86
|
onStart: [],
|
|
87
|
+
onStop: [],
|
|
87
88
|
};
|
|
88
89
|
constructor(token, options) {
|
|
89
90
|
if (!token || typeof token !== "string")
|
|
@@ -316,7 +317,7 @@ let Bot = (() => {
|
|
|
316
317
|
if (trigger instanceof RegExp && !trigger.test(context.data))
|
|
317
318
|
return next();
|
|
318
319
|
// @ts-expect-error
|
|
319
|
-
context.
|
|
320
|
+
context.queryData = trigger.unpack(context.data);
|
|
320
321
|
//@ts-expect-error
|
|
321
322
|
return handler(context);
|
|
322
323
|
});
|
|
@@ -364,9 +365,12 @@ let Bot = (() => {
|
|
|
364
365
|
group(grouped) {
|
|
365
366
|
return grouped(this);
|
|
366
367
|
}
|
|
367
|
-
async
|
|
368
|
+
async init() {
|
|
368
369
|
await Promise.all(this.lazyloadPlugins.map(async (plugin) => this.extend(await plugin)));
|
|
369
370
|
this.info = await this.api.getMe();
|
|
371
|
+
}
|
|
372
|
+
async start({ webhook, dropPendingUpdates, allowedUpdates, } = {}) {
|
|
373
|
+
await this.init();
|
|
370
374
|
if (!webhook) {
|
|
371
375
|
await this.api.deleteWebhook({
|
|
372
376
|
drop_pending_updates: dropPendingUpdates,
|
|
@@ -376,6 +380,7 @@ let Bot = (() => {
|
|
|
376
380
|
});
|
|
377
381
|
this.runImmutableHooks("onStart", {
|
|
378
382
|
plugins: this.dependencies,
|
|
383
|
+
// biome-ignore lint/style/noNonNullAssertion: bot.init() guarantees this.info
|
|
379
384
|
info: this.info,
|
|
380
385
|
updatesFrom: "long-polling",
|
|
381
386
|
});
|
|
@@ -390,11 +395,24 @@ let Bot = (() => {
|
|
|
390
395
|
});
|
|
391
396
|
this.runImmutableHooks("onStart", {
|
|
392
397
|
plugins: this.dependencies,
|
|
398
|
+
// biome-ignore lint/style/noNonNullAssertion: bot.init() guarantees this.info
|
|
393
399
|
info: this.info,
|
|
394
400
|
updatesFrom: "webhook",
|
|
395
401
|
});
|
|
396
402
|
return this.info;
|
|
397
403
|
}
|
|
404
|
+
/** Currently does not implement graceful shutdown */
|
|
405
|
+
async stop() {
|
|
406
|
+
if (this.updates.isStarted)
|
|
407
|
+
this.updates.stopPolling();
|
|
408
|
+
else
|
|
409
|
+
await this.api.deleteWebhook();
|
|
410
|
+
await this.runImmutableHooks("onStop", {
|
|
411
|
+
plugins: this.dependencies,
|
|
412
|
+
// biome-ignore lint/style/noNonNullAssertion: bot.init() guarantees this.info
|
|
413
|
+
info: this.info,
|
|
414
|
+
});
|
|
415
|
+
}
|
|
398
416
|
};
|
|
399
417
|
return Bot = _classThis;
|
|
400
418
|
})();
|
package/dist/types.d.ts
CHANGED
|
@@ -37,10 +37,15 @@ export declare namespace Hooks {
|
|
|
37
37
|
info: TelegramUser;
|
|
38
38
|
updatesFrom: "webhook" | "long-polling";
|
|
39
39
|
}) => unknown;
|
|
40
|
+
type OnStop = (context: {
|
|
41
|
+
plugins: string[];
|
|
42
|
+
info: TelegramUser;
|
|
43
|
+
}) => unknown;
|
|
40
44
|
interface Store<T extends ErrorDefinitions> {
|
|
41
45
|
preRequest: PreRequest[];
|
|
42
46
|
onError: OnError<T>[];
|
|
43
47
|
onStart: OnStart[];
|
|
48
|
+
onStop: OnStop[];
|
|
44
49
|
}
|
|
45
50
|
}
|
|
46
51
|
export type ErrorDefinitions = Record<string, Error>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gramio",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.24",
|
|
4
4
|
"description": "Powerful Telegram Bot API framework",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"typescript": "^5.4.3"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@gramio/callback-data": "^0.0.
|
|
33
|
+
"@gramio/callback-data": "^0.0.2",
|
|
34
34
|
"@gramio/contexts": "^0.0.7",
|
|
35
35
|
"@gramio/files": "^0.0.3",
|
|
36
36
|
"@gramio/format": "^0.0.8",
|