@peopl-health/nexus 5.55.0-dev.8148 → 5.55.0-dev.8169

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.
@@ -3,6 +3,7 @@ const runtimeConfig = require('../../config/runtimeConfig');
3
3
  const DEFAULT_OFFER_WINDOW_MS = 24 * 60 * 60 * 1000;
4
4
  const DEFAULT_HUMAN_QUIET_MS = 24 * 60 * 60 * 1000;
5
5
  const DEFAULT_ACTIVITY_QUIET_MS = 2 * 60 * 60 * 1000;
6
+ const DEFAULT_PAUSE_QUIET_MS = 10 * 60 * 1000;
6
7
  const DEFAULT_TAP_WINDOW_MS = 30 * 60 * 1000;
7
8
  const DEFAULT_PLEDGE_MS = 8 * 60 * 60 * 1000;
8
9
  const DEFAULT_SWEEP_INTERVAL_MS = 5 * 60 * 1000;
@@ -81,6 +82,7 @@ module.exports = {
81
82
  getOfferWindowMs: () => duration('offerWindowMs', 'PAUSED_SAFETY_NET_WINDOW_MS', DEFAULT_OFFER_WINDOW_MS),
82
83
  getHumanQuietMs: () => duration('humanQuietMs', 'SAFETY_NET_HUMAN_QUIET_MS', DEFAULT_HUMAN_QUIET_MS),
83
84
  getActivityQuietMs: () => duration('activityQuietMs', 'SAFETY_NET_ACTIVITY_QUIET_MS', DEFAULT_ACTIVITY_QUIET_MS),
85
+ getPauseQuietMs: () => duration('pauseQuietMs', 'SAFETY_NET_PAUSE_QUIET_MS', DEFAULT_PAUSE_QUIET_MS),
84
86
  getTapWindowMs: () => duration('tapWindowMs', 'SAFETY_NET_TAP_WINDOW_MS', DEFAULT_TAP_WINDOW_MS),
85
87
  getPledgeMs: () => duration('pledgeMs', 'SAFETY_NET_PLEDGE_MS', DEFAULT_PLEDGE_MS),
86
88
  getSweepIntervalMs: () => duration('sweepIntervalMs', 'SAFETY_NET_SWEEP_INTERVAL_MS', DEFAULT_SWEEP_INTERVAL_MS)
@@ -3,6 +3,7 @@ const {
3
3
  getActivityQuietMs,
4
4
  getHumanQuietMs,
5
5
  getOfferWindowMs,
6
+ getPauseQuietMs,
6
7
  getSafetyNetContentSid,
7
8
  getSafetyNetLabel,
8
9
  getSafetyNetPhone,
@@ -11,6 +12,7 @@ const {
11
12
  } = require('../config/safetyNetConfig');
12
13
  const { logger } = require('../../utils/logger');
13
14
 
15
+ const { pausedSince } = require('../../helpers/pausedThreadHelper');
14
16
  const { acquireSendClaim, completeSendClaim, releaseSendClaim } = require('../../helpers/sendClaimHelper');
15
17
 
16
18
  const { normalizePayload: normalize, registerInteractiveRoute, unregisterInteractiveRoute } = require('../../core/interactiveRouteService');
@@ -111,6 +113,7 @@ async function offerSafetyNet({ code, reason = PAUSED }) {
111
113
  try {
112
114
  if (!code || !getSafetyNetContentSid() || !getSafetyNetPhone()) return { sent: false, reason: 'not_configured' };
113
115
  if (await offerClaims().get(code)) return { sent: false, reason: 'recent_offer' };
116
+ if (await pausedSince(code, new Date(Date.now() - getPauseQuietMs()))) return { sent: false, reason: 'just_paused' };
114
117
  if (await humanRepliedSince(code, new Date(Date.now() - getHumanQuietMs()))) return { sent: false, reason: 'human_active' };
115
118
  if (await anyoneRepliedSince(code, new Date(Date.now() - getActivityQuietMs()))) return { sent: false, reason: 'conversation_active' };
116
119
 
@@ -15,7 +15,7 @@ const stopAssistantController = async (req, res) => {
15
15
 
16
16
  const stopped = typeof stop === 'string' ? stop === 'true' : !!stop;
17
17
  try {
18
- await switchThreadStoppedStatus(code, stopped);
18
+ await switchThreadStoppedStatus(code, stopped, { byOperator: true });
19
19
  return res.status(200).json({ success: true, message: stopped ? 'Assistant stopped' : 'Assistant resumed' });
20
20
  } catch (error) {
21
21
  logger.error('[AssistantController] Failed to stop assistant', { error: error.message, code });
@@ -12,4 +12,9 @@ async function botIsPaused(code, { label = '[pausedThread]' } = {}) {
12
12
  }
13
13
  }
14
14
 
15
- module.exports = { botIsPaused };
15
+ async function pausedSince(code, since) {
16
+ const paused = await Thread.findOne({ code, stopped: true, pausedAt: { $gt: since } }, { _id: 1 }).lean();
17
+ return Boolean(paused);
18
+ }
19
+
20
+ module.exports = { botIsPaused, pausedSince };
package/lib/index.d.ts CHANGED
@@ -63,6 +63,7 @@ declare module '@peopl-health/nexus' {
63
63
  runId?: string;
64
64
  nombre?: string;
65
65
  stopped?: boolean;
66
+ pausedAt?: Date | null;
66
67
  nextSid?: string[];
67
68
  createdAt: Date;
68
69
  }
@@ -10,6 +10,7 @@ const threadSchema = new mongoose.Schema({
10
10
  run_id: { type: String, default: null },
11
11
  nombre: { type: String, default: null },
12
12
  stopped: { type: Boolean, default: false },
13
+ pausedAt: { type: Date, default: null },
13
14
  review: { type: Boolean, default: false },
14
15
  version: { type: Number, default: null },
15
16
  preset_id: { type: String, default: null },
@@ -34,8 +34,12 @@ const getThreadInfo = async (code) => {
34
34
  }
35
35
  };
36
36
 
37
- const switchThreadStoppedStatus = async (code, stopped) => {
38
- await Thread.updateOne({ code }, { stopped });
37
+ const switchThreadStoppedStatus = async (code, stopped, { byOperator = false } = {}) => {
38
+ if (stopped && byOperator) {
39
+ await Thread.updateOne({ code, stopped: { $ne: true } }, { stopped, pausedAt: new Date() });
40
+ } else {
41
+ await Thread.updateOne({ code }, stopped ? { stopped } : { stopped, pausedAt: null });
42
+ }
39
43
 
40
44
  updateRecordByFilter(Monitoreo_ID, 'message_monitor', `{whatsapp_id} = "${code}"`, { stopped }, code)
41
45
  .catch(err => logger.error('[switchThreadStoppedStatus] Failed to update message_monitor', { code, error: err.message }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peopl-health/nexus",
3
- "version": "5.55.0-dev.8148",
3
+ "version": "5.55.0-dev.8169",
4
4
  "description": "Core messaging and assistant library for WhatsApp communication platforms",
5
5
  "keywords": [
6
6
  "whatsapp",