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.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +25 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +21 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -147,7 +147,7 @@ interface IMessage extends Document {
|
|
|
147
147
|
/**
|
|
148
148
|
* Create (or retrieve) Message model safely
|
|
149
149
|
*/
|
|
150
|
-
declare function createMessageModel(options: InitOptions, conn
|
|
150
|
+
declare function createMessageModel(options: InitOptions, conn: Connection): Model<IMessage>;
|
|
151
151
|
|
|
152
152
|
declare const modelRegistry: Map<string, mongoose.Model<any, {}, {}, {}, any, any>>;
|
|
153
153
|
/**
|
|
@@ -266,7 +266,7 @@ interface IConversation extends Document {
|
|
|
266
266
|
/**
|
|
267
267
|
* Create (or retrieve) Conversation model safely
|
|
268
268
|
*/
|
|
269
|
-
declare function createConversationModel(options: InitOptions, conn
|
|
269
|
+
declare function createConversationModel(options: InitOptions, conn: Connection): Model<IConversation>;
|
|
270
270
|
|
|
271
271
|
/**
|
|
272
272
|
* Pagination result interface
|
package/dist/index.d.ts
CHANGED
|
@@ -147,7 +147,7 @@ interface IMessage extends Document {
|
|
|
147
147
|
/**
|
|
148
148
|
* Create (or retrieve) Message model safely
|
|
149
149
|
*/
|
|
150
|
-
declare function createMessageModel(options: InitOptions, conn
|
|
150
|
+
declare function createMessageModel(options: InitOptions, conn: Connection): Model<IMessage>;
|
|
151
151
|
|
|
152
152
|
declare const modelRegistry: Map<string, mongoose.Model<any, {}, {}, {}, any, any>>;
|
|
153
153
|
/**
|
|
@@ -266,7 +266,7 @@ interface IConversation extends Document {
|
|
|
266
266
|
/**
|
|
267
267
|
* Create (or retrieve) Conversation model safely
|
|
268
268
|
*/
|
|
269
|
-
declare function createConversationModel(options: InitOptions, conn
|
|
269
|
+
declare function createConversationModel(options: InitOptions, conn: Connection): Model<IConversation>;
|
|
270
270
|
|
|
271
271
|
/**
|
|
272
272
|
* Pagination result interface
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var mongoose = require('mongoose');
|
|
4
3
|
var axios = require('axios');
|
|
5
4
|
var Redis = require('ioredis');
|
|
6
5
|
var ws = require('ws');
|
|
@@ -8,13 +7,12 @@ var url = require('url');
|
|
|
8
7
|
|
|
9
8
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
9
|
|
|
11
|
-
var mongoose__default = /*#__PURE__*/_interopDefault(mongoose);
|
|
12
10
|
var axios__default = /*#__PURE__*/_interopDefault(axios);
|
|
13
11
|
var Redis__default = /*#__PURE__*/_interopDefault(Redis);
|
|
14
12
|
var url__default = /*#__PURE__*/_interopDefault(url);
|
|
15
13
|
|
|
16
14
|
// src/models/Conversation.model.ts
|
|
17
|
-
function createConversationModel(options, conn
|
|
15
|
+
function createConversationModel(options, conn) {
|
|
18
16
|
const connectionId = conn.id || conn.name || "default";
|
|
19
17
|
const registryKey = `${connectionId}:Conversation`;
|
|
20
18
|
if (modelRegistry.has(registryKey)) {
|
|
@@ -26,7 +24,8 @@ function createConversationModel(options, conn = mongoose__default.default.conne
|
|
|
26
24
|
modelRegistry.set(registryKey, existingModel);
|
|
27
25
|
return existingModel;
|
|
28
26
|
}
|
|
29
|
-
const
|
|
27
|
+
const Schema = conn.base.Schema;
|
|
28
|
+
const ParticipantSchema = new Schema(
|
|
30
29
|
{
|
|
31
30
|
entityModel: {
|
|
32
31
|
type: String,
|
|
@@ -45,7 +44,7 @@ function createConversationModel(options, conn = mongoose__default.default.conne
|
|
|
45
44
|
},
|
|
46
45
|
{ _id: false }
|
|
47
46
|
);
|
|
48
|
-
const ConversationSchema = new
|
|
47
|
+
const ConversationSchema = new Schema(
|
|
49
48
|
{
|
|
50
49
|
organizationId: {
|
|
51
50
|
type: String,
|
|
@@ -71,7 +70,7 @@ function createConversationModel(options, conn = mongoose__default.default.conne
|
|
|
71
70
|
lastMessagePreview: String,
|
|
72
71
|
lastMessageSenderId: String,
|
|
73
72
|
lastMessageSenderModel: String,
|
|
74
|
-
metadata:
|
|
73
|
+
metadata: Schema.Types.Mixed
|
|
75
74
|
},
|
|
76
75
|
{ timestamps: true }
|
|
77
76
|
);
|
|
@@ -79,13 +78,15 @@ function createConversationModel(options, conn = mongoose__default.default.conne
|
|
|
79
78
|
modelRegistry.set(registryKey, model);
|
|
80
79
|
return model;
|
|
81
80
|
}
|
|
81
|
+
|
|
82
|
+
// src/models/Message.model.ts
|
|
82
83
|
var sourceType = {
|
|
83
84
|
LINKEDIN: "linkedin",
|
|
84
85
|
WHATSAPP: "whatsapp",
|
|
85
86
|
EMAIL: "email",
|
|
86
87
|
CORE: "core"
|
|
87
88
|
};
|
|
88
|
-
function createMessageModel(options, conn
|
|
89
|
+
function createMessageModel(options, conn) {
|
|
89
90
|
const connectionId = conn.id || conn.name || "default";
|
|
90
91
|
const registryKey = `${connectionId}:Message`;
|
|
91
92
|
if (modelRegistry.has(registryKey)) {
|
|
@@ -97,7 +98,8 @@ function createMessageModel(options, conn = mongoose__default.default.connection
|
|
|
97
98
|
modelRegistry.set(registryKey, existingModel);
|
|
98
99
|
return existingModel;
|
|
99
100
|
}
|
|
100
|
-
const
|
|
101
|
+
const Schema = conn.base.Schema;
|
|
102
|
+
const MessageSchema = new Schema(
|
|
101
103
|
{
|
|
102
104
|
organizationId: {
|
|
103
105
|
type: String,
|
|
@@ -305,13 +307,23 @@ function createConversationsService(models) {
|
|
|
305
307
|
* Create a new conversation or find existing one between participants
|
|
306
308
|
*/
|
|
307
309
|
async createOrFindConversation(args) {
|
|
310
|
+
console.log("Creating or finding conversation for users:", {
|
|
311
|
+
args
|
|
312
|
+
});
|
|
308
313
|
const { organizationId, a, b } = args;
|
|
314
|
+
console.log("Creating or finding conversation for users:", {
|
|
315
|
+
organizationId,
|
|
316
|
+
a,
|
|
317
|
+
b
|
|
318
|
+
});
|
|
309
319
|
try {
|
|
320
|
+
console.log("asdfa");
|
|
310
321
|
const existingConversation = await searchByParticipantPair(Conversation, {
|
|
311
322
|
organizationId,
|
|
312
323
|
a,
|
|
313
324
|
b
|
|
314
325
|
});
|
|
326
|
+
console.log("Existing conversation:", existingConversation);
|
|
315
327
|
if (existingConversation) {
|
|
316
328
|
return existingConversation;
|
|
317
329
|
}
|
|
@@ -334,7 +346,9 @@ function createConversationsService(models) {
|
|
|
334
346
|
lastMessageAt: /* @__PURE__ */ new Date()
|
|
335
347
|
// Set initial lastMessageAt
|
|
336
348
|
});
|
|
349
|
+
console.log("New conversation:", newConversation);
|
|
337
350
|
await newConversation.save();
|
|
351
|
+
console.log("Saved conversation:", newConversation);
|
|
338
352
|
return newConversation;
|
|
339
353
|
} catch (error) {
|
|
340
354
|
console.error("Error in createOrFindConversation:", error);
|
|
@@ -687,18 +701,18 @@ function createMessagesService(models, hooks = {}) {
|
|
|
687
701
|
}
|
|
688
702
|
sendersByModel[senderModel].add(senderId);
|
|
689
703
|
});
|
|
690
|
-
const
|
|
704
|
+
const mongoose = Message.base;
|
|
691
705
|
const senders = {};
|
|
692
706
|
await Promise.all(
|
|
693
707
|
Object.entries(sendersByModel).map(async ([senderModel, senderIdsSet]) => {
|
|
694
708
|
const modelName = modelMapping[senderModel] || senderModel;
|
|
695
709
|
const senderIds = Array.from(senderIdsSet);
|
|
696
|
-
if (!
|
|
710
|
+
if (!mongoose.modelNames().includes(modelName)) {
|
|
697
711
|
console.warn(`Model ${modelName} not found for sender population`);
|
|
698
712
|
return;
|
|
699
713
|
}
|
|
700
714
|
try {
|
|
701
|
-
const SenderModel =
|
|
715
|
+
const SenderModel = mongoose.model(modelName);
|
|
702
716
|
const modelSenders = await SenderModel.find({ _id: { $in: senderIds } }).select(fields).lean().exec();
|
|
703
717
|
senders[senderModel] = {};
|
|
704
718
|
modelSenders.forEach((sender) => {
|