gramio 0.0.49 → 0.0.51
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 +2 -2
- package/dist/bot.js +13 -16
- package/dist/plugin.d.ts +2 -2
- package/dist/updates.js +9 -10
- package/package.json +6 -6
package/dist/bot.d.ts
CHANGED
|
@@ -138,10 +138,10 @@ export declare class Bot<Errors extends ErrorDefinitions = {}, Derives extends D
|
|
|
138
138
|
* })
|
|
139
139
|
* ```
|
|
140
140
|
*/
|
|
141
|
-
derive<Handler extends Hooks.Derive<Context<typeof this
|
|
141
|
+
derive<Handler extends Hooks.Derive<Context<typeof this> & Derives["global"]>>(handler: Handler): Bot<Errors, Derives & {
|
|
142
142
|
global: Awaited<ReturnType<Handler>>;
|
|
143
143
|
}>;
|
|
144
|
-
derive<Update extends UpdateName, Handler extends Hooks.Derive<ContextType<typeof this, Update
|
|
144
|
+
derive<Update extends UpdateName, Handler extends Hooks.Derive<ContextType<typeof this, Update> & Derives["global"] & Derives[Update]>>(updateName: MaybeArray<Update>, handler: Handler): Bot<Errors, Derives & {
|
|
145
145
|
[K in Update]: Awaited<ReturnType<Handler>>;
|
|
146
146
|
}>;
|
|
147
147
|
decorate<Value extends Record<string, any>>(value: Value): Bot<Errors, Derives & {
|
package/dist/bot.js
CHANGED
|
@@ -38,8 +38,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
38
38
|
};
|
|
39
39
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
40
|
exports.Bot = void 0;
|
|
41
|
-
const node_buffer_1 = require("node:buffer");
|
|
42
41
|
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
42
|
+
const node_stream_1 = require("node:stream");
|
|
43
43
|
const callback_data_1 = require("@gramio/callback-data");
|
|
44
44
|
const contexts_1 = require("@gramio/contexts");
|
|
45
45
|
const files_1 = require("@gramio/files");
|
|
@@ -119,7 +119,7 @@ let Bot = (() => {
|
|
|
119
119
|
};
|
|
120
120
|
errorHandler(context, error) {
|
|
121
121
|
if (!this.hooks.onError.length)
|
|
122
|
-
|
|
122
|
+
return console.error("[Default Error Handler]", context, error);
|
|
123
123
|
return this.runImmutableHooks("onError", {
|
|
124
124
|
context,
|
|
125
125
|
//@ts-expect-error ErrorKind exists if user register error-class with .error("kind", SomeError);
|
|
@@ -253,11 +253,14 @@ let Bot = (() => {
|
|
|
253
253
|
const file = await this.api.getFile({ file_id: fileId });
|
|
254
254
|
const url = `${this.options.api.baseURL.replace("/bot", "/file/bot")}${this.options.token}/${file.file_path}`;
|
|
255
255
|
const res = await fetch(url);
|
|
256
|
-
const buffer = await res.arrayBuffer();
|
|
257
256
|
if (path) {
|
|
258
|
-
|
|
257
|
+
if (!res.body)
|
|
258
|
+
throw new Error("Response without body (should be never throw)");
|
|
259
|
+
// @ts-ignore denoo
|
|
260
|
+
await promises_1.default.writeFile(path, node_stream_1.Readable.fromWeb(res.body));
|
|
259
261
|
return path;
|
|
260
262
|
}
|
|
263
|
+
const buffer = await res.arrayBuffer();
|
|
261
264
|
return buffer;
|
|
262
265
|
}
|
|
263
266
|
/**
|
|
@@ -619,9 +622,7 @@ let Bot = (() => {
|
|
|
619
622
|
if ((typeof trigger === "string" && context.query === trigger) ||
|
|
620
623
|
// @ts-expect-error
|
|
621
624
|
(typeof trigger === "function" && trigger(context)) ||
|
|
622
|
-
(trigger instanceof RegExp &&
|
|
623
|
-
context.query &&
|
|
624
|
-
trigger.test(context.query))) {
|
|
625
|
+
(trigger instanceof RegExp && trigger.test(context.query))) {
|
|
625
626
|
//@ts-expect-error
|
|
626
627
|
context.args =
|
|
627
628
|
trigger instanceof RegExp ? context.query?.match(trigger) : null;
|
|
@@ -675,9 +676,7 @@ let Bot = (() => {
|
|
|
675
676
|
if ((typeof trigger === "string" && context.query === trigger) ||
|
|
676
677
|
// @ts-expect-error
|
|
677
678
|
(typeof trigger === "function" && trigger(context)) ||
|
|
678
|
-
(trigger instanceof RegExp &&
|
|
679
|
-
context.query &&
|
|
680
|
-
trigger.test(context.query))) {
|
|
679
|
+
(trigger instanceof RegExp && trigger.test(context.query))) {
|
|
681
680
|
//@ts-expect-error
|
|
682
681
|
context.args =
|
|
683
682
|
trigger instanceof RegExp ? context.query?.match(trigger) : null;
|
|
@@ -697,15 +696,13 @@ let Bot = (() => {
|
|
|
697
696
|
*/
|
|
698
697
|
hears(trigger, handler) {
|
|
699
698
|
return this.on("message", (context, next) => {
|
|
700
|
-
|
|
699
|
+
const text = context.text ?? context.caption;
|
|
700
|
+
if ((typeof trigger === "string" && text === trigger) ||
|
|
701
701
|
// @ts-expect-error
|
|
702
702
|
(typeof trigger === "function" && trigger(context)) ||
|
|
703
|
-
(trigger instanceof RegExp &&
|
|
704
|
-
context.text &&
|
|
705
|
-
trigger.test(context.text))) {
|
|
703
|
+
(trigger instanceof RegExp && text && trigger.test(text))) {
|
|
706
704
|
//@ts-expect-error
|
|
707
|
-
context.args =
|
|
708
|
-
trigger instanceof RegExp ? context.text?.match(trigger) : null;
|
|
705
|
+
context.args = trigger instanceof RegExp ? text?.match(trigger) : null;
|
|
709
706
|
// TODO: remove
|
|
710
707
|
//@ts-expect-error
|
|
711
708
|
return handler(context);
|
package/dist/plugin.d.ts
CHANGED
|
@@ -106,10 +106,10 @@ export declare class Plugin<Errors extends ErrorDefinitions = {}, Derives extend
|
|
|
106
106
|
* })
|
|
107
107
|
* ```
|
|
108
108
|
*/
|
|
109
|
-
derive<Handler extends Hooks.Derive<Context<AnyBot
|
|
109
|
+
derive<Handler extends Hooks.Derive<Context<AnyBot> & Derives["global"]>>(handler: Handler): Plugin<Errors, Derives & {
|
|
110
110
|
global: Awaited<ReturnType<Handler>>;
|
|
111
111
|
}>;
|
|
112
|
-
derive<Update extends UpdateName, Handler extends Hooks.Derive<ContextType<AnyBot, Update
|
|
112
|
+
derive<Update extends UpdateName, Handler extends Hooks.Derive<ContextType<AnyBot, Update> & Derives["global"] & Derives[Update]>>(updateName: MaybeArray<Update>, handler: Handler): Plugin<Errors, Derives & {
|
|
113
113
|
[K in Update]: Awaited<ReturnType<Handler>>;
|
|
114
114
|
}>;
|
|
115
115
|
decorate<Value extends Record<string, any>>(value: Value): Plugin<Errors, Derives & {
|
package/dist/updates.js
CHANGED
|
@@ -4,7 +4,6 @@ exports.Updates = void 0;
|
|
|
4
4
|
const promises_1 = require("node:timers/promises");
|
|
5
5
|
const contexts_1 = require("@gramio/contexts");
|
|
6
6
|
const composer_1 = require("./composer");
|
|
7
|
-
const errors_1 = require("./errors");
|
|
8
7
|
class Updates {
|
|
9
8
|
bot;
|
|
10
9
|
isStarted = false;
|
|
@@ -65,20 +64,20 @@ class Updates {
|
|
|
65
64
|
}
|
|
66
65
|
async startFetchLoop(params = {}) {
|
|
67
66
|
while (this.isStarted) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
if (updates instanceof errors_1.TelegramError || typeof updates === "undefined") {
|
|
74
|
-
await promises_1.scheduler.wait(this.bot.options.api.retryGetUpdatesWait);
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
67
|
+
try {
|
|
68
|
+
const updates = await this.bot.api.getUpdates({
|
|
69
|
+
...params,
|
|
70
|
+
offset: this.offset,
|
|
71
|
+
});
|
|
77
72
|
for await (const update of updates) {
|
|
78
73
|
//TODO: update errors
|
|
79
74
|
await this.handleUpdate(update).catch(console.error);
|
|
80
75
|
}
|
|
81
76
|
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
console.error("Error received when fetching updates", error);
|
|
79
|
+
await promises_1.scheduler.wait(this.bot.options.api.retryGetUpdatesWait);
|
|
80
|
+
}
|
|
82
81
|
}
|
|
83
82
|
}
|
|
84
83
|
stopPolling() {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gramio",
|
|
3
3
|
"type": "commonjs",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.51",
|
|
5
5
|
"description": "Powerful, extensible and really type-safe Telegram Bot API framework",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
@@ -27,11 +27,11 @@
|
|
|
27
27
|
"author": "kravets",
|
|
28
28
|
"license": "MIT",
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@biomejs/biome": "1.
|
|
31
|
-
"@types/bun": "^1.1.
|
|
30
|
+
"@biomejs/biome": "1.9.1",
|
|
31
|
+
"@types/bun": "^1.1.9",
|
|
32
32
|
"@types/debug": "^4.1.12",
|
|
33
|
-
"pkgroll": "^2.
|
|
34
|
-
"typescript": "^5.
|
|
33
|
+
"pkgroll": "^2.5.0",
|
|
34
|
+
"typescript": "^5.6.2"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@gramio/callback-data": "^0.0.3",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"@gramio/files": "^0.0.12",
|
|
40
40
|
"@gramio/format": "^0.1.3",
|
|
41
41
|
"@gramio/keyboards": "^0.3.3",
|
|
42
|
-
"@gramio/types": "^7.10.
|
|
42
|
+
"@gramio/types": "^7.10.1",
|
|
43
43
|
"debug": "^4.3.7",
|
|
44
44
|
"inspectable": "^3.0.2",
|
|
45
45
|
"middleware-io": "^2.8.1"
|