@peopl-health/nexus 5.58.0-dev.10499 → 5.58.1

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.
@@ -79,9 +79,19 @@ const officeVisibleQuery = (patientCode, assistant) => ({
79
79
  { from_me: false },
80
80
  { from_me: true, triggeredBy: assistant.email },
81
81
  { from_me: true, origin: 'whatsapp_platform', plainBody: { $regex: `^${escapeRegExp(assistant.label)}:` } },
82
+ // Context for the office: what the agent and PEOPL staff told the patient. Staff sends carry the sender's email;
83
+ // automated sends (reminders, retries) carry a job name and stay hidden.
84
+ { from_me: true, origin: 'assistant' },
85
+ { from_me: true, origin: 'whatsapp_platform', triggeredBy: { $regex: '@' } },
82
86
  ],
83
87
  });
84
88
 
89
+ function officeSenderOf(message, assistant) {
90
+ if (!message.from_me) return 'patient';
91
+ if (message.triggeredBy === assistant.email || String(message.plainBody ?? '').startsWith(`${assistant.label}:`)) return 'office';
92
+ return message.origin === 'assistant' ? 'agent' : 'team';
93
+ }
94
+
85
95
  async function readOfficeMessages({ requestedBy, code, limit }) {
86
96
  const assistant = await requireOfficeAssistant(requestedBy);
87
97
  const patientCode = await officePatientCode(assistant, code);
@@ -99,7 +109,7 @@ async function readOfficeMessages({ requestedBy, code, limit }) {
99
109
  id: String(message._id),
100
110
  body: message.plainBody ?? '',
101
111
  mediaType: message.media?.mediaType ?? null,
102
- sender: message.from_me ? 'office' : 'patient',
112
+ sender: officeSenderOf(message, assistant),
103
113
  status: message.statusInfo?.status ?? null,
104
114
  createdAt: message.createdAt,
105
115
  })),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peopl-health/nexus",
3
- "version": "5.58.0-dev.10499",
3
+ "version": "5.58.1",
4
4
  "description": "Core messaging and assistant library for WhatsApp communication platforms",
5
5
  "keywords": [
6
6
  "whatsapp",