@green-api/greenapi-integration 0.10.0 → 0.10.1
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.
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.GreenApiClient = void 0;
|
|
7
7
|
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const mime_types_1 = require("mime-types");
|
|
8
9
|
const errors_1 = require("./errors");
|
|
9
10
|
const logger_1 = require("./logger");
|
|
10
11
|
const defaults_1 = require("../defaults");
|
|
@@ -50,8 +51,18 @@ class GreenApiClient {
|
|
|
50
51
|
buildUrl(host) {
|
|
51
52
|
return `${host}/waInstance${this.instance.idInstance}`;
|
|
52
53
|
}
|
|
53
|
-
|
|
54
|
-
|
|
54
|
+
mimeType(data, fileName) {
|
|
55
|
+
if (data instanceof Blob && data.type) {
|
|
56
|
+
return data.type;
|
|
57
|
+
}
|
|
58
|
+
return (fileName && (0, mime_types_1.lookup)(fileName)) || undefined;
|
|
59
|
+
}
|
|
60
|
+
toBlob(data, fileName) {
|
|
61
|
+
const type = this.mimeType(data, fileName);
|
|
62
|
+
if (data instanceof Blob && (data.type || !type)) {
|
|
63
|
+
return data;
|
|
64
|
+
}
|
|
65
|
+
return new Blob([data instanceof Blob ? data : data], type ? { type } : undefined);
|
|
55
66
|
}
|
|
56
67
|
toBuffer(data) {
|
|
57
68
|
return Buffer.isBuffer(data) ? data : Buffer.from(data.buffer, data.byteOffset, data.byteLength);
|
|
@@ -167,7 +178,7 @@ class GreenApiClient {
|
|
|
167
178
|
*/
|
|
168
179
|
async sendFileByUpload(message) {
|
|
169
180
|
const formData = new FormData();
|
|
170
|
-
formData.append("file", this.toBlob(message.file.data), message.file.fileName);
|
|
181
|
+
formData.append("file", this.toBlob(message.file.data, message.file.fileName), message.file.fileName);
|
|
171
182
|
formData.append("chatId", message.chatId);
|
|
172
183
|
formData.append("fileName", message.file.fileName);
|
|
173
184
|
if (message.caption)
|
|
@@ -432,12 +443,9 @@ class GreenApiClient {
|
|
|
432
443
|
* @returns Promise resolving to upload response with file URL
|
|
433
444
|
*/
|
|
434
445
|
async uploadFile(file, fileName) {
|
|
435
|
-
const mimeType = file
|
|
436
|
-
const headers = {};
|
|
437
|
-
if (mimeType) {
|
|
438
|
-
headers["Content-Type"] = mimeType;
|
|
439
|
-
}
|
|
440
|
-
else if (fileName) {
|
|
446
|
+
const mimeType = this.mimeType(file, fileName);
|
|
447
|
+
const headers = { "Content-Type": mimeType || false };
|
|
448
|
+
if (!mimeType && fileName) {
|
|
441
449
|
headers["GA-Filename"] = fileName;
|
|
442
450
|
}
|
|
443
451
|
const body = file instanceof Blob ? Buffer.from(await file.arrayBuffer()) : this.toBuffer(file);
|
|
@@ -453,7 +461,7 @@ class GreenApiClient {
|
|
|
453
461
|
*/
|
|
454
462
|
async requestWithFile(endpoint, file, fields = {}) {
|
|
455
463
|
const formData = new FormData();
|
|
456
|
-
formData.append("file", this.toBlob(file.data), file.fileName);
|
|
464
|
+
formData.append("file", this.toBlob(file.data, file.fileName), file.fileName);
|
|
457
465
|
for (const [key, value] of Object.entries(fields)) {
|
|
458
466
|
formData.append(key, String(value));
|
|
459
467
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@green-api/greenapi-integration",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.1",
|
|
4
4
|
"description": "GREEN-API Integration library",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
"license": "MIT",
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@types/jest": "^30.0.0",
|
|
28
|
+
"@types/mime-types": "^3.0.1",
|
|
28
29
|
"@types/node": "^22.20.5",
|
|
29
30
|
"jest": "^30.5.2",
|
|
30
31
|
"rimraf": "^6.1.3",
|
|
@@ -34,6 +35,7 @@
|
|
|
34
35
|
"typescript": "^6.0.3"
|
|
35
36
|
},
|
|
36
37
|
"dependencies": {
|
|
37
|
-
"axios": "^1.20.0"
|
|
38
|
+
"axios": "^1.20.0",
|
|
39
|
+
"mime-types": "^3.0.2"
|
|
38
40
|
}
|
|
39
41
|
}
|