@gamastudio/sendwave-provider 1.0.0 → 1.0.2

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.
@@ -89,7 +89,7 @@ class SenderMessage {
89
89
  }
90
90
  }
91
91
  async sendList(data) {
92
- var _a, _b, _c, _d, _e;
92
+ var _a, _b, _c, _d, _e, _f;
93
93
  try {
94
94
  if (!(data === null || data === void 0 ? void 0 : data.from))
95
95
  throw new Error("sendList: falta 'from'");
@@ -126,11 +126,15 @@ class SenderMessage {
126
126
  footerText,
127
127
  buttonText: button,
128
128
  sections,
129
+ delay: data.delay || 2000,
130
+ quoted: data.quoted,
131
+ everyOne: data.everyOne || false,
132
+ mentioned: ((_c = data.mentioned) === null || _c === void 0 ? void 0 : _c.length) ? data.mentioned : [data.from],
129
133
  ...this.globalVendorArgs,
130
134
  }));
131
135
  }
132
136
  catch (err) {
133
- console.error("[sendList Error]", ((_e = (_d = (_c = err.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) || err.message);
137
+ console.error("[sendList Error]", ((_f = (_e = (_d = err.response) === null || _d === void 0 ? void 0 : _d.data) === null || _e === void 0 ? void 0 : _e.response) === null || _f === void 0 ? void 0 : _f.message) || err.message);
134
138
  }
135
139
  }
136
140
  async sendMedia(data) {
@@ -280,12 +284,6 @@ class SenderMessage {
280
284
  detectorMedia_1.detectorMedia.updateLimits(this.globalVendorArgs.payloadLimits.media);
281
285
  }
282
286
  const { media } = await detectorMedia_1.detectorMedia.processMedia(data.url);
283
- // try {
284
- // await this.sendPresence({
285
- // from: data.from,
286
- // presence: "recording",
287
- // });
288
- // } catch (error) {}
289
287
  return await ((_c = this.sendwaveApi) === null || _c === void 0 ? void 0 : _c.post(`/message/sendWhatsAppAudio/${(_d = this.globalVendorArgs) === null || _d === void 0 ? void 0 : _d.name}`, {
290
288
  number: data.from,
291
289
  audio: media,
@@ -315,31 +313,85 @@ class SenderMessage {
315
313
  }
316
314
  }
317
315
  async sendButton(data) {
318
- var _a, _b, _c, _d, _e;
316
+ var _a, _b, _c, _d, _e, _f;
319
317
  try {
320
318
  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}`, {
321
319
  number: data.from,
320
+ thumbnailUrl: data.thumbnailUrl,
322
321
  title: data.title,
323
322
  body: data.body,
324
323
  description: data.description,
325
324
  footer: data.footer,
326
- buttons: data.buttons.map((button, index) => ({
327
- type: button.type,
328
- title: button.text,
329
- displayText: button.text,
330
- id: `${index + 1}`,
331
- })),
325
+ buttons: data.buttons.map((button, index) => {
326
+ let type = "reply";
327
+ let displayText = "";
328
+ let rest = {};
329
+ if (typeof button === "string") {
330
+ displayText = button;
331
+ }
332
+ else if (button.displayText) {
333
+ displayText = button.displayText;
334
+ type = button.type || "reply";
335
+ rest = button;
336
+ }
337
+ else if (button.type === "reply") {
338
+ displayText = button.displayText;
339
+ type = "reply";
340
+ rest = button;
341
+ }
342
+ else {
343
+ displayText = button.displayText || button.text || button;
344
+ type = button.type || "reply";
345
+ rest = button;
346
+ }
347
+ const base = {
348
+ type,
349
+ displayText,
350
+ id: typeof button === 'string' ? `${index + 1}` : button.id,
351
+ ...rest
352
+ };
353
+ // Clean up unwanted properties
354
+ delete base.text;
355
+ delete base.body;
356
+ delete base.reply;
357
+ return base;
358
+ }),
359
+ delay: data.delay || 2000,
360
+ quoted: data.quoted,
361
+ everyOne: data.everyOne || false,
362
+ mentioned: ((_c = data.mentioned) === null || _c === void 0 ? void 0 : _c.length) ? data.mentioned : [data.from],
332
363
  ...this.globalVendorArgs,
333
364
  }));
334
365
  }
335
366
  catch (error) {
336
- 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) ||
367
+ const msg = ((_f = (_e = (_d = error === null || error === void 0 ? void 0 : error.response) === null || _d === void 0 ? void 0 : _d.data) === null || _e === void 0 ? void 0 : _e.response) === null || _f === void 0 ? void 0 : _f.message) ||
337
368
  (error === null || error === void 0 ? void 0 : error.message) ||
338
369
  "Unknown error";
339
370
  console.error(`[sendButton Error] ${msg}`);
340
371
  throw new Error(msg);
341
372
  }
342
373
  }
374
+ async sendPoll(data) {
375
+ var _a, _b, _c, _d, _e, _f;
376
+ try {
377
+ return await ((_a = this.sendwaveApi) === null || _a === void 0 ? void 0 : _a.post(`/message/sendPoll/${(_b = this.globalVendorArgs) === null || _b === void 0 ? void 0 : _b.name}`, {
378
+ number: data.from,
379
+ name: data.poll.name,
380
+ selectableCount: data.poll.selectableCount || 1,
381
+ values: data.poll.values,
382
+ delay: data.delay || 2000,
383
+ quoted: data.quoted,
384
+ everyOne: data.everyOne || false,
385
+ mentioned: ((_c = data.mentioned) === null || _c === void 0 ? void 0 : _c.length) ? data.mentioned : [data.from],
386
+ ...this.globalVendorArgs,
387
+ }));
388
+ }
389
+ catch (e) {
390
+ const msg = ((_f = (_e = (_d = e === null || e === void 0 ? void 0 : e.response) === null || _d === void 0 ? void 0 : _d.data) === null || _e === void 0 ? void 0 : _e.response) === null || _f === void 0 ? void 0 : _f.message) || (e === null || e === void 0 ? void 0 : e.message) || "Unknown error";
391
+ console.error(`[sendPoll Error] ${msg}`);
392
+ throw new Error(msg);
393
+ }
394
+ }
343
395
  async sendLocation(data) {
344
396
  var _a, _b, _c, _d, _e;
345
397
  try {
@@ -61,9 +61,10 @@ class DetectorMedia {
61
61
  });
62
62
  }
63
63
  async validateUrlSize(url, mediaType) {
64
+ var _a;
64
65
  try {
65
66
  const response = await axios_1.default.head(url);
66
- const contentLength = parseInt(response.headers["content-length"] || "0");
67
+ const contentLength = parseInt(String((_a = response.headers["content-length"]) !== null && _a !== void 0 ? _a : "0"));
67
68
  if (contentLength > 0) {
68
69
  const limitStr = this.mediaLimits[mediaType] || "10mb";
69
70
  const limit = this.parseSize(limitStr);
@@ -114,10 +115,11 @@ class DetectorMedia {
114
115
  try {
115
116
  const res = await axios_1.default.head(url);
116
117
  const contentType = res.headers["content-type"];
117
- const mediaType = this.mapMimeToCategory(contentType);
118
+ const contentTypeStr = contentType ? String(contentType) : null;
119
+ const mediaType = this.mapMimeToCategory(contentTypeStr !== null && contentTypeStr !== void 0 ? contentTypeStr : "unknown");
118
120
  return {
119
121
  mediaType: mediaType || null,
120
- mimeType: contentType || null,
122
+ mimeType: contentTypeStr,
121
123
  };
122
124
  }
123
125
  catch {