wexa-chat 0.3.1 → 0.3.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.
package/dist/index.mjs CHANGED
@@ -558,6 +558,7 @@ function createMessagesService(models, hooks = {}) {
558
558
  * @returns The created message
559
559
  */
560
560
  async sendMessage(args) {
561
+ var _a, _b;
561
562
  const {
562
563
  organizationId,
563
564
  conversationId,
@@ -651,7 +652,7 @@ function createMessagesService(models, hooks = {}) {
651
652
  tasks.push({
652
653
  name: "email",
653
654
  run: async () => {
654
- var _a;
655
+ var _a2;
655
656
  const path = paths.email.sendEmail(String(emailConnector.connectorId));
656
657
  const primaryRecipient = {
657
658
  display_name: (emailMeta == null ? void 0 : emailMeta.recipientName) || "Recipient",
@@ -704,7 +705,7 @@ function createMessagesService(models, hooks = {}) {
704
705
  const res = await getAxios().post(path, payload);
705
706
  console.log("Email response:", res.data);
706
707
  const data = res.data;
707
- if ((_a = data.mail_sent_data) == null ? void 0 : _a.provider_id) {
708
+ if ((_a2 = data.mail_sent_data) == null ? void 0 : _a2.provider_id) {
708
709
  emailChatId = data.mail_sent_data.provider_id;
709
710
  console.log("Email provider_id extracted:", emailChatId);
710
711
  } else {
@@ -723,12 +724,12 @@ function createMessagesService(models, hooks = {}) {
723
724
  if (tasks.length > 0) {
724
725
  const results = await Promise.allSettled(tasks.map((t) => t.run()));
725
726
  results.forEach((result, idx) => {
726
- var _a, _b, _c, _d, _e, _f;
727
+ var _a2, _b2, _c, _d, _e, _f;
727
728
  const name = tasks[idx].name;
728
729
  if (result.status === "fulfilled") {
729
730
  success_source.push(name);
730
731
  } else {
731
- 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";
732
+ const error = ((_c = (_b2 = (_a2 = result.reason) == null ? void 0 : _a2.response) == null ? void 0 : _b2.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";
732
733
  failed_source.push({
733
734
  source: name,
734
735
  message: typeof error === "string" ? error : JSON.stringify(error)
@@ -771,7 +772,9 @@ function createMessagesService(models, hooks = {}) {
771
772
  if (lastEmailId) conversationUpdate.lastEmailId = lastEmailId;
772
773
  if (linkedinChatId) conversationUpdate.linkedinChatId = linkedinChatId;
773
774
  if (whatsappChatId) conversationUpdate.whatsappChatId = whatsappChatId;
774
- if (emailChatId) conversationUpdate.emailChatId = emailChatId;
775
+ if (emailChatId && !((_b = (_a = args.metadata) == null ? void 0 : _a.email) == null ? void 0 : _b.replyTo)) {
776
+ conversationUpdate.emailChatId = emailChatId;
777
+ }
775
778
  await Conversation.findByIdAndUpdate(conversationId, {
776
779
  $set: conversationUpdate
777
780
  });