@peopl-health/nexus 1.7.1 → 1.7.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/CHANGELOG.md +0 -0
- package/LICENSE +0 -0
- package/MIGRATION_GUIDE.md +0 -0
- package/README.md +0 -0
- package/examples/.env.example +0 -0
- package/examples/assistants/BaseAssistant.js +0 -0
- package/examples/assistants/DoctorScheduleAssistant.js +0 -0
- package/examples/assistants/ExampleAssistant.js +0 -0
- package/examples/assistants/index.js +0 -0
- package/examples/basic-usage.js +0 -0
- package/examples/consumer-server.js +0 -0
- package/lib/adapters/BaileysProvider.js +0 -0
- package/lib/adapters/TwilioProvider.js +0 -0
- package/lib/adapters/index.js +0 -0
- package/lib/adapters/registry.js +0 -0
- package/lib/assistants/BaseAssistant.js +0 -0
- package/lib/assistants/index.js +0 -0
- package/lib/config/airtableConfig.js +0 -0
- package/lib/config/awsConfig.js +0 -0
- package/lib/config/configLoader.js +0 -0
- package/lib/config/llmConfig.js +0 -0
- package/lib/config/mongoAuthConfig.js +0 -0
- package/lib/config/runtimeConfig.js +0 -0
- package/lib/controllers/assistantController.js +0 -0
- package/lib/controllers/conversationController.js +0 -0
- package/lib/controllers/mediaController.js +0 -0
- package/lib/controllers/messageController.js +0 -0
- package/lib/controllers/templateController.js +0 -0
- package/lib/controllers/templateFlowController.js +0 -0
- package/lib/controllers/uploadController.js +0 -0
- package/lib/core/MessageProvider.js +0 -0
- package/lib/core/NexusMessaging.js +7 -4
- package/lib/core/index.js +0 -0
- package/lib/helpers/assistantHelper.js +32 -12
- package/lib/helpers/baileysHelper.js +0 -0
- package/lib/helpers/filesHelper.js +0 -0
- package/lib/helpers/llmsHelper.js +0 -0
- package/lib/helpers/mediaHelper.js +0 -0
- package/lib/helpers/mongoHelper.js +0 -0
- package/lib/helpers/qrHelper.js +0 -0
- package/lib/helpers/twilioHelper.js +0 -0
- package/lib/helpers/twilioMediaProcessor.js +0 -0
- package/lib/helpers/whatsappHelper.js +0 -0
- package/lib/index.d.ts +0 -0
- package/lib/index.js +0 -0
- package/lib/interactive/index.js +0 -0
- package/lib/interactive/registry.js +0 -0
- package/lib/interactive/twilioMapper.js +0 -0
- package/lib/models/agendaMessageModel.js +0 -0
- package/lib/models/index.js +0 -0
- package/lib/models/messageModel.js +0 -0
- package/lib/models/templateModel.js +0 -0
- package/lib/models/threadModel.js +0 -0
- package/lib/providers/OpenAIProvider.js +0 -0
- package/lib/routes/index.js +0 -0
- package/lib/services/airtableService.js +0 -0
- package/lib/services/assistantService.js +0 -0
- package/lib/services/conversationService.js +0 -0
- package/lib/services/twilioService.js +0 -0
- package/lib/storage/MongoStorage.js +0 -0
- package/lib/storage/NoopStorage.js +0 -0
- package/lib/storage/index.js +0 -0
- package/lib/storage/registry.js +0 -0
- package/lib/templates/predefinedTemplates.js +0 -0
- package/lib/templates/templateStructure.js +0 -0
- package/lib/utils/dateUtils.js +0 -0
- package/lib/utils/defaultLLMProvider.js +0 -0
- package/lib/utils/errorHandler.js +0 -0
- package/lib/utils/index.js +0 -0
- package/lib/utils/logger.js +0 -0
- package/lib/utils/mediaValidator.js +0 -0
- package/lib/utils/messageParser.js +0 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
File without changes
|
package/LICENSE
CHANGED
|
File without changes
|
package/MIGRATION_GUIDE.md
CHANGED
|
File without changes
|
package/README.md
CHANGED
|
File without changes
|
package/examples/.env.example
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/examples/basic-usage.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/lib/adapters/index.js
CHANGED
|
File without changes
|
package/lib/adapters/registry.js
CHANGED
|
File without changes
|
|
File without changes
|
package/lib/assistants/index.js
CHANGED
|
File without changes
|
|
File without changes
|
package/lib/config/awsConfig.js
CHANGED
|
File without changes
|
|
File without changes
|
package/lib/config/llmConfig.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -598,16 +598,19 @@ class NexusMessaging {
|
|
|
598
598
|
try {
|
|
599
599
|
console.log(`Processing batched messages from ${chatId}`);
|
|
600
600
|
|
|
601
|
+
// Get assistant response
|
|
601
602
|
const botResponse = await replyAssistant(chatId);
|
|
602
603
|
if (botResponse && this.provider) {
|
|
603
|
-
await this.sendMessage({
|
|
604
|
-
|
|
605
|
-
message: botResponse
|
|
604
|
+
await this.provider.sendMessage({
|
|
605
|
+
to: chatId,
|
|
606
|
+
message: botResponse,
|
|
607
|
+
type: 'text'
|
|
606
608
|
});
|
|
607
609
|
}
|
|
608
610
|
|
|
611
|
+
// Emit event for batched processing
|
|
609
612
|
this.events.emit('messages:batched', { chatId, response: botResponse });
|
|
610
|
-
|
|
613
|
+
|
|
611
614
|
} catch (error) {
|
|
612
615
|
console.error('Error in batched message handling:', error);
|
|
613
616
|
}
|
package/lib/core/index.js
CHANGED
|
File without changes
|
|
@@ -10,6 +10,7 @@ const { getRecordByFilter } = require('../services/airtableService.js');
|
|
|
10
10
|
|
|
11
11
|
const fs = require('fs');
|
|
12
12
|
const path = require('path');
|
|
13
|
+
const moment = require('moment-timezone');
|
|
13
14
|
|
|
14
15
|
const mode = process.env.NODE_ENV || 'dev';
|
|
15
16
|
|
|
@@ -94,6 +95,7 @@ async function getLastMessages(code) {
|
|
|
94
95
|
);
|
|
95
96
|
}
|
|
96
97
|
|
|
98
|
+
console.log('[getLastMessages] Marked', patientReply.length, 'messages as processed');
|
|
97
99
|
return patientReply.reverse();
|
|
98
100
|
} catch (error) {
|
|
99
101
|
console.error('Error getting the last user messages:', error);
|
|
@@ -110,7 +112,8 @@ async function getLastNMessages(code, n) {
|
|
|
110
112
|
// Format each message and concatenate them with skip lines
|
|
111
113
|
const formattedMessages = lastMessages
|
|
112
114
|
.reverse()
|
|
113
|
-
.map(message =>
|
|
115
|
+
.map(message => formatMessage(message))
|
|
116
|
+
.filter(formatted => formatted !== null) // Filter out any null results from formatMessage
|
|
114
117
|
.join('\n\n');
|
|
115
118
|
|
|
116
119
|
console.log('[getLastNMessages] Fetched last messages:', formattedMessages);
|
|
@@ -144,7 +147,19 @@ const getPatientRoleAndName = (reply, numbers) => {
|
|
|
144
147
|
|
|
145
148
|
function formatMessage(reply) {
|
|
146
149
|
try {
|
|
147
|
-
|
|
150
|
+
// Validate timestamp exists
|
|
151
|
+
if (!reply.timestamp) {
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Convert timestamp to Mexico City timezone with Spanish format
|
|
156
|
+
// Format: martes, 30 de septiembre de 2025 a las 8:30 AM
|
|
157
|
+
const mexicoCityTime = moment(reply.timestamp)
|
|
158
|
+
.tz('America/Mexico_City')
|
|
159
|
+
.locale('es')
|
|
160
|
+
.format('dddd, D [de] MMMM [de] YYYY [a las] h:mm A');
|
|
161
|
+
|
|
162
|
+
return `[${mexicoCityTime}] ${reply.body}`;
|
|
148
163
|
} catch {
|
|
149
164
|
return null;
|
|
150
165
|
}
|
|
@@ -189,6 +204,7 @@ async function processIndividualMessage(code, reply, thread) {
|
|
|
189
204
|
try {
|
|
190
205
|
const provider = llmConfig.requireOpenAIProvider();
|
|
191
206
|
const formattedMessage = formatMessage(reply);
|
|
207
|
+
console.log('[processIndividualMessage] formattedMessage:', formattedMessage);
|
|
192
208
|
const isNotAssistant = !reply.from_me;
|
|
193
209
|
let messagesChat = [];
|
|
194
210
|
let attachments = [];
|
|
@@ -259,16 +275,20 @@ async function processIndividualMessage(code, reply, thread) {
|
|
|
259
275
|
}
|
|
260
276
|
|
|
261
277
|
console.log('messagesChat', messagesChat);
|
|
262
|
-
console.log('attachments', attachments);
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
278
|
+
console.log('[processIndividualMessage] attachments:', attachments);
|
|
279
|
+
console.log('[processIndividualMessage] formattedMessage:', formattedMessage);
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
// ONLY add user messages to the thread
|
|
283
|
+
if (isNotAssistant) {
|
|
284
|
+
await provider.addMessage({
|
|
285
|
+
conversationId: thread.thread_id,
|
|
286
|
+
role: 'user',
|
|
287
|
+
content: messagesChat,
|
|
288
|
+
attachments: attachments
|
|
289
|
+
});
|
|
290
|
+
console.log('[processIndividualMessage] User message added to thread');
|
|
291
|
+
}
|
|
272
292
|
|
|
273
293
|
await Message.updateOne(
|
|
274
294
|
{ message_id: reply.message_id, timestamp: reply.timestamp },
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/lib/helpers/qrHelper.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/lib/index.d.ts
CHANGED
|
File without changes
|
package/lib/index.js
CHANGED
|
File without changes
|
package/lib/interactive/index.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/lib/models/index.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/lib/routes/index.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/lib/storage/index.js
CHANGED
|
File without changes
|
package/lib/storage/registry.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/lib/utils/dateUtils.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/lib/utils/index.js
CHANGED
|
File without changes
|
package/lib/utils/logger.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|