@gamastudio/sendwave-provider 0.0.10 → 0.0.13
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/build/package.json +8 -8
- package/build/provider/core.js +22 -16
- package/build/provider/provider.d.ts +8 -0
- package/build/provider/provider.js +85 -17
- package/build/provider/sender.js +47 -14
- package/build/utils/parserMsg.js +1 -1
- package/package.json +8 -8
package/build/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gamastudio/sendwave-provider",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.13",
|
|
4
4
|
"description": "Librería para interactuar con Sendwave usando configuración dinámica.",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -23,26 +23,26 @@
|
|
|
23
23
|
"license": "ISC",
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@builderbot/bot": "^1.2.9",
|
|
26
|
-
"@gamastudio/colorslog": "^0.1.
|
|
27
|
-
"@types/mime-types": "^
|
|
28
|
-
"axios": "^1.
|
|
26
|
+
"@gamastudio/colorslog": "^0.1.8",
|
|
27
|
+
"@types/mime-types": "^3.0.1",
|
|
28
|
+
"axios": "^1.13.2",
|
|
29
29
|
"body-parser": "^2.2.0",
|
|
30
30
|
"cors": "^2.8.5",
|
|
31
|
-
"file-type": "^
|
|
31
|
+
"file-type": "^21.1.0",
|
|
32
32
|
"mime-types": "^3.0.1",
|
|
33
33
|
"queue-promise": "^2.2.1",
|
|
34
|
-
"sirv": "^3.0.
|
|
34
|
+
"sirv": "^3.0.2"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@types/axios": "^0.14.4",
|
|
38
38
|
"@types/body-parser": "^1.19.6",
|
|
39
39
|
"@types/cors": "^2.8.19",
|
|
40
|
-
"@types/node": "^
|
|
40
|
+
"@types/node": "^24.10.1",
|
|
41
41
|
"copyfiles": "^2.4.1",
|
|
42
42
|
"ts-node": "^10.9.2",
|
|
43
43
|
"ts-node-dev": "^2.0.0",
|
|
44
44
|
"tsc-alias": "^1.8.16",
|
|
45
45
|
"tsconfig-paths": "^4.2.0",
|
|
46
|
-
"typescript": "^5.9.
|
|
46
|
+
"typescript": "^5.9.3"
|
|
47
47
|
}
|
|
48
48
|
}
|
package/build/provider/core.js
CHANGED
|
@@ -33,6 +33,12 @@ class SendWaveCore extends node_events_1.EventEmitter {
|
|
|
33
33
|
var _a;
|
|
34
34
|
try {
|
|
35
35
|
const { body } = req;
|
|
36
|
+
if ((body === null || body === void 0 ? void 0 : body.event) === "qrcode.updated") {
|
|
37
|
+
if (body === null || body === void 0 ? void 0 : body.base64)
|
|
38
|
+
this.emitQR(body.base64);
|
|
39
|
+
this.emit("qr-update-request", { event: body.event });
|
|
40
|
+
return res.end("QR update processed");
|
|
41
|
+
}
|
|
36
42
|
if (!["messages.upsert", "send_message"].includes(body.event)) {
|
|
37
43
|
return res.end("Message queued");
|
|
38
44
|
}
|
|
@@ -55,33 +61,33 @@ class SendWaveCore extends node_events_1.EventEmitter {
|
|
|
55
61
|
catch (e) {
|
|
56
62
|
console.error("[IncomingMsg Error]:", e);
|
|
57
63
|
// Handle PayloadTooLargeError specifically
|
|
58
|
-
if (e.name ===
|
|
59
|
-
console.error(`[PayloadTooLarge] Request from ${req.ip ||
|
|
64
|
+
if (e.name === "PayloadTooLargeError" || e.type === "entity.too.large") {
|
|
65
|
+
console.error(`[PayloadTooLarge] Request from ${req.ip || "unknown"} exceeded size limit`);
|
|
60
66
|
res.statusCode = 413;
|
|
61
|
-
res.setHeader(
|
|
67
|
+
res.setHeader("Content-Type", "application/json");
|
|
62
68
|
return res.end(JSON.stringify({
|
|
63
|
-
error:
|
|
64
|
-
message:
|
|
65
|
-
code:
|
|
69
|
+
error: "Payload too large",
|
|
70
|
+
message: "El archivo o mensaje es demasiado grande",
|
|
71
|
+
code: "PAYLOAD_TOO_LARGE",
|
|
66
72
|
}));
|
|
67
73
|
}
|
|
68
74
|
// Handle timeout errors
|
|
69
|
-
if (e.type ===
|
|
70
|
-
console.error(`[RequestTimeout] Request from ${req.ip ||
|
|
75
|
+
if (e.type === "request.timeout") {
|
|
76
|
+
console.error(`[RequestTimeout] Request from ${req.ip || "unknown"} timed out`);
|
|
71
77
|
res.statusCode = 408;
|
|
72
|
-
res.setHeader(
|
|
78
|
+
res.setHeader("Content-Type", "application/json");
|
|
73
79
|
return res.end(JSON.stringify({
|
|
74
|
-
error:
|
|
75
|
-
message:
|
|
76
|
-
code:
|
|
80
|
+
error: "Request timeout",
|
|
81
|
+
message: "La solicitud ha tardado demasiado",
|
|
82
|
+
code: "REQUEST_TIMEOUT",
|
|
77
83
|
}));
|
|
78
84
|
}
|
|
79
85
|
res.statusCode = 500;
|
|
80
|
-
res.setHeader(
|
|
86
|
+
res.setHeader("Content-Type", "application/json");
|
|
81
87
|
return res.end(JSON.stringify({
|
|
82
|
-
error:
|
|
83
|
-
message:
|
|
84
|
-
code:
|
|
88
|
+
error: "Internal Server Error",
|
|
89
|
+
message: "Error interno del servidor",
|
|
90
|
+
code: "INTERNAL_ERROR",
|
|
85
91
|
}));
|
|
86
92
|
}
|
|
87
93
|
};
|
|
@@ -12,6 +12,12 @@ export declare class SendWaveProvider extends ProviderClass<SendWaveCore> {
|
|
|
12
12
|
state: Boolean;
|
|
13
13
|
instanceConnected: Boolean;
|
|
14
14
|
sender: SenderMessage;
|
|
15
|
+
private rateLimits;
|
|
16
|
+
private rateLimitConfig;
|
|
17
|
+
private queueOptions;
|
|
18
|
+
private connectionPollIntervalMs;
|
|
19
|
+
private connectionPollTimer?;
|
|
20
|
+
private lastReadyState?;
|
|
15
21
|
globalVendorArgs: GlobalVendorArgs;
|
|
16
22
|
constructor(args: Partial<GlobalVendorArgs>);
|
|
17
23
|
private setupGlobalErrorHandlers;
|
|
@@ -19,6 +25,8 @@ export declare class SendWaveProvider extends ProviderClass<SendWaveCore> {
|
|
|
19
25
|
protected beforeHttpServerInit: () => Promise<void>;
|
|
20
26
|
protected getApiQrConnect: () => Promise<void>;
|
|
21
27
|
protected afterHttpServerInit(): Promise<void>;
|
|
28
|
+
private startConnectionPolling;
|
|
29
|
+
private stopConnectionPolling;
|
|
22
30
|
saveFile(_: any, options?: {
|
|
23
31
|
path: string;
|
|
24
32
|
}): Promise<string>;
|
|
@@ -23,6 +23,10 @@ class SendWaveProvider extends bot_1.ProviderClass {
|
|
|
23
23
|
this.queue = new queue_promise_1.default();
|
|
24
24
|
this.state = false;
|
|
25
25
|
this.instanceConnected = false;
|
|
26
|
+
this.rateLimits = new Map();
|
|
27
|
+
this.rateLimitConfig = { windowMs: 60 * 1000, max: 120 };
|
|
28
|
+
this.queueOptions = { concurrent: 50, interval: 100 };
|
|
29
|
+
this.connectionPollIntervalMs = 2000;
|
|
26
30
|
this.globalVendorArgs = {
|
|
27
31
|
name: "bot",
|
|
28
32
|
url: "https://sendwave-api.gamastudio.co",
|
|
@@ -79,6 +83,24 @@ class SendWaveProvider extends bot_1.ProviderClass {
|
|
|
79
83
|
})
|
|
80
84
|
.use((0, cors_1.default)({ origin: "*", methods: "GET,POST" }))
|
|
81
85
|
.use("/assets", assets)
|
|
86
|
+
.use((req, res, next) => {
|
|
87
|
+
var _a;
|
|
88
|
+
const ip = (req.ip || req.headers['x-forwarded-for'] || ((_a = req.connection) === null || _a === void 0 ? void 0 : _a.remoteAddress) || 'unknown').toString();
|
|
89
|
+
const now = Date.now();
|
|
90
|
+
const rec = this.rateLimits.get(ip) || { count: 0, windowStart: now };
|
|
91
|
+
if (now - rec.windowStart > this.rateLimitConfig.windowMs) {
|
|
92
|
+
rec.count = 0;
|
|
93
|
+
rec.windowStart = now;
|
|
94
|
+
}
|
|
95
|
+
rec.count += 1;
|
|
96
|
+
this.rateLimits.set(ip, rec);
|
|
97
|
+
if (rec.count > this.rateLimitConfig.max) {
|
|
98
|
+
res.statusCode = 429;
|
|
99
|
+
res.setHeader('Content-Type', 'application/json');
|
|
100
|
+
return res.end(JSON.stringify({ error: 'Too Many Requests' }));
|
|
101
|
+
}
|
|
102
|
+
next();
|
|
103
|
+
})
|
|
82
104
|
.get("/", async (req, res) => {
|
|
83
105
|
if (this.state && this.instanceConnected) {
|
|
84
106
|
await this.afterHttpServerInit();
|
|
@@ -92,6 +114,23 @@ class SendWaveProvider extends bot_1.ProviderClass {
|
|
|
92
114
|
else {
|
|
93
115
|
}
|
|
94
116
|
return this.vendor.indexError(req, res);
|
|
117
|
+
})
|
|
118
|
+
.get("/health", async (_, res) => {
|
|
119
|
+
res.setHeader('Content-Type', 'application/json');
|
|
120
|
+
res.end(JSON.stringify({
|
|
121
|
+
connected: this.instanceConnected,
|
|
122
|
+
state: this.state,
|
|
123
|
+
port: this.globalVendorArgs.port,
|
|
124
|
+
uptime: process.uptime()
|
|
125
|
+
}));
|
|
126
|
+
})
|
|
127
|
+
.get("/metrics", async (_, res) => {
|
|
128
|
+
res.setHeader('Content-Type', 'application/json');
|
|
129
|
+
res.end(JSON.stringify({
|
|
130
|
+
queue: this.queueOptions,
|
|
131
|
+
queueFlow: this.getQueueFlowStats(),
|
|
132
|
+
rateLimit: this.rateLimitConfig
|
|
133
|
+
}));
|
|
95
134
|
})
|
|
96
135
|
.post("/webhook", this.vendor.incomingMsg);
|
|
97
136
|
};
|
|
@@ -143,6 +182,13 @@ class SendWaveProvider extends bot_1.ProviderClass {
|
|
|
143
182
|
this.emit("host", payload);
|
|
144
183
|
},
|
|
145
184
|
},
|
|
185
|
+
{
|
|
186
|
+
event: "qr-update-request",
|
|
187
|
+
func: (_payload) => {
|
|
188
|
+
this.getApiQrConnect();
|
|
189
|
+
this.startConnectionPolling();
|
|
190
|
+
},
|
|
191
|
+
},
|
|
146
192
|
];
|
|
147
193
|
this.initAll = (port, opts) => {
|
|
148
194
|
this.globalVendorArgs.port = port;
|
|
@@ -195,9 +241,13 @@ class SendWaveProvider extends bot_1.ProviderClass {
|
|
|
195
241
|
};
|
|
196
242
|
const cleanArgs = Object.fromEntries(Object.entries(args).filter(([_, v]) => v !== undefined));
|
|
197
243
|
this.globalVendorArgs = { ...this.globalVendorArgs, ...cleanArgs };
|
|
244
|
+
if (process.env.SENDWAVE_URL)
|
|
245
|
+
this.globalVendorArgs.url = process.env.SENDWAVE_URL;
|
|
246
|
+
if (process.env.SENDWAVE_API_KEY)
|
|
247
|
+
this.globalVendorArgs.apiKey = process.env.SENDWAVE_API_KEY;
|
|
198
248
|
this.queue = new queue_promise_1.default({
|
|
199
|
-
concurrent:
|
|
200
|
-
interval:
|
|
249
|
+
concurrent: this.queueOptions.concurrent,
|
|
250
|
+
interval: this.queueOptions.interval,
|
|
201
251
|
start: true,
|
|
202
252
|
});
|
|
203
253
|
// Initialize queue flow system if enabled
|
|
@@ -210,8 +260,12 @@ class SendWaveProvider extends bot_1.ProviderClass {
|
|
|
210
260
|
}
|
|
211
261
|
this.createInstance();
|
|
212
262
|
this.on("ready", (isReady) => {
|
|
213
|
-
|
|
214
|
-
|
|
263
|
+
if (this.lastReadyState !== isReady) {
|
|
264
|
+
if (isReady) {
|
|
265
|
+
console.log("Instance connection status:", "Connected to server");
|
|
266
|
+
}
|
|
267
|
+
this.lastReadyState = isReady;
|
|
268
|
+
}
|
|
215
269
|
});
|
|
216
270
|
this.sender = new sender_1.SenderMessage(this.globalVendorArgs);
|
|
217
271
|
// Add global error handlers for payload errors
|
|
@@ -251,12 +305,14 @@ class SendWaveProvider extends bot_1.ProviderClass {
|
|
|
251
305
|
this.instanceConnected = true;
|
|
252
306
|
this.state = true;
|
|
253
307
|
this.emit("ready", true);
|
|
308
|
+
this.stopConnectionPolling();
|
|
254
309
|
}
|
|
255
310
|
else {
|
|
256
311
|
this.instanceConnected = true;
|
|
257
312
|
this.emit("ready", false);
|
|
258
313
|
this.getApiQrConnect();
|
|
259
314
|
this.state = false;
|
|
315
|
+
this.startConnectionPolling();
|
|
260
316
|
}
|
|
261
317
|
}));
|
|
262
318
|
}
|
|
@@ -267,6 +323,19 @@ class SendWaveProvider extends bot_1.ProviderClass {
|
|
|
267
323
|
});
|
|
268
324
|
}
|
|
269
325
|
}
|
|
326
|
+
startConnectionPolling() {
|
|
327
|
+
if (this.connectionPollTimer)
|
|
328
|
+
return;
|
|
329
|
+
this.connectionPollTimer = setInterval(() => {
|
|
330
|
+
this.afterHttpServerInit();
|
|
331
|
+
}, this.connectionPollIntervalMs);
|
|
332
|
+
}
|
|
333
|
+
stopConnectionPolling() {
|
|
334
|
+
if (this.connectionPollTimer) {
|
|
335
|
+
clearInterval(this.connectionPollTimer);
|
|
336
|
+
this.connectionPollTimer = undefined;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
270
339
|
saveFile(_, options) {
|
|
271
340
|
return new Promise((resolve, reject) => {
|
|
272
341
|
try {
|
|
@@ -298,23 +367,22 @@ class SendWaveProvider extends bot_1.ProviderClass {
|
|
|
298
367
|
maxBodyLength: maxContentLength,
|
|
299
368
|
timeout: 300000, // 5 minutes timeout for large files
|
|
300
369
|
});
|
|
301
|
-
// Add request interceptor for large file logging
|
|
302
370
|
this.sendwaveApi.interceptors.request.use((config) => {
|
|
303
|
-
const contentLength = config.headers['content-length'] ||
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
console.log(`[LargeRequest] Sending ${Math.round(contentLength / 1024 / 1024 * 100) / 100}MB to ${config.url}`);
|
|
371
|
+
const contentLength = (config.headers && config.headers['content-length']) || (config.data ? JSON.stringify(config.data).length : 0);
|
|
372
|
+
if (contentLength > 1024 * 1024) {
|
|
373
|
+
console.log(`[LargeRequest] Sending ${Math.round((contentLength / 1024 / 1024) * 100) / 100}MB to ${config.url}`);
|
|
307
374
|
}
|
|
308
375
|
return config;
|
|
309
376
|
}, (error) => Promise.reject(error));
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
377
|
+
this.sendwaveApi.interceptors.response.use((response) => response, async (error) => {
|
|
378
|
+
const config = error.config || {};
|
|
379
|
+
config.__retryCount = config.__retryCount || 0;
|
|
380
|
+
const shouldRetry = error.code === 'ECONNRESET' || error.code === 'ETIMEDOUT' || (error.response && error.response.status >= 500);
|
|
381
|
+
if (shouldRetry && config.__retryCount < 3) {
|
|
382
|
+
config.__retryCount += 1;
|
|
383
|
+
const delay = Math.min(1000 * Math.pow(2, config.__retryCount), 8000);
|
|
384
|
+
await new Promise((r) => setTimeout(r, delay));
|
|
385
|
+
return this.sendwaveApi.request(config);
|
|
318
386
|
}
|
|
319
387
|
return Promise.reject(error);
|
|
320
388
|
});
|
package/build/provider/sender.js
CHANGED
|
@@ -7,6 +7,7 @@ exports.SenderMessage = void 0;
|
|
|
7
7
|
const https_1 = require("https");
|
|
8
8
|
const axios_1 = __importDefault(require("axios"));
|
|
9
9
|
const detectorMedia_1 = require("../utils/detectorMedia");
|
|
10
|
+
const crypto_1 = require("crypto");
|
|
10
11
|
class SenderMessage {
|
|
11
12
|
constructor(args) {
|
|
12
13
|
const payloadLimits = args.payloadLimits || {};
|
|
@@ -23,6 +24,18 @@ class SenderMessage {
|
|
|
23
24
|
timeout: 300000, // 5 minutes for large files
|
|
24
25
|
});
|
|
25
26
|
this.globalVendorArgs = args;
|
|
27
|
+
this.sendwaveApi.interceptors.response.use((response) => response, async (error) => {
|
|
28
|
+
const config = error.config || {};
|
|
29
|
+
config.__retryCount = config.__retryCount || 0;
|
|
30
|
+
const shouldRetry = error.code === 'ECONNRESET' || error.code === 'ETIMEDOUT' || (error.response && error.response.status >= 500);
|
|
31
|
+
if (shouldRetry && config.__retryCount < 3) {
|
|
32
|
+
config.__retryCount += 1;
|
|
33
|
+
const delay = Math.min(1000 * Math.pow(2, config.__retryCount), 8000);
|
|
34
|
+
await new Promise((r) => setTimeout(r, delay));
|
|
35
|
+
return this.sendwaveApi.request(config);
|
|
36
|
+
}
|
|
37
|
+
return Promise.reject(error);
|
|
38
|
+
});
|
|
26
39
|
}
|
|
27
40
|
parseSize(size) {
|
|
28
41
|
const units = {
|
|
@@ -39,7 +52,7 @@ class SenderMessage {
|
|
|
39
52
|
return Math.floor(value * units[unit]);
|
|
40
53
|
}
|
|
41
54
|
async sendPresence(data) {
|
|
42
|
-
var _a, _b;
|
|
55
|
+
var _a, _b, _c, _d, _e;
|
|
43
56
|
try {
|
|
44
57
|
return await ((_a = this.sendwaveApi) === null || _a === void 0 ? void 0 : _a.post(`/chat/sendPresence/${(_b = this.globalVendorArgs) === null || _b === void 0 ? void 0 : _b.name}`, {
|
|
45
58
|
number: data.from,
|
|
@@ -48,7 +61,9 @@ class SenderMessage {
|
|
|
48
61
|
}));
|
|
49
62
|
}
|
|
50
63
|
catch (e) {
|
|
51
|
-
|
|
64
|
+
const msg = ((_e = (_d = (_c = e === null || e === void 0 ? void 0 : e.response) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.response) === null || _e === void 0 ? void 0 : _e.message) || (e === null || e === void 0 ? void 0 : e.message) || "Unknown error";
|
|
65
|
+
console.error(`[sendPresence Error] ${msg}`);
|
|
66
|
+
throw new Error(msg);
|
|
52
67
|
}
|
|
53
68
|
}
|
|
54
69
|
async sendText(data) {
|
|
@@ -160,7 +175,7 @@ class SenderMessage {
|
|
|
160
175
|
number: data.from.split("@")[0],
|
|
161
176
|
mediatype: mediaType,
|
|
162
177
|
mimetype: mimeType,
|
|
163
|
-
fileName: data.fileName || `${
|
|
178
|
+
fileName: data.fileName || `${(0, crypto_1.randomUUID)()}.${mimeType.split("/")[1]}`,
|
|
164
179
|
media: media,
|
|
165
180
|
caption: data.text,
|
|
166
181
|
delay: data.delay || 0,
|
|
@@ -197,18 +212,22 @@ class SenderMessage {
|
|
|
197
212
|
return (defaults[mediaType] || "application/octet-stream");
|
|
198
213
|
}
|
|
199
214
|
async sendFile(data) {
|
|
215
|
+
var _a, _b, _c;
|
|
200
216
|
try {
|
|
201
217
|
return await this.sendMedia({
|
|
202
218
|
...data,
|
|
203
|
-
fileName: data.fileName ||
|
|
219
|
+
fileName: data.fileName || (0, crypto_1.randomUUID)(),
|
|
204
220
|
mediaType: "document",
|
|
205
221
|
});
|
|
206
222
|
}
|
|
207
223
|
catch (e) {
|
|
208
|
-
|
|
224
|
+
const msg = ((_c = (_b = (_a = e === null || e === void 0 ? void 0 : e.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.response) === null || _c === void 0 ? void 0 : _c.message) || (e === null || e === void 0 ? void 0 : e.message) || "Unknown error";
|
|
225
|
+
console.error(`[sendFile Error] ${msg}`);
|
|
226
|
+
throw new Error(msg);
|
|
209
227
|
}
|
|
210
228
|
}
|
|
211
229
|
async sendImage(data) {
|
|
230
|
+
var _a, _b, _c;
|
|
212
231
|
try {
|
|
213
232
|
return await this.sendMedia({
|
|
214
233
|
...data,
|
|
@@ -216,10 +235,13 @@ class SenderMessage {
|
|
|
216
235
|
});
|
|
217
236
|
}
|
|
218
237
|
catch (e) {
|
|
219
|
-
|
|
238
|
+
const msg = ((_c = (_b = (_a = e === null || e === void 0 ? void 0 : e.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.response) === null || _c === void 0 ? void 0 : _c.message) || (e === null || e === void 0 ? void 0 : e.message) || "Unknown error";
|
|
239
|
+
console.error(`[sendImage Error] ${msg}`);
|
|
240
|
+
throw new Error(msg);
|
|
220
241
|
}
|
|
221
242
|
}
|
|
222
243
|
async sendAudio(data) {
|
|
244
|
+
var _a, _b, _c;
|
|
223
245
|
try {
|
|
224
246
|
return await this.sendMedia({
|
|
225
247
|
...data,
|
|
@@ -227,10 +249,13 @@ class SenderMessage {
|
|
|
227
249
|
});
|
|
228
250
|
}
|
|
229
251
|
catch (e) {
|
|
230
|
-
|
|
252
|
+
const msg = ((_c = (_b = (_a = e === null || e === void 0 ? void 0 : e.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.response) === null || _c === void 0 ? void 0 : _c.message) || (e === null || e === void 0 ? void 0 : e.message) || "Unknown error";
|
|
253
|
+
console.error(`[sendAudio Error] ${msg}`);
|
|
254
|
+
throw new Error(msg);
|
|
231
255
|
}
|
|
232
256
|
}
|
|
233
257
|
async sendVideo(data) {
|
|
258
|
+
var _a, _b, _c;
|
|
234
259
|
try {
|
|
235
260
|
return await this.sendMedia({
|
|
236
261
|
...data,
|
|
@@ -238,7 +263,9 @@ class SenderMessage {
|
|
|
238
263
|
});
|
|
239
264
|
}
|
|
240
265
|
catch (e) {
|
|
241
|
-
|
|
266
|
+
const msg = ((_c = (_b = (_a = e === null || e === void 0 ? void 0 : e.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.response) === null || _c === void 0 ? void 0 : _c.message) || (e === null || e === void 0 ? void 0 : e.message) || "Unknown error";
|
|
267
|
+
console.error(`[sendVideo Error] ${msg}`);
|
|
268
|
+
throw new Error(msg);
|
|
242
269
|
}
|
|
243
270
|
}
|
|
244
271
|
async sendVoice(data) {
|
|
@@ -282,7 +309,7 @@ class SenderMessage {
|
|
|
282
309
|
}
|
|
283
310
|
}
|
|
284
311
|
async sendButton(data) {
|
|
285
|
-
var _a, _b;
|
|
312
|
+
var _a, _b, _c, _d, _e;
|
|
286
313
|
try {
|
|
287
314
|
return await ((_a = this.sendwaveApi) === null || _a === void 0 ? void 0 : _a.post(`/message/sendButtons/${(_b = this.globalVendorArgs) === null || _b === void 0 ? void 0 : _b.name}`, {
|
|
288
315
|
number: data.from.split("@")[0],
|
|
@@ -300,11 +327,13 @@ class SenderMessage {
|
|
|
300
327
|
}));
|
|
301
328
|
}
|
|
302
329
|
catch (error) {
|
|
303
|
-
|
|
330
|
+
const msg = ((_e = (_d = (_c = error === null || error === void 0 ? void 0 : error.response) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.response) === null || _e === void 0 ? void 0 : _e.message) || (error === null || error === void 0 ? void 0 : error.message) || "Unknown error";
|
|
331
|
+
console.error(`[sendButton Error] ${msg}`);
|
|
332
|
+
throw new Error(msg);
|
|
304
333
|
}
|
|
305
334
|
}
|
|
306
335
|
async sendLocation(data) {
|
|
307
|
-
var _a, _b;
|
|
336
|
+
var _a, _b, _c, _d, _e;
|
|
308
337
|
try {
|
|
309
338
|
return await ((_a = this.sendwaveApi) === null || _a === void 0 ? void 0 : _a.post(`/message/sendLocation/${(_b = this.globalVendorArgs) === null || _b === void 0 ? void 0 : _b.name}`, {
|
|
310
339
|
number: data.from.split("@")[0],
|
|
@@ -316,11 +345,13 @@ class SenderMessage {
|
|
|
316
345
|
}));
|
|
317
346
|
}
|
|
318
347
|
catch (error) {
|
|
319
|
-
|
|
348
|
+
const msg = ((_e = (_d = (_c = error === null || error === void 0 ? void 0 : error.response) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.response) === null || _e === void 0 ? void 0 : _e.message) || (error === null || error === void 0 ? void 0 : error.message) || "Unknown error";
|
|
349
|
+
console.error(`[sendLocation Error] ${msg}`);
|
|
350
|
+
throw new Error(msg);
|
|
320
351
|
}
|
|
321
352
|
}
|
|
322
353
|
async sendReaction(data) {
|
|
323
|
-
var _a, _b;
|
|
354
|
+
var _a, _b, _c, _d, _e;
|
|
324
355
|
try {
|
|
325
356
|
return await ((_a = this.sendwaveApi) === null || _a === void 0 ? void 0 : _a.post(`/message/sendReaction/${(_b = this.globalVendorArgs) === null || _b === void 0 ? void 0 : _b.name}`, {
|
|
326
357
|
key: data.key,
|
|
@@ -329,7 +360,9 @@ class SenderMessage {
|
|
|
329
360
|
}));
|
|
330
361
|
}
|
|
331
362
|
catch (error) {
|
|
332
|
-
|
|
363
|
+
const msg = ((_e = (_d = (_c = error === null || error === void 0 ? void 0 : error.response) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.response) === null || _e === void 0 ? void 0 : _e.message) || (error === null || error === void 0 ? void 0 : error.message) || "Unknown error";
|
|
364
|
+
console.error(`[sendReaction Error] ${msg}`);
|
|
365
|
+
throw new Error(msg);
|
|
333
366
|
}
|
|
334
367
|
}
|
|
335
368
|
}
|
package/build/utils/parserMsg.js
CHANGED
|
@@ -13,7 +13,7 @@ function parseIncomingMsg(payload) {
|
|
|
13
13
|
}
|
|
14
14
|
// if (msg.key.fromMe) return null
|
|
15
15
|
const fromMe = msg.key.fromMe;
|
|
16
|
-
const from = (_a = msg.key) === null || _a === void 0 ? void 0 : _a.remoteJid.split("@")[0];
|
|
16
|
+
const from = (((_a = msg.key) === null || _a === void 0 ? void 0 : _a.remoteJid) || "").split("@")[0].split(":")[0];
|
|
17
17
|
const to = payload.instance || "";
|
|
18
18
|
const name = msg.pushName;
|
|
19
19
|
const messageContent = msg.message || {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gamastudio/sendwave-provider",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.13",
|
|
4
4
|
"description": "Librería para interactuar con Sendwave usando configuración dinámica.",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -23,26 +23,26 @@
|
|
|
23
23
|
"license": "ISC",
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@builderbot/bot": "^1.2.9",
|
|
26
|
-
"@gamastudio/colorslog": "^0.1.
|
|
27
|
-
"@types/mime-types": "^
|
|
28
|
-
"axios": "^1.
|
|
26
|
+
"@gamastudio/colorslog": "^0.1.8",
|
|
27
|
+
"@types/mime-types": "^3.0.1",
|
|
28
|
+
"axios": "^1.13.2",
|
|
29
29
|
"body-parser": "^2.2.0",
|
|
30
30
|
"cors": "^2.8.5",
|
|
31
|
-
"file-type": "^
|
|
31
|
+
"file-type": "^21.1.0",
|
|
32
32
|
"mime-types": "^3.0.1",
|
|
33
33
|
"queue-promise": "^2.2.1",
|
|
34
|
-
"sirv": "^3.0.
|
|
34
|
+
"sirv": "^3.0.2"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@types/axios": "^0.14.4",
|
|
38
38
|
"@types/body-parser": "^1.19.6",
|
|
39
39
|
"@types/cors": "^2.8.19",
|
|
40
|
-
"@types/node": "^
|
|
40
|
+
"@types/node": "^24.10.1",
|
|
41
41
|
"copyfiles": "^2.4.1",
|
|
42
42
|
"ts-node": "^10.9.2",
|
|
43
43
|
"ts-node-dev": "^2.0.0",
|
|
44
44
|
"tsc-alias": "^1.8.16",
|
|
45
45
|
"tsconfig-paths": "^4.2.0",
|
|
46
|
-
"typescript": "^5.9.
|
|
46
|
+
"typescript": "^5.9.3"
|
|
47
47
|
}
|
|
48
48
|
}
|