@peopl-health/nexus 5.56.12 → 5.56.13
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.
|
@@ -6,7 +6,7 @@ const { Thread } = require('../models/threadModel');
|
|
|
6
6
|
const { botIsPaused } = require('../helpers/pausedThreadHelper');
|
|
7
7
|
const { isWithin24HourWindow } = require('../helpers/conversationWindowHelper');
|
|
8
8
|
const { inboundRecoveryLive } = require('../clinical/flags/inboundRecoveryFlags');
|
|
9
|
-
const { recordUnresolvedRequest } = require('../clinical/services/clinicalAirtableService');
|
|
9
|
+
const { formatOpsAlert, recordUnresolvedRequest } = require('../clinical/services/clinicalAirtableService');
|
|
10
10
|
const { WriteClaimStore } = require('../clinical/services/writeClaimStore');
|
|
11
11
|
const { getMessages, countMessages, aggregateMessages } = require('./messageService');
|
|
12
12
|
|
|
@@ -24,6 +24,7 @@ const recoveryClaims = new WriteClaimStore({ namespace: 'inbound-recovery', ttlM
|
|
|
24
24
|
const ticketClaims = new WriteClaimStore({ namespace: 'inbound-recovery-ticket', ttlMs: CLAIM_TTL_MS, maxSize: 500 });
|
|
25
25
|
|
|
26
26
|
const FAILED_SEND = { 'statusInfo.status': 'failed', message_id: null };
|
|
27
|
+
const UNANSWERED_QUESTION = 'El paciente escribió y no recibió respuesta.';
|
|
27
28
|
|
|
28
29
|
async function unansweredThreads(now) {
|
|
29
30
|
return Thread.find(
|
|
@@ -67,9 +68,17 @@ async function stillUnanswered(code, now = new Date()) {
|
|
|
67
68
|
return replies === 0 ? newest : null;
|
|
68
69
|
}
|
|
69
70
|
|
|
70
|
-
|
|
71
|
+
// This sweep only ever looks at the last hour, so minutes is the only unit it can reach.
|
|
72
|
+
const waitedFor = (ageMs) => `lleva ${Math.max(0, Math.round(ageMs / 60000))} min sin respuesta`;
|
|
73
|
+
|
|
74
|
+
async function fileTicket(code, alert, ageMs) {
|
|
71
75
|
try {
|
|
72
|
-
return Boolean(await alert({
|
|
76
|
+
return Boolean(await alert({
|
|
77
|
+
code,
|
|
78
|
+
category: 'contact_team_member',
|
|
79
|
+
question: UNANSWERED_QUESTION,
|
|
80
|
+
details: formatOpsAlert(code, { label: 'Paciente sin respuesta', summary: waitedFor(ageMs) }),
|
|
81
|
+
}));
|
|
73
82
|
} catch (error) {
|
|
74
83
|
logger.error('[inboundRecovery] could not file the ops ticket', { code, error: error.message });
|
|
75
84
|
return false;
|
|
@@ -142,7 +151,7 @@ async function sweepUnansweredInbound({
|
|
|
142
151
|
if (ticket !== 'acquired') { skipped += 1; continue; }
|
|
143
152
|
|
|
144
153
|
logger.error('[inboundRecovery] a replay already ran and the patient is still unanswered', { code, ageMs });
|
|
145
|
-
if (await fileTicket(code, alert)) {
|
|
154
|
+
if (await fileTicket(code, alert, ageMs)) {
|
|
146
155
|
alerted += 1;
|
|
147
156
|
} else {
|
|
148
157
|
await ticketGate.release(key);
|
|
@@ -168,7 +177,7 @@ async function sweepUnansweredInbound({
|
|
|
168
177
|
logger.error('[inboundRecovery] patient was left unanswered', {
|
|
169
178
|
code, ageMs, recoveryLive: canRecover, reachable,
|
|
170
179
|
});
|
|
171
|
-
if (await fileTicket(code, alert)) {
|
|
180
|
+
if (await fileTicket(code, alert, ageMs)) {
|
|
172
181
|
alerted += 1;
|
|
173
182
|
} else {
|
|
174
183
|
await claims.release(key);
|