@open-wa/wa-automate 4.37.5 → 4.39.0

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.
@@ -19,7 +19,7 @@ import { Listener } from 'eventemitter2';
19
19
  import PriorityQueue from 'p-queue/dist/priority-queue';
20
20
  import { NextFunction, Request, Response } from 'express';
21
21
  import { Call } from './model/call';
22
- import { Button, LocationButtonBody, Section } from './model/button';
22
+ import { AdvancedButton, Button, LocationButtonBody, Section } from './model/button';
23
23
  import { JsonObject } from 'type-fest';
24
24
  import { ReactionEvent } from './model/reactions';
25
25
  export declare enum namespace {
@@ -178,6 +178,13 @@ export declare class Client {
178
178
  * @fires [[Message]]
179
179
  */
180
180
  onButton(fn: (message: Message) => void): Promise<Listener | boolean>;
181
+ /**
182
+ * Listens to broadcast messages
183
+ * @event
184
+ * @param fn callback
185
+ * @fires [[Message]]
186
+ */
187
+ onBroadcast(fn: (message: Message) => void): Promise<Listener | boolean>;
181
188
  /**
182
189
  * Listens to battery changes
183
190
  *
@@ -508,6 +515,21 @@ export declare class Client {
508
515
  * @param {string} footer The footer of the buttons message
509
516
  */
510
517
  sendButtons(to: ChatId, body: string | LocationButtonBody, buttons: Button[], title?: string, footer?: string): Promise<boolean | MessageId>;
518
+ /**
519
+ * {@license:insiders@}
520
+ *
521
+ * Send advanced buttons with media body. This is an insiders feature for MD accounts.
522
+ *
523
+ * Body can be location, image, video or document. Buttons can be quick reply, url or call buttons.
524
+ *
525
+ * @param {ChatId} to chat id
526
+ * @param {string | LocationButtonBody} body The body of the buttons message
527
+ * @param {AdvancedButton[]} buttons Array of buttons - limit is 3!
528
+ * @param {string} title The title/header of the buttons message
529
+ * @param {string} footer The footer of the buttons message
530
+ * @param {string} filename Required if body is a file!!
531
+ */
532
+ sendAdvancedButtons(to: ChatId, body: string | LocationButtonBody, buttons: AdvancedButton[], text: string, footer: string, filename: string): Promise<boolean | MessageId>;
511
533
  /**
512
534
  * Send a banner image
513
535
  *
@@ -519,7 +541,7 @@ export declare class Client {
519
541
  sendBanner(to: ChatId, base64: Base64): Promise<boolean | MessageId>;
520
542
  /**
521
543
  * {@license:insiders@}
522
- * <span theme="badge contrast license">Insiders</span>
544
+ *
523
545
  * [REQUIRES AN INSIDERS LICENSE-KEY](https://gum.co/open-wa?tier=Insiders%20Program)
524
546
  *
525
547
  * Send a list message. This will not work when being sent from business accounts!
@@ -564,7 +586,7 @@ export declare class Client {
564
586
  * @param chatId The chat you want to send this message to.
565
587
  *
566
588
  */
567
- sendMessageWithThumb(thumb: string, url: string, title: string, description: string, text: Content, chatId: ChatId): Promise<MessageId | string | boolean>;
589
+ sendMessageWithThumb(thumb: string, url: string, title: string, description: string, text: Content, chatId: ChatId): Promise<MessageId | boolean>;
568
590
  /**
569
591
  * Sends a location message to given chat
570
592
  * @param to chat id: `xxxxx@c.us`
@@ -678,8 +678,8 @@ class Client {
678
678
  //do nothing
679
679
  }
680
680
  const m = fil ? [message].filter(typeof fil == "function" ? fil : x => x)[0] : message;
681
- logging_1.log.info(`Preproc START: ${this._createConfig.messagePreprocessor} ${fil} ${message.id} ${m.id}`);
682
- if (m && this._createConfig.messagePreprocessor && preProcessors_1.MessagePreprocessors[this._createConfig.messagePreprocessor]) {
681
+ if (m && this._createConfig.messagePreprocessor && preProcessors_1.MessagePreprocessors[this._createConfig.messagePreprocessor] && message.mimetype) {
682
+ logging_1.log.info(`Preproc START: ${this._createConfig.messagePreprocessor} ${fil} ${message.id} ${m.id}`);
683
683
  logging_1.log.info(`Preproccessing message: ${this._createConfig.messagePreprocessor}`);
684
684
  const preprocres = ((yield preProcessors_1.MessagePreprocessors[this._createConfig.messagePreprocessor](m, this)) || message);
685
685
  delete this._preprocIdempotencyCheck[message.id];
@@ -753,6 +753,17 @@ class Client {
753
753
  return this.registerListener(events_2.SimpleListener.Button, fn);
754
754
  });
755
755
  }
756
+ /**
757
+ * Listens to broadcast messages
758
+ * @event
759
+ * @param fn callback
760
+ * @fires [[Message]]
761
+ */
762
+ onBroadcast(fn) {
763
+ return __awaiter(this, void 0, void 0, function* () {
764
+ return this.registerListener(events_2.SimpleListener.Broadcast, fn);
765
+ });
766
+ }
756
767
  /**
757
768
  * Listens to battery changes
758
769
  *
@@ -1332,6 +1343,47 @@ class Client {
1332
1343
  }, { to, body, buttons, title, footer });
1333
1344
  });
1334
1345
  }
1346
+ /**
1347
+ * {@license:insiders@}
1348
+ *
1349
+ * Send advanced buttons with media body. This is an insiders feature for MD accounts.
1350
+ *
1351
+ * Body can be location, image, video or document. Buttons can be quick reply, url or call buttons.
1352
+ *
1353
+ * @param {ChatId} to chat id
1354
+ * @param {string | LocationButtonBody} body The body of the buttons message
1355
+ * @param {AdvancedButton[]} buttons Array of buttons - limit is 3!
1356
+ * @param {string} title The title/header of the buttons message
1357
+ * @param {string} footer The footer of the buttons message
1358
+ * @param {string} filename Required if body is a file!!
1359
+ */
1360
+ sendAdvancedButtons(to, body, buttons, text, footer, filename) {
1361
+ return __awaiter(this, void 0, void 0, function* () {
1362
+ if (typeof body !== "string" && body.lat) {
1363
+ //this is a location body
1364
+ // eslint-disable-next-line no-self-assign
1365
+ body = body;
1366
+ }
1367
+ else if (typeof body == "string" && !(0, tools_1.isDataURL)(body) && !(0, tools_1.isBase64)(body) && !body.includes("data:")) {
1368
+ //must be a file then
1369
+ const relativePath = path.join(path.resolve(process.cwd(), body || ''));
1370
+ if (typeof body == "string" && fs.existsSync(body) || fs.existsSync(relativePath)) {
1371
+ body = yield (0, datauri_1.default)(fs.existsSync(body) ? body : relativePath);
1372
+ }
1373
+ else if (typeof body == "string" && (0, is_url_superb_1.default)(body)) {
1374
+ body = yield (0, tools_1.getDUrl)(body);
1375
+ }
1376
+ else
1377
+ throw new errors_1.CustomError(errors_1.ERROR_NAME.FILE_NOT_FOUND, `Cannot find file. Make sure the file reference is relative, a valid URL or a valid DataURL: ${body.slice(0, 25)}`);
1378
+ }
1379
+ else if (typeof body == "string" && (body.includes("data:") && body.includes("undefined") || body.includes("application/octet-stream") && filename && mime_types_1.default.lookup(filename))) {
1380
+ body = `data:${mime_types_1.default.lookup(filename)};base64,${body.split(',')[1]}`;
1381
+ }
1382
+ return yield this.pup(({ to, body, buttons, text, footer, filename }) => {
1383
+ return WAPI.sendAdvancedButtons(to, body, buttons, text, footer, filename);
1384
+ }, { to, body, buttons, text, footer, filename });
1385
+ });
1386
+ }
1335
1387
  /**
1336
1388
  * Send a banner image
1337
1389
  *
@@ -1349,7 +1401,7 @@ class Client {
1349
1401
  }
1350
1402
  /**
1351
1403
  * {@license:insiders@}
1352
- * <span theme="badge contrast license">Insiders</span>
1404
+ *
1353
1405
  * [REQUIRES AN INSIDERS LICENSE-KEY](https://gum.co/open-wa?tier=Insiders%20Program)
1354
1406
  *
1355
1407
  * Send a list message. This will not work when being sent from business accounts!
@@ -2,6 +2,12 @@ export interface Button {
2
2
  id: string;
3
3
  text: string;
4
4
  }
5
+ export interface AdvancedButton {
6
+ id?: string;
7
+ text: string;
8
+ url?: string;
9
+ number?: string;
10
+ }
5
11
  export interface Row {
6
12
  title: string;
7
13
  description: string;
@@ -62,6 +62,10 @@ export declare enum SimpleListener {
62
62
  * Represents [[onButton]]
63
63
  */
64
64
  Button = "onButton",
65
+ /**
66
+ * Represents [[onBroadcast]]
67
+ */
68
+ Broadcast = "onBroadcast",
65
69
  /**
66
70
  * Represents [[onLabel]]
67
71
  */
@@ -69,6 +69,10 @@ var SimpleListener;
69
69
  * Represents [[onButton]]
70
70
  */
71
71
  SimpleListener["Button"] = "onButton";
72
+ /**
73
+ * Represents [[onBroadcast]]
74
+ */
75
+ SimpleListener["Broadcast"] = "onBroadcast";
72
76
  /**
73
77
  * Represents [[onLabel]]
74
78
  */