@peopl-health/nexus 4.2.10 → 4.2.12
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.
|
@@ -547,33 +547,27 @@ class TwilioProvider extends MessageProvider {
|
|
|
547
547
|
|
|
548
548
|
async submitForApproval(contentSid, name, category) {
|
|
549
549
|
if (!contentSid) throw new Error('Content SID is required');
|
|
550
|
-
|
|
551
|
-
|
|
550
|
+
|
|
551
|
+
let approvalsUrl = null;
|
|
552
|
+
for (let attempt = 0; attempt < 3 && !approvalsUrl; attempt++) {
|
|
553
|
+
if (attempt > 0) await new Promise(r => setTimeout(r, 300));
|
|
554
|
+
const content = await this.getTemplate(contentSid);
|
|
552
555
|
const links = (content && content.links) || {};
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
contentSid,
|
|
558
|
-
warning: 'Twilio account does not expose an approvals endpoint. Approval must be handled manually in the Console.'
|
|
559
|
-
};
|
|
560
|
-
}
|
|
561
|
-
const payload = {
|
|
562
|
-
name,
|
|
563
|
-
category,
|
|
564
|
-
friendly_name: name,
|
|
565
|
-
categories: category ? [category] : undefined,
|
|
566
|
-
channel: 'whatsapp'
|
|
567
|
-
};
|
|
568
|
-
const resp = await axios.post(approvalsUrl, payload, { auth: { username: this.accountSid, password: this.authToken } });
|
|
569
|
-
return { success: true, contentSid, approvalRequest: resp.data || null };
|
|
570
|
-
} catch (error) {
|
|
571
|
-
return {
|
|
572
|
-
success: false,
|
|
573
|
-
contentSid,
|
|
574
|
-
warning: `Failed to submit for approval via API: ${error.message}`
|
|
575
|
-
};
|
|
556
|
+
approvalsUrl = links.approval_create || links.approvals || links.approvalRequests || links.approval_requests;
|
|
557
|
+
}
|
|
558
|
+
if (!approvalsUrl) {
|
|
559
|
+
throw new Error(`Approvals URL not available for template ${contentSid}`);
|
|
576
560
|
}
|
|
561
|
+
|
|
562
|
+
const payload = {
|
|
563
|
+
name,
|
|
564
|
+
category,
|
|
565
|
+
friendly_name: name,
|
|
566
|
+
categories: category ? [category] : undefined,
|
|
567
|
+
channel: 'whatsapp'
|
|
568
|
+
};
|
|
569
|
+
const resp = await axios.post(approvalsUrl, payload, { auth: { username: this.accountSid, password: this.authToken } });
|
|
570
|
+
return { success: true, contentSid, approvalRequest: resp.data || null };
|
|
577
571
|
}
|
|
578
572
|
|
|
579
573
|
async deleteTemplate(sid) {
|
|
@@ -92,24 +92,24 @@ class ScheduledMessageJob extends BaseJob {
|
|
|
92
92
|
});
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
95
|
+
try {
|
|
96
|
+
let parentMessageId = msg.parentMessageId || null;
|
|
97
|
+
if (!parentMessageId) {
|
|
98
|
+
const storage = this.requireMessageStorage?.();
|
|
99
|
+
if (storage?.savePendingMessage) {
|
|
100
|
+
const parent = await storage.savePendingMessage({
|
|
101
|
+
code: msg.code, body: msg.message, fileUrl: msg.fileUrl, fileType: msg.fileType,
|
|
102
|
+
contentSid: msg.contentSid, variables: msg.variables,
|
|
103
|
+
fromMe: true, processed: true,
|
|
104
|
+
frontendId: msg.frontendId, triggeredBy: msg.triggeredBy
|
|
105
|
+
});
|
|
106
|
+
parentMessageId = parent?._id || null;
|
|
107
|
+
if (parentMessageId) {
|
|
108
|
+
await ScheduledMessage.updateOne({ _id: scheduledMessageId }, { $set: { parentMessageId } });
|
|
109
|
+
}
|
|
108
110
|
}
|
|
109
111
|
}
|
|
110
|
-
}
|
|
111
112
|
|
|
112
|
-
try {
|
|
113
113
|
const result = await this.sendMessage({
|
|
114
114
|
code: msg.code,
|
|
115
115
|
body: msg.message,
|