@peopl-health/nexus 6.0.7 → 6.0.8

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.
@@ -5,7 +5,7 @@ const { getEscalationReview } = require('../models/escalationReviewModel');
5
5
  const { isWithin24HourWindow } = require('../helpers/conversationWindowHelper');
6
6
  const { readGroupMessageId } = require('../clinical/services/clinicalAirtableService');
7
7
 
8
- const { countMessages } = require('./messageService');
8
+ const { countMessages, getMessages } = require('./messageService');
9
9
  const { logPatientChange } = require('./patientService');
10
10
  const { getThreadInfo } = require('./threadService');
11
11
  const { AUTO_HANDOFF_OPERATOR, BOOKKEEPING, DRAFT_OPERATOR, MAX_DOCTOR_UPDATES, PRE_DECISION_STATUSES, caseTakenReason, handOffToDoctor, teamAlertIdentity } = require('./escalationReviewService');
@@ -26,6 +26,7 @@ const GRAVE_REASONS = { unobtainable: 'no lo puede dar', unanswered: 'no contest
26
26
  const QUIET_REMINDER_TEXT = '¿Pudiste ver lo que te pregunté? Cuando puedas, respóndeme por aquí.';
27
27
  // A reminder this late (an outage, a deploy) is not sent.
28
28
  const QUIET_REMINDER_STALE_MS = 30 * 60 * 1000;
29
+ const UNDELIVERED_STATUSES = ['failed', 'undelivered'];
29
30
  const getMessaging = () => require('../core/NexusMessaging');
30
31
 
31
32
  const noteOf = (text) => oneLineOf(text).slice(0, MAX_NOTE_LENGTH);
@@ -247,8 +248,14 @@ async function remindQuietPatient(review, clock, now) {
247
248
  // A short reply records no clinical update, so the patient's own messages decide whether she answered.
248
249
  if (await countMessages({ numero: review.patientCode, from_me: false, createdAt: { $gt: latest.createdAt } })) return;
249
250
 
251
+ // The draft's missing datum never reaches the bot, so the reminder needs a question of the bot's own still open in the chat.
252
+ // The reminder itself and a send that never arrived are no question of the bot's.
253
+ const [last] = await getMessages({
254
+ numero: review.patientCode, origin: { $nin: ['system', 'instruction'] }, body: { $ne: QUIET_REMINDER_TEXT }, 'statusInfo.status': { $nin: UNDELIVERED_STATUSES },
255
+ }, { sort: { createdAt: -1 }, limit: 1, select: 'from_me body' });
250
256
  let skippedReason = null;
251
257
  if (now.getTime() - dueAt.getTime() > QUIET_REMINDER_STALE_MS) skippedReason = 'stale';
258
+ else if (!last?.from_me || !String(last.body ?? '').includes('?')) skippedReason = 'no_open_question';
252
259
  else skippedReason = await takenOf(review, clock);
253
260
  if (!skippedReason && !await isWithin24HourWindow(review.patientCode)) skippedReason = 'outside_window';
254
261
  const entry = { draftAt: latest.createdAt, sentAt: now, skippedReason, delivered: null };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peopl-health/nexus",
3
- "version": "6.0.7",
3
+ "version": "6.0.8",
4
4
  "description": "Core messaging and assistant library for WhatsApp communication platforms",
5
5
  "keywords": [
6
6
  "whatsapp",