@peopl-health/nexus 1.7.0 → 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.
@@ -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 => `[${message.timestamp}] ${message.body}`)
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
- return `[${reply.timestamp}] ${reply.body}`;
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
- await provider.addMessage({
265
- conversationId: thread.thread_id,
266
- role: 'user',
267
- content: messagesChat,
268
- attachments: attachments
269
- });
270
-
271
- console.log('Formatted message:', formattedMessage);
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 },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peopl-health/nexus",
3
- "version": "1.7.0",
3
+ "version": "1.7.2",
4
4
  "description": "Core messaging and assistant library for WhatsApp communication platforms",
5
5
  "keywords": [
6
6
  "whatsapp",