@open-wa/wa-automate 4.64.3 → 4.64.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.
@@ -474,92 +474,101 @@ class ChatwootClient {
474
474
  processWAMessage(message) {
475
475
  var _a;
476
476
  return __awaiter(this, void 0, void 0, function* () {
477
- let isNewConversation = false;
478
- if (message.chatId.includes('g')) {
479
- //chatwoot integration does not support group chats
480
- return;
481
- }
482
- /**
483
- * Does the contact exist in chatwoot?
484
- */
485
- if (!contactReg[message.chatId]) {
486
- const contact = yield this.searchContact(message.chatId);
487
- if (contact) {
488
- contactReg[message.chatId] = contact.id;
489
- }
490
- else {
491
- //create the contact
492
- contactReg[message.chatId] = (yield this.createContact(message.sender)).id;
477
+ try {
478
+ let isNewConversation = false;
479
+ if (message.chatId.includes('g')) {
480
+ //chatwoot integration does not support group chats
481
+ return;
493
482
  }
494
- }
495
- if (!convoReg[message.chatId]) {
496
- const conversation = yield this.getContactConversation(message.chatId);
497
- if (conversation) {
498
- convoReg[message.chatId] = conversation.id;
483
+ if (message.chatId.includes('broadcast')) {
484
+ //chatwoot integration does not support broadcast or story messages
485
+ return;
499
486
  }
500
- else {
501
- //create the conversation
502
- convoReg[message.chatId] = (yield this.createConversation(contactReg[message.chatId])).id;
503
- isNewConversation = convoReg[message.chatId];
487
+ /**
488
+ * Does the contact exist in chatwoot?
489
+ */
490
+ if (!contactReg[message.chatId]) {
491
+ const contact = yield this.searchContact(message.chatId);
492
+ if (contact) {
493
+ contactReg[message.chatId] = contact.id;
494
+ }
495
+ else {
496
+ //create the contact
497
+ contactReg[message.chatId] = (yield this.createContact(message.sender)).id;
498
+ }
504
499
  }
505
- }
506
- /**
507
- * Does the conversation exist in
508
- */
509
- let text = message.body;
510
- let hasAttachments = false;
511
- switch (message.type) {
512
- case 'list_response':
513
- /**
514
- * Possible CSAT response:
515
- */
516
- yield this.processCSATResponse(message);
517
- break;
518
- case 'location':
519
- text = `Location Message:\n\n${message.loc}\n\nhttps://www.google.com/maps?q=${message.lat},${message.lng}`;
520
- break;
521
- case 'buttons_response':
522
- text = message.selectedButtonId;
523
- break;
524
- case 'document':
525
- case 'image':
526
- case 'audio':
527
- case 'ptt':
528
- case 'video':
529
- if (message.cloudUrl) {
530
- text = `FILE:\t${message.cloudUrl}\n\nMESSAGE:\t${message.text}`;
500
+ if (!convoReg[message.chatId]) {
501
+ const conversation = yield this.getContactConversation(message.chatId);
502
+ if (conversation) {
503
+ convoReg[message.chatId] = conversation.id;
531
504
  }
532
505
  else {
533
- text = message.text;
534
- hasAttachments = true;
506
+ //create the conversation
507
+ convoReg[message.chatId] = (yield this.createConversation(contactReg[message.chatId])).id;
508
+ isNewConversation = convoReg[message.chatId];
535
509
  }
536
- break;
537
- default:
538
- text = ((_a = message === null || message === void 0 ? void 0 : message.ctwaContext) === null || _a === void 0 ? void 0 : _a.sourceUrl) ? `${message.body}\n\n${message.ctwaContext.sourceUrl}` : message.body || "__UNHANDLED__";
539
- break;
540
- }
541
- const newCWMessage = hasAttachments ? yield this.sendAttachmentMessage(text, message.chatId, message) : yield this.sendConversationMessage(text, message.chatId, message);
542
- if (isNewConversation !== false) {
543
- /**
544
- * Wait 3 seconds before trying to check for an automated message
545
- */
546
- yield (0, tools_1.timeout)(3000);
547
- /**
548
- * Check the messages to see if a message_type: 3 comes through after the initial message;
549
- */
550
- const msgs = yield this.getAllInboxMessages(`${isNewConversation}`);
551
- if (!msgs)
552
- return;
553
- /**
554
- * Message IDs are numbers (for now)
555
- */
556
- const possibleWelcomeMessage = msgs.filter(m => m.id > newCWMessage.id).find(m => m.message_type === 3 && m.content_type !== 'input_csat');
557
- if (!possibleWelcomeMessage)
558
- return;
510
+ }
559
511
  /**
560
- * Ok reply with the welcome message now
512
+ * Does the conversation exist in
561
513
  */
562
- yield this.client.sendText(message.chatId, possibleWelcomeMessage.content || "...");
514
+ let text = message.body;
515
+ let hasAttachments = false;
516
+ switch (message.type) {
517
+ case 'list_response':
518
+ /**
519
+ * Possible CSAT response:
520
+ */
521
+ yield this.processCSATResponse(message);
522
+ break;
523
+ case 'location':
524
+ text = `Location Message:\n\n${message.loc}\n\nhttps://www.google.com/maps?q=${message.lat},${message.lng}`;
525
+ break;
526
+ case 'buttons_response':
527
+ text = message.selectedButtonId;
528
+ break;
529
+ case 'document':
530
+ case 'image':
531
+ case 'audio':
532
+ case 'ptt':
533
+ case 'video':
534
+ if (message.cloudUrl) {
535
+ text = `FILE:\t${message.cloudUrl}\n\nMESSAGE:\t${message.text}`;
536
+ }
537
+ else {
538
+ text = message.text;
539
+ hasAttachments = true;
540
+ }
541
+ break;
542
+ default:
543
+ text = ((_a = message === null || message === void 0 ? void 0 : message.ctwaContext) === null || _a === void 0 ? void 0 : _a.sourceUrl) ? `${message.body}\n\n${message.ctwaContext.sourceUrl}` : message.body || "__UNHANDLED__";
544
+ break;
545
+ }
546
+ const newCWMessage = hasAttachments ? yield this.sendAttachmentMessage(text, message.chatId, message) : yield this.sendConversationMessage(text, message.chatId, message);
547
+ if (isNewConversation !== false) {
548
+ /**
549
+ * Wait 3 seconds before trying to check for an automated message
550
+ */
551
+ yield (0, tools_1.timeout)(3000);
552
+ /**
553
+ * Check the messages to see if a message_type: 3 comes through after the initial message;
554
+ */
555
+ const msgs = yield this.getAllInboxMessages(`${isNewConversation}`);
556
+ if (!msgs)
557
+ return;
558
+ /**
559
+ * Message IDs are numbers (for now)
560
+ */
561
+ const possibleWelcomeMessage = msgs.filter(m => m.id > newCWMessage.id).find(m => m.message_type === 3 && m.content_type !== 'input_csat');
562
+ if (!possibleWelcomeMessage)
563
+ return;
564
+ /**
565
+ * Ok reply with the welcome message now
566
+ */
567
+ yield this.client.sendText(message.chatId, possibleWelcomeMessage.content || "...");
568
+ }
569
+ }
570
+ catch (error) {
571
+ console.error(`Something went wrong processing this message: ${message.id}`, error);
563
572
  }
564
573
  });
565
574
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-wa/wa-automate",
3
- "version": "4.64.3",
3
+ "version": "4.64.5",
4
4
  "licenseCheckUrl": "https://funcs.openwa.dev/license-check",
5
5
  "brokenMethodReportUrl": "https://funcs.openwa.dev/report-bm",
6
6
  "patches": "https://cdn.openwa.dev/patches.json",
@@ -154,7 +154,7 @@
154
154
  "pidtree": "^0.6.0",
155
155
  "pidusage": "^3.0.0",
156
156
  "postman-2-swagger": "^0.5.0",
157
- "puppeteer": "^19.4.1",
157
+ "puppeteer": "^19.9.0",
158
158
  "puppeteer-extra": "^3.3.4",
159
159
  "puppeteer-extra-plugin-block-resources": "^2.4.2",
160
160
  "puppeteer-extra-plugin-devtools": "^2.4.4",