wexa-chat 0.2.5 → 0.2.9
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/dist/index.d.cts +17 -1
- package/dist/index.d.ts +17 -1
- package/dist/index.js +30 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +30 -12
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -547,6 +547,8 @@ function createMessagesService(models, hooks = {}) {
|
|
|
547
547
|
const tasks = [];
|
|
548
548
|
let lastLinkedInId;
|
|
549
549
|
let lastWhatsAppId;
|
|
550
|
+
let linkedinChatId;
|
|
551
|
+
let whatsappChatId;
|
|
550
552
|
if (Array.isArray(source) && source.includes("linkedin")) {
|
|
551
553
|
const LinkedinConnector = connectorIds && connectorIds.linkedin;
|
|
552
554
|
lastLinkedInId = LinkedinConnector == null ? void 0 : LinkedinConnector.connectorId;
|
|
@@ -555,10 +557,18 @@ function createMessagesService(models, hooks = {}) {
|
|
|
555
557
|
name: "linkedin",
|
|
556
558
|
run: async () => {
|
|
557
559
|
const path = paths.linkedin.startChat(String(LinkedinConnector.connectorId));
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
560
|
+
try {
|
|
561
|
+
const res = await getAxios().post(path, {
|
|
562
|
+
linkedin_url: LinkedinConnector.contactId,
|
|
563
|
+
text
|
|
564
|
+
});
|
|
565
|
+
const data = res.data;
|
|
566
|
+
console.log("linkedinChatId", data);
|
|
567
|
+
linkedinChatId = data.chat_data.chat_id;
|
|
568
|
+
return { status: "fulfilled", value: data };
|
|
569
|
+
} catch (error) {
|
|
570
|
+
return { status: "rejected", reason: error };
|
|
571
|
+
}
|
|
562
572
|
}
|
|
563
573
|
});
|
|
564
574
|
} else {
|
|
@@ -579,7 +589,14 @@ function createMessagesService(models, hooks = {}) {
|
|
|
579
589
|
phone_numbers: sanitize(raw),
|
|
580
590
|
text
|
|
581
591
|
};
|
|
582
|
-
|
|
592
|
+
try {
|
|
593
|
+
const res = await getAxios().post(path, body);
|
|
594
|
+
const data = res.data;
|
|
595
|
+
whatsappChatId = data.chat_id;
|
|
596
|
+
return { status: "fulfilled", value: data };
|
|
597
|
+
} catch (error) {
|
|
598
|
+
return { status: "rejected", reason: error };
|
|
599
|
+
}
|
|
583
600
|
}
|
|
584
601
|
});
|
|
585
602
|
} else {
|
|
@@ -588,22 +605,21 @@ function createMessagesService(models, hooks = {}) {
|
|
|
588
605
|
}
|
|
589
606
|
if (tasks.length > 0) {
|
|
590
607
|
const results = await Promise.allSettled(tasks.map((t) => t.run()));
|
|
591
|
-
results.forEach((
|
|
608
|
+
results.forEach((result, idx) => {
|
|
609
|
+
var _a, _b, _c, _d, _e, _f;
|
|
592
610
|
const name = tasks[idx].name;
|
|
593
|
-
if (
|
|
611
|
+
if (result.status === "fulfilled") {
|
|
594
612
|
success_source.push(name);
|
|
595
613
|
} else {
|
|
596
|
-
const
|
|
597
|
-
res.reason.response.data.detail || res.reason.response.data || "Unknown error";
|
|
614
|
+
const error = ((_c = (_b = (_a = result.reason) == null ? void 0 : _a.response) == null ? void 0 : _b.data) == null ? void 0 : _c.detail) || ((_e = (_d = result.reason) == null ? void 0 : _d.response) == null ? void 0 : _e.data) || ((_f = result.reason) == null ? void 0 : _f.message) || "Unknown error";
|
|
598
615
|
failed_source.push({
|
|
599
616
|
source: name,
|
|
600
|
-
message: typeof
|
|
617
|
+
message: typeof error === "string" ? error : JSON.stringify(error)
|
|
601
618
|
});
|
|
619
|
+
console.error(`${name} failed:`, error);
|
|
602
620
|
}
|
|
603
621
|
});
|
|
604
|
-
console.log("results", results);
|
|
605
622
|
}
|
|
606
|
-
console.log("success_source", success_source);
|
|
607
623
|
const message = new Message({
|
|
608
624
|
organizationId,
|
|
609
625
|
conversationId,
|
|
@@ -624,6 +640,8 @@ function createMessagesService(models, hooks = {}) {
|
|
|
624
640
|
};
|
|
625
641
|
if (lastLinkedInId) conversationUpdate.lastLinkedInId = lastLinkedInId;
|
|
626
642
|
if (lastWhatsAppId) conversationUpdate.lastWhatsAppId = lastWhatsAppId;
|
|
643
|
+
if (linkedinChatId) conversationUpdate.linkedinChatId = linkedinChatId;
|
|
644
|
+
if (whatsappChatId) conversationUpdate.whatsappChatId = whatsappChatId;
|
|
627
645
|
await Conversation.findByIdAndUpdate(conversationId, {
|
|
628
646
|
$set: conversationUpdate
|
|
629
647
|
});
|