gramio 0.0.39 → 0.0.41
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.js +15 -2
- package/dist/types.d.ts +5 -0
- package/dist/updates.js +11 -3
- package/dist/webhook/index.d.ts +1 -44
- package/dist/webhook/index.js +1 -2
- package/package.json +9 -6
package/dist/bot.js
CHANGED
|
@@ -44,11 +44,14 @@ const callback_data_1 = require("@gramio/callback-data");
|
|
|
44
44
|
const contexts_1 = require("@gramio/contexts");
|
|
45
45
|
const files_1 = require("@gramio/files");
|
|
46
46
|
const format_1 = require("@gramio/format");
|
|
47
|
+
const debug_1 = __importDefault(require("debug"));
|
|
47
48
|
const inspectable_1 = require("inspectable");
|
|
48
49
|
const undici_1 = require("undici");
|
|
49
50
|
const errors_1 = require("./errors");
|
|
50
51
|
const plugin_1 = require("./plugin");
|
|
51
52
|
const updates_1 = require("./updates");
|
|
53
|
+
const $debugger = (0, debug_1.default)("gramio");
|
|
54
|
+
const debug$api = $debugger.extend("api");
|
|
52
55
|
/** Bot instance
|
|
53
56
|
*
|
|
54
57
|
* @example
|
|
@@ -134,7 +137,11 @@ let Bot = (() => {
|
|
|
134
137
|
this.options = {
|
|
135
138
|
...(typeof tokenOrOptions === "object" ? tokenOrOptions : options),
|
|
136
139
|
token,
|
|
137
|
-
api: {
|
|
140
|
+
api: {
|
|
141
|
+
baseURL: "https://api.telegram.org/bot",
|
|
142
|
+
retryGetUpdatesWait: 1000,
|
|
143
|
+
...options?.api,
|
|
144
|
+
},
|
|
138
145
|
};
|
|
139
146
|
if (!(options?.plugins &&
|
|
140
147
|
"format" in options.plugins &&
|
|
@@ -142,6 +149,7 @@ let Bot = (() => {
|
|
|
142
149
|
this.extend(new plugin_1.Plugin("@gramio/format").preRequest((context) => {
|
|
143
150
|
if (!context.params)
|
|
144
151
|
return context;
|
|
152
|
+
// @ts-ignore
|
|
145
153
|
const formattable = format_1.FormattableMap[context.method];
|
|
146
154
|
// @ts-ignore add AnyTelegramMethod to @gramio/format
|
|
147
155
|
if (formattable)
|
|
@@ -164,6 +172,7 @@ let Bot = (() => {
|
|
|
164
172
|
}
|
|
165
173
|
}
|
|
166
174
|
async _callApi(method, params = {}) {
|
|
175
|
+
const debug$api$method = debug$api.extend(method);
|
|
167
176
|
const url = `${this.options.api.baseURL}${this.options.token}/${method}`;
|
|
168
177
|
const reqOptions = {
|
|
169
178
|
method: "POST",
|
|
@@ -177,7 +186,9 @@ let Bot = (() => {
|
|
|
177
186
|
});
|
|
178
187
|
// biome-ignore lint/style/noParameterAssign: mutate params
|
|
179
188
|
params = context.params;
|
|
189
|
+
// @ts-ignore
|
|
180
190
|
if (params && (0, files_1.isMediaUpload)(method, params)) {
|
|
191
|
+
// @ts-ignore
|
|
181
192
|
const formData = await (0, files_1.convertJsonToFormData)(method, params);
|
|
182
193
|
reqOptions.body = formData;
|
|
183
194
|
}
|
|
@@ -187,8 +198,10 @@ let Bot = (() => {
|
|
|
187
198
|
};
|
|
188
199
|
reqOptions.body = JSON.stringify(params);
|
|
189
200
|
}
|
|
201
|
+
debug$api$method("options: %j", reqOptions);
|
|
190
202
|
const response = await (0, undici_1.request)(url, reqOptions);
|
|
191
203
|
const data = (await response.body.json());
|
|
204
|
+
debug$api$method("response: %j", data);
|
|
192
205
|
if (!data.ok) {
|
|
193
206
|
const err = new errors_1.TelegramError(data, method, params);
|
|
194
207
|
// @ts-expect-error
|
|
@@ -675,7 +688,7 @@ let Bot = (() => {
|
|
|
675
688
|
?.replace(`@${this.info.username}`, "");
|
|
676
689
|
// @ts-expect-error
|
|
677
690
|
context.args = context.text?.slice(entity.length).trim() || null;
|
|
678
|
-
return cmd
|
|
691
|
+
return cmd === command;
|
|
679
692
|
}))
|
|
680
693
|
// @ts-expect-error
|
|
681
694
|
return handler(context);
|
package/dist/types.d.ts
CHANGED
package/dist/updates.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Updates = void 0;
|
|
4
|
+
const promises_1 = require("node:timers/promises");
|
|
4
5
|
const contexts_1 = require("@gramio/contexts");
|
|
5
6
|
const composer_1 = require("./composer");
|
|
7
|
+
const errors_1 = require("./errors");
|
|
6
8
|
class Updates {
|
|
7
9
|
bot;
|
|
8
10
|
isStarted = false;
|
|
@@ -66,10 +68,16 @@ class Updates {
|
|
|
66
68
|
const updates = await this.bot.api.getUpdates({
|
|
67
69
|
...params,
|
|
68
70
|
offset: this.offset,
|
|
71
|
+
suppress: true,
|
|
69
72
|
});
|
|
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 {
|
|
77
|
+
for await (const update of updates) {
|
|
78
|
+
//TODO: update errors
|
|
79
|
+
await this.handleUpdate(update).catch(console.error);
|
|
80
|
+
}
|
|
73
81
|
}
|
|
74
82
|
}
|
|
75
83
|
}
|
package/dist/webhook/index.d.ts
CHANGED
|
@@ -30,49 +30,6 @@ export type WebhookHandlers = keyof typeof frameworks;
|
|
|
30
30
|
* });
|
|
31
31
|
* ```
|
|
32
32
|
*/
|
|
33
|
-
export declare function webhookHandler<Framework extends keyof typeof frameworks>(bot: Bot, framework: Framework, secretToken?: string): ReturnType<{
|
|
34
|
-
elysia: ({ body, headers }: any) => {
|
|
35
|
-
update: any;
|
|
36
|
-
header: any;
|
|
37
|
-
unauthorized: () => import("undici").Response;
|
|
38
|
-
};
|
|
39
|
-
fastify: (request: any, reply: any) => {
|
|
40
|
-
update: any;
|
|
41
|
-
header: any;
|
|
42
|
-
unauthorized: () => any;
|
|
43
|
-
};
|
|
44
|
-
hono: (c: any) => {
|
|
45
|
-
update: any;
|
|
46
|
-
header: any;
|
|
47
|
-
unauthorized: () => any;
|
|
48
|
-
};
|
|
49
|
-
express: (req: any, res: any) => {
|
|
50
|
-
update: any;
|
|
51
|
-
header: any;
|
|
52
|
-
unauthorized: () => any;
|
|
53
|
-
};
|
|
54
|
-
koa: (ctx: any) => {
|
|
55
|
-
update: any;
|
|
56
|
-
header: any;
|
|
57
|
-
unauthorized: () => void;
|
|
58
|
-
};
|
|
59
|
-
http: (req: any, res: any) => {
|
|
60
|
-
update: Promise<import("@gramio/types").TelegramUpdate>;
|
|
61
|
-
header: any;
|
|
62
|
-
unauthorized: () => any;
|
|
63
|
-
};
|
|
64
|
-
"std/http": (req: any) => {
|
|
65
|
-
update: any;
|
|
66
|
-
header: any;
|
|
67
|
-
response: () => import("undici").Response;
|
|
68
|
-
unauthorized: () => import("undici").Response;
|
|
69
|
-
};
|
|
70
|
-
"Bun.serve": (req: any) => {
|
|
71
|
-
update: any;
|
|
72
|
-
header: any;
|
|
73
|
-
response: () => import("undici").Response;
|
|
74
|
-
unauthorized: () => import("undici").Response;
|
|
75
|
-
};
|
|
76
|
-
}[Framework]> extends {
|
|
33
|
+
export declare function webhookHandler<Framework extends keyof typeof frameworks>(bot: Bot, framework: Framework, secretToken?: string): ReturnType<(typeof frameworks)[Framework]> extends {
|
|
77
34
|
response: () => any;
|
|
78
35
|
} ? (...args: Parameters<(typeof frameworks)[Framework]>) => ReturnType<ReturnType<(typeof frameworks)[Framework]>["response"]> : (...args: Parameters<(typeof frameworks)[Framework]>) => void;
|
package/dist/webhook/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.webhookHandler =
|
|
3
|
+
exports.webhookHandler = webhookHandler;
|
|
4
4
|
const adapters_1 = require("./adapters");
|
|
5
5
|
/**
|
|
6
6
|
* Setup handler with yours web-framework to receive updates via webhook
|
|
@@ -44,4 +44,3 @@ function webhookHandler(bot, framework, secretToken) {
|
|
|
44
44
|
return response();
|
|
45
45
|
});
|
|
46
46
|
}
|
|
47
|
-
exports.webhookHandler = webhookHandler;
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gramio",
|
|
3
|
-
"
|
|
3
|
+
"type": "commonjs",
|
|
4
|
+
"version": "0.0.41",
|
|
4
5
|
"description": "Powerful Telegram Bot API framework",
|
|
5
6
|
"main": "./dist/index.js",
|
|
6
7
|
"types": "./dist/index.d.ts",
|
|
@@ -27,8 +28,9 @@
|
|
|
27
28
|
"license": "ISC",
|
|
28
29
|
"devDependencies": {
|
|
29
30
|
"@biomejs/biome": "1.7.3",
|
|
30
|
-
"@types/
|
|
31
|
-
"
|
|
31
|
+
"@types/debug": "^4.1.12",
|
|
32
|
+
"@types/node": "^20.14.9",
|
|
33
|
+
"typescript": "^5.5.2"
|
|
32
34
|
},
|
|
33
35
|
"dependencies": {
|
|
34
36
|
"@gramio/callback-data": "^0.0.3",
|
|
@@ -36,10 +38,11 @@
|
|
|
36
38
|
"@gramio/files": "^0.0.8",
|
|
37
39
|
"@gramio/format": "^0.1.3",
|
|
38
40
|
"@gramio/keyboards": "^0.3.3",
|
|
39
|
-
"@gramio/types": "^7.
|
|
40
|
-
"
|
|
41
|
+
"@gramio/types": "^7.5.0",
|
|
42
|
+
"debug": "^4.3.5",
|
|
43
|
+
"inspectable": "^3.0.2",
|
|
41
44
|
"middleware-io": "^2.8.1",
|
|
42
|
-
"undici": "^6.
|
|
45
|
+
"undici": "^6.19.2"
|
|
43
46
|
},
|
|
44
47
|
"files": [
|
|
45
48
|
"dist"
|