gramio 0.2.4 → 0.2.5
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 +30 -3
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +31 -4
- package/package.json +7 -7
package/dist/index.cjs
CHANGED
|
@@ -317,6 +317,23 @@ Plugin = __decorateElement$1(_init$1, 0, "Plugin", _Plugin_decorators, Plugin);
|
|
|
317
317
|
__runInitializers$1(_init$1, 1, Plugin);
|
|
318
318
|
|
|
319
319
|
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
320
|
+
function convertToString(value) {
|
|
321
|
+
const typeOfValue = typeof value;
|
|
322
|
+
if (typeOfValue === "string") return value;
|
|
323
|
+
if (typeOfValue === "object") return JSON.stringify(value);
|
|
324
|
+
return String(value);
|
|
325
|
+
}
|
|
326
|
+
function simplifyObject(obj) {
|
|
327
|
+
const result = {};
|
|
328
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
329
|
+
const typeOfValue = typeof value;
|
|
330
|
+
if (value === void 0 || value === null || typeOfValue === "function")
|
|
331
|
+
continue;
|
|
332
|
+
result[key] = convertToString(value);
|
|
333
|
+
}
|
|
334
|
+
return result;
|
|
335
|
+
}
|
|
336
|
+
const IS_BUN = typeof Bun !== "undefined";
|
|
320
337
|
|
|
321
338
|
class UpdateQueue {
|
|
322
339
|
updateQueue = [];
|
|
@@ -574,7 +591,7 @@ class Bot {
|
|
|
574
591
|
}
|
|
575
592
|
async _callApi(method, params = {}) {
|
|
576
593
|
const debug$api$method = debug$api.extend(method);
|
|
577
|
-
|
|
594
|
+
let url = `${this.options.api.baseURL}${this.options.token}/${this.options.api.useTest ? "test/" : ""}${method}`;
|
|
578
595
|
const reqOptions = {
|
|
579
596
|
method: "POST",
|
|
580
597
|
...this.options.api.fetchOptions,
|
|
@@ -592,8 +609,18 @@ class Bot {
|
|
|
592
609
|
);
|
|
593
610
|
params = context.params;
|
|
594
611
|
if (params && files.isMediaUpload(method, params)) {
|
|
595
|
-
|
|
596
|
-
|
|
612
|
+
if (IS_BUN) {
|
|
613
|
+
const formData = await files.convertJsonToFormData(method, params);
|
|
614
|
+
reqOptions.body = formData;
|
|
615
|
+
} else {
|
|
616
|
+
const [formData, paramsWithoutFiles] = await files.extractFilesToFormData(
|
|
617
|
+
method,
|
|
618
|
+
params
|
|
619
|
+
);
|
|
620
|
+
reqOptions.body = formData;
|
|
621
|
+
const simplifiedParams = simplifyObject(paramsWithoutFiles);
|
|
622
|
+
url += `?${new URLSearchParams(simplifiedParams).toString()}`;
|
|
623
|
+
}
|
|
597
624
|
} else {
|
|
598
625
|
reqOptions.headers.set("Content-Type", "application/json");
|
|
599
626
|
reqOptions.body = JSON.stringify(params);
|
package/dist/index.d.cts
CHANGED
|
@@ -944,7 +944,7 @@ declare class Bot<Errors extends ErrorDefinitions = {}, Derives extends DeriveDe
|
|
|
944
944
|
* if (context.args) await context.send(`Params ${context.args[1]}`);
|
|
945
945
|
* });
|
|
946
946
|
*/
|
|
947
|
-
hears<Ctx = ContextType<typeof this, "message"> & Derives["global"] & Derives["message"]
|
|
947
|
+
hears<Ctx = ContextType<typeof this, "message"> & Derives["global"] & Derives["message"], Trigger extends RegExp | string | ((context: Ctx) => boolean) = RegExp | string | ((context: Ctx) => boolean)>(trigger: Trigger, handler: (context: Ctx & {
|
|
948
948
|
args: RegExpMatchArray | null;
|
|
949
949
|
}) => unknown): this;
|
|
950
950
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -944,7 +944,7 @@ declare class Bot<Errors extends ErrorDefinitions = {}, Derives extends DeriveDe
|
|
|
944
944
|
* if (context.args) await context.send(`Params ${context.args[1]}`);
|
|
945
945
|
* });
|
|
946
946
|
*/
|
|
947
|
-
hears<Ctx = ContextType<typeof this, "message"> & Derives["global"] & Derives["message"]
|
|
947
|
+
hears<Ctx = ContextType<typeof this, "message"> & Derives["global"] & Derives["message"], Trigger extends RegExp | string | ((context: Ctx) => boolean) = RegExp | string | ((context: Ctx) => boolean)>(trigger: Trigger, handler: (context: Ctx & {
|
|
948
948
|
args: RegExpMatchArray | null;
|
|
949
949
|
}) => unknown): this;
|
|
950
950
|
/**
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import { CallbackData } from '@gramio/callback-data';
|
|
|
4
4
|
export * from '@gramio/callback-data';
|
|
5
5
|
import { contextsMappings, PhotoAttachment } from '@gramio/contexts';
|
|
6
6
|
export * from '@gramio/contexts';
|
|
7
|
-
import { isMediaUpload, convertJsonToFormData } from '@gramio/files';
|
|
7
|
+
import { isMediaUpload, convertJsonToFormData, extractFilesToFormData } from '@gramio/files';
|
|
8
8
|
export * from '@gramio/files';
|
|
9
9
|
import { FormattableMap } from '@gramio/format';
|
|
10
10
|
export * from '@gramio/format';
|
|
@@ -319,6 +319,23 @@ Plugin = __decorateElement$1(_init$1, 0, "Plugin", _Plugin_decorators, Plugin);
|
|
|
319
319
|
__runInitializers$1(_init$1, 1, Plugin);
|
|
320
320
|
|
|
321
321
|
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
322
|
+
function convertToString(value) {
|
|
323
|
+
const typeOfValue = typeof value;
|
|
324
|
+
if (typeOfValue === "string") return value;
|
|
325
|
+
if (typeOfValue === "object") return JSON.stringify(value);
|
|
326
|
+
return String(value);
|
|
327
|
+
}
|
|
328
|
+
function simplifyObject(obj) {
|
|
329
|
+
const result = {};
|
|
330
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
331
|
+
const typeOfValue = typeof value;
|
|
332
|
+
if (value === void 0 || value === null || typeOfValue === "function")
|
|
333
|
+
continue;
|
|
334
|
+
result[key] = convertToString(value);
|
|
335
|
+
}
|
|
336
|
+
return result;
|
|
337
|
+
}
|
|
338
|
+
const IS_BUN = typeof Bun !== "undefined";
|
|
322
339
|
|
|
323
340
|
class UpdateQueue {
|
|
324
341
|
updateQueue = [];
|
|
@@ -576,7 +593,7 @@ class Bot {
|
|
|
576
593
|
}
|
|
577
594
|
async _callApi(method, params = {}) {
|
|
578
595
|
const debug$api$method = debug$api.extend(method);
|
|
579
|
-
|
|
596
|
+
let url = `${this.options.api.baseURL}${this.options.token}/${this.options.api.useTest ? "test/" : ""}${method}`;
|
|
580
597
|
const reqOptions = {
|
|
581
598
|
method: "POST",
|
|
582
599
|
...this.options.api.fetchOptions,
|
|
@@ -594,8 +611,18 @@ class Bot {
|
|
|
594
611
|
);
|
|
595
612
|
params = context.params;
|
|
596
613
|
if (params && isMediaUpload(method, params)) {
|
|
597
|
-
|
|
598
|
-
|
|
614
|
+
if (IS_BUN) {
|
|
615
|
+
const formData = await convertJsonToFormData(method, params);
|
|
616
|
+
reqOptions.body = formData;
|
|
617
|
+
} else {
|
|
618
|
+
const [formData, paramsWithoutFiles] = await extractFilesToFormData(
|
|
619
|
+
method,
|
|
620
|
+
params
|
|
621
|
+
);
|
|
622
|
+
reqOptions.body = formData;
|
|
623
|
+
const simplifiedParams = simplifyObject(paramsWithoutFiles);
|
|
624
|
+
url += `?${new URLSearchParams(simplifiedParams).toString()}`;
|
|
625
|
+
}
|
|
599
626
|
} else {
|
|
600
627
|
reqOptions.headers.set("Content-Type", "application/json");
|
|
601
628
|
reqOptions.body = JSON.stringify(params);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gramio",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.5",
|
|
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",
|
|
@@ -41,18 +41,18 @@
|
|
|
41
41
|
"license": "MIT",
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@biomejs/biome": "1.9.4",
|
|
44
|
-
"@types/bun": "^1.2.
|
|
44
|
+
"@types/bun": "^1.2.5",
|
|
45
45
|
"@types/debug": "^4.1.12",
|
|
46
|
-
"pkgroll": "^2.
|
|
47
|
-
"typescript": "^5.
|
|
46
|
+
"pkgroll": "^2.11.2",
|
|
47
|
+
"typescript": "^5.8.2"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"@gramio/callback-data": "^0.0.3",
|
|
51
|
-
"@gramio/contexts": "^0.1.
|
|
52
|
-
"@gramio/files": "^0.
|
|
51
|
+
"@gramio/contexts": "^0.1.4",
|
|
52
|
+
"@gramio/files": "^0.2.0",
|
|
53
53
|
"@gramio/format": "^0.1.5",
|
|
54
54
|
"@gramio/keyboards": "^1.1.0",
|
|
55
|
-
"@gramio/types": "^8.3.
|
|
55
|
+
"@gramio/types": "^8.3.3",
|
|
56
56
|
"debug": "^4.4.0",
|
|
57
57
|
"inspectable": "^3.0.2",
|
|
58
58
|
"middleware-io": "^2.8.1"
|