wexa-chat 0.2.0 → 0.2.1

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
@@ -1,11 +1,10 @@
1
- import mongoose, { Schema } from 'mongoose';
2
1
  import axios from 'axios';
3
2
  import Redis from 'ioredis';
4
3
  import { WebSocketServer, WebSocket } from 'ws';
5
4
  import url from 'url';
6
5
 
7
6
  // src/models/Conversation.model.ts
8
- function createConversationModel(options, conn = mongoose.connection) {
7
+ function createConversationModel(options, conn) {
9
8
  const connectionId = conn.id || conn.name || "default";
10
9
  const registryKey = `${connectionId}:Conversation`;
11
10
  if (modelRegistry.has(registryKey)) {
@@ -17,6 +16,7 @@ function createConversationModel(options, conn = mongoose.connection) {
17
16
  modelRegistry.set(registryKey, existingModel);
18
17
  return existingModel;
19
18
  }
19
+ const Schema = conn.base.Schema;
20
20
  const ParticipantSchema = new Schema(
21
21
  {
22
22
  entityModel: {
@@ -70,13 +70,15 @@ function createConversationModel(options, conn = mongoose.connection) {
70
70
  modelRegistry.set(registryKey, model);
71
71
  return model;
72
72
  }
73
+
74
+ // src/models/Message.model.ts
73
75
  var sourceType = {
74
76
  LINKEDIN: "linkedin",
75
77
  WHATSAPP: "whatsapp",
76
78
  EMAIL: "email",
77
79
  CORE: "core"
78
80
  };
79
- function createMessageModel(options, conn = mongoose.connection) {
81
+ function createMessageModel(options, conn) {
80
82
  const connectionId = conn.id || conn.name || "default";
81
83
  const registryKey = `${connectionId}:Message`;
82
84
  if (modelRegistry.has(registryKey)) {
@@ -88,6 +90,7 @@ function createMessageModel(options, conn = mongoose.connection) {
88
90
  modelRegistry.set(registryKey, existingModel);
89
91
  return existingModel;
90
92
  }
93
+ const Schema = conn.base.Schema;
91
94
  const MessageSchema = new Schema(
92
95
  {
93
96
  organizationId: {
@@ -296,13 +299,23 @@ function createConversationsService(models) {
296
299
  * Create a new conversation or find existing one between participants
297
300
  */
298
301
  async createOrFindConversation(args) {
302
+ console.log("Creating or finding conversation for users:", {
303
+ args
304
+ });
299
305
  const { organizationId, a, b } = args;
306
+ console.log("Creating or finding conversation for users:", {
307
+ organizationId,
308
+ a,
309
+ b
310
+ });
300
311
  try {
312
+ console.log("asdfa");
301
313
  const existingConversation = await searchByParticipantPair(Conversation, {
302
314
  organizationId,
303
315
  a,
304
316
  b
305
317
  });
318
+ console.log("Existing conversation:", existingConversation);
306
319
  if (existingConversation) {
307
320
  return existingConversation;
308
321
  }
@@ -325,7 +338,9 @@ function createConversationsService(models) {
325
338
  lastMessageAt: /* @__PURE__ */ new Date()
326
339
  // Set initial lastMessageAt
327
340
  });
341
+ console.log("New conversation:", newConversation);
328
342
  await newConversation.save();
343
+ console.log("Saved conversation:", newConversation);
329
344
  return newConversation;
330
345
  } catch (error) {
331
346
  console.error("Error in createOrFindConversation:", error);
@@ -678,18 +693,18 @@ function createMessagesService(models, hooks = {}) {
678
693
  }
679
694
  sendersByModel[senderModel].add(senderId);
680
695
  });
681
- const mongoose3 = Message.base;
696
+ const mongoose = Message.base;
682
697
  const senders = {};
683
698
  await Promise.all(
684
699
  Object.entries(sendersByModel).map(async ([senderModel, senderIdsSet]) => {
685
700
  const modelName = modelMapping[senderModel] || senderModel;
686
701
  const senderIds = Array.from(senderIdsSet);
687
- if (!mongoose3.modelNames().includes(modelName)) {
702
+ if (!mongoose.modelNames().includes(modelName)) {
688
703
  console.warn(`Model ${modelName} not found for sender population`);
689
704
  return;
690
705
  }
691
706
  try {
692
- const SenderModel = mongoose3.model(modelName);
707
+ const SenderModel = mongoose.model(modelName);
693
708
  const modelSenders = await SenderModel.find({ _id: { $in: senderIds } }).select(fields).lean().exec();
694
709
  senders[senderModel] = {};
695
710
  modelSenders.forEach((sender) => {