@peopl-health/nexus 2.5.11 → 2.7.0
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/examples/basic-usage.js +3 -4
- package/lib/assistants/BaseAssistant.js +1 -16
- package/lib/config/airtableConfig.js +3 -0
- package/lib/controllers/conversationController.js +52 -42
- package/lib/core/NexusMessaging.js +66 -87
- package/lib/helpers/messageHelper.js +0 -26
- package/lib/models/messageModel.js +6 -0
- package/lib/providers/OpenAIResponsesProvider.js +85 -80
- package/lib/providers/OpenAIResponsesProviderTools.js +4 -1
- package/lib/providers/createProvider.js +11 -1
- package/lib/routes/index.js +1 -1
- package/lib/services/ConversationManager.js +43 -0
- package/lib/services/DefaultConversationManager.js +207 -0
- package/lib/services/airtableService.js +1 -1
- package/lib/services/assistantServiceCore.js +0 -23
- package/lib/services/conversationService.js +42 -10
- package/package.json +2 -2
|
@@ -12,6 +12,7 @@ const fetchConversationData = async (filter, skip, limit) => {
|
|
|
12
12
|
unread: { ...baseMatch, ...unreadMatch },
|
|
13
13
|
recent: { ...baseMatch, createdAt: { $gt: new Date(Date.now() - 24 * 60 * 60 * 1000) } },
|
|
14
14
|
'no-response': baseMatch,
|
|
15
|
+
'pending-review': baseMatch,
|
|
15
16
|
all: baseMatch
|
|
16
17
|
};
|
|
17
18
|
|
|
@@ -20,10 +21,36 @@ const fetchConversationData = async (filter, skip, limit) => {
|
|
|
20
21
|
|
|
21
22
|
const pipeline = [
|
|
22
23
|
{ $match: filterConditions },
|
|
23
|
-
{ $
|
|
24
|
-
{ $
|
|
25
|
-
|
|
24
|
+
{ $sort: { numero: 1, createdAt: -1 } },
|
|
25
|
+
{ $group: {
|
|
26
|
+
_id: '$numero',
|
|
27
|
+
latestMessage: { $first: {
|
|
28
|
+
_id: '$_id',
|
|
29
|
+
body: '$body',
|
|
30
|
+
createdAt: '$createdAt',
|
|
31
|
+
media: '$media',
|
|
32
|
+
nombre_whatsapp: '$nombre_whatsapp',
|
|
33
|
+
from_me: '$from_me'
|
|
34
|
+
} },
|
|
35
|
+
messageCount: { $sum: 1 }
|
|
36
|
+
} },
|
|
37
|
+
{ $match: { _id: { $nin: [null, ''] } } },
|
|
26
38
|
...(filter === 'no-response' ? [{ $match: { 'latestMessage.from_me': false } }] : []),
|
|
39
|
+
{
|
|
40
|
+
$lookup: {
|
|
41
|
+
from: 'threads',
|
|
42
|
+
localField: '_id',
|
|
43
|
+
foreignField: 'code',
|
|
44
|
+
as: 'threadInfo'
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
$addFields: {
|
|
49
|
+
review: { $arrayElemAt: ['$threadInfo.review', 0] }
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
{ $project: { threadInfo: 0 } },
|
|
53
|
+
...(filter === 'pending-review' ? [{ $match: { $or: [{ review: false }, { review: null }] } }] : []),
|
|
27
54
|
{ $sort: { 'latestMessage.createdAt': -1 } },
|
|
28
55
|
{ $skip: skip },
|
|
29
56
|
{ $limit: limit }
|
|
@@ -31,12 +58,16 @@ const fetchConversationData = async (filter, skip, limit) => {
|
|
|
31
58
|
|
|
32
59
|
const startTime = Date.now();
|
|
33
60
|
const [conversations, contactNames, unreadCounts, totalResult] = await Promise.all([
|
|
34
|
-
Message.aggregate(pipeline),
|
|
35
|
-
Message.aggregate([{ $match: { ...baseMatch, from_me: false } }, { $sort: { createdAt: -1 } }, { $group: { _id: '$numero', name: { $first: '$nombre_whatsapp' } } }]),
|
|
36
|
-
Message.aggregate([{ $match: { ...baseMatch, ...unreadMatch } }, { $group: { _id: '$numero', unreadCount: { $sum: 1 } } }]),
|
|
37
|
-
Message.aggregate(
|
|
38
|
-
|
|
39
|
-
|
|
61
|
+
Message.aggregate(pipeline, { allowDiskUse: true }),
|
|
62
|
+
Message.aggregate([{ $match: { ...baseMatch, from_me: false } }, { $sort: { createdAt: -1 } }, { $group: { _id: '$numero', name: { $first: '$nombre_whatsapp' } } }], { allowDiskUse: true }),
|
|
63
|
+
Message.aggregate([{ $match: { ...baseMatch, ...unreadMatch } }, { $group: { _id: '$numero', unreadCount: { $sum: 1 } } }], { allowDiskUse: true }),
|
|
64
|
+
Message.aggregate(
|
|
65
|
+
filter === 'no-response'
|
|
66
|
+
? [{ $match: baseMatch }, { $project: { numero: 1, from_me: 1, createdAt: 1 } }, { $sort: { createdAt: -1 } }, { $group: { _id: '$numero', latestMessage: { $first: '$$ROOT' } } }, { $match: { 'latestMessage.from_me': false } }, { $count: 'total' }]
|
|
67
|
+
: filter === 'pending-review'
|
|
68
|
+
? [{ $match: baseMatch }, { $group: { _id: '$numero' } }, { $lookup: { from: 'threads', localField: '_id', foreignField: 'code', as: 'threadInfo' } }, { $addFields: { review: { $arrayElemAt: ['$threadInfo.review', 0] } } }, { $match: { $or: [{ review: false }, { review: null }] } }, { $count: 'total' }]
|
|
69
|
+
: [{ $match: filterConditions }, { $group: { _id: '$numero' } }, { $count: 'total' }],
|
|
70
|
+
{ allowDiskUse: true }
|
|
40
71
|
)
|
|
41
72
|
]);
|
|
42
73
|
|
|
@@ -76,7 +107,8 @@ const processConversations = async (conversations, nameMap, unreadMap) => {
|
|
|
76
107
|
unreadCount: unreadMap[phoneNumber] || 0,
|
|
77
108
|
isLastMessageMedia: !!msg?.media,
|
|
78
109
|
lastMessageType: getMediaType(msg?.media),
|
|
79
|
-
lastMessageFromMe: msg?.from_me || false
|
|
110
|
+
lastMessageFromMe: msg?.from_me || false,
|
|
111
|
+
review: conv?.review || false
|
|
80
112
|
};
|
|
81
113
|
};
|
|
82
114
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peopl-health/nexus",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.7.0",
|
|
4
4
|
"description": "Core messaging and assistant library for WhatsApp communication platforms",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"whatsapp",
|
|
@@ -105,7 +105,7 @@
|
|
|
105
105
|
"peerDependencies": {
|
|
106
106
|
"@anthropic-ai/sdk": "^0.32.0",
|
|
107
107
|
"baileys": "^6.4.0",
|
|
108
|
-
"express": "4.
|
|
108
|
+
"express": "4.22.1",
|
|
109
109
|
"openai": "6.7.0",
|
|
110
110
|
"twilio": "5.6.0"
|
|
111
111
|
},
|