@peopl-health/nexus 1.5.3 → 1.5.4

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.
@@ -151,30 +151,67 @@ class TwilioProvider extends MessageProvider {
151
151
  }
152
152
 
153
153
  /**
154
- * Attempt to check approval status.
155
- * Twilio SDK may not expose approval requests directly; return content and null approval by default.
154
+ * Check template approval status using Twilio Content API helpers
156
155
  */
157
156
  async checkApprovalStatus(sid) {
157
+ if (!this.isConnected || !this.twilioClient) {
158
+ throw new Error('Twilio provider not initialized');
159
+ }
158
160
  if (!sid) throw new Error('Content SID is required');
159
- const content = await this.getTemplate(sid);
161
+
160
162
  try {
161
- const links = (content && content.links) || {};
162
- let approvalsUrl = links.approvals || links.approvalRequests || links.approval_requests;
163
- if (!approvalsUrl) {
164
- return { content, approvalRequest: null, warning: 'Approval endpoint not provided by Twilio' };
165
- }
166
- const resp = await axios.get(approvalsUrl, { auth: { username: this.accountSid, password: this.authToken } });
167
- const data = resp && resp.data ? resp.data : null;
168
- let approvals = [];
169
- if (data) {
170
- approvals = data.approval_requests || data.approvalRequests || data.results || data.data || (Array.isArray(data) ? data : []);
171
- if (!Array.isArray(approvals) && data.approvalRequest) approvals = [data.approvalRequest];
163
+ const content = await this.twilioClient.content.v1.contents(sid).fetch();
164
+ let processedApprovalRequest = null;
165
+
166
+ try {
167
+ const approvalRequest = await this.twilioClient.content.v1
168
+ .contents(sid)
169
+ .approvalFetch()
170
+ .fetch();
171
+
172
+ if (approvalRequest) {
173
+ processedApprovalRequest = {
174
+ sid: approvalRequest.sid,
175
+ status: 'UNKNOWN'
176
+ };
177
+
178
+ if (approvalRequest.whatsapp) {
179
+ processedApprovalRequest.status = approvalRequest.whatsapp.status?.toUpperCase() || 'UNKNOWN';
180
+ processedApprovalRequest.category = approvalRequest.whatsapp.category;
181
+ processedApprovalRequest.name = approvalRequest.whatsapp.name;
182
+ processedApprovalRequest.rejectionReason = approvalRequest.whatsapp.rejection_reason;
183
+ processedApprovalRequest.contentType = approvalRequest.whatsapp.content_type;
184
+ } else {
185
+ processedApprovalRequest.status = approvalRequest.status || 'PENDING';
186
+ }
187
+
188
+ if (processedApprovalRequest.status === 'approved') {
189
+ processedApprovalRequest.status = 'APPROVED';
190
+ } else if (processedApprovalRequest.status === 'rejected') {
191
+ processedApprovalRequest.status = 'REJECTED';
192
+ } else if (processedApprovalRequest.status === 'pending') {
193
+ processedApprovalRequest.status = 'PENDING';
194
+ }
195
+
196
+ if (approvalRequest.dateCreated || approvalRequest.date_created) {
197
+ processedApprovalRequest.dateCreated = approvalRequest.dateCreated || approvalRequest.date_created;
198
+ }
199
+
200
+ if (approvalRequest.dateUpdated || approvalRequest.date_updated) {
201
+ processedApprovalRequest.dateUpdated = approvalRequest.dateUpdated || approvalRequest.date_updated;
202
+ }
203
+ }
204
+ } catch (approvalError) {
205
+ console.warn('Approval request fetch failed:', approvalError?.message || approvalError);
172
206
  }
173
- const approvalRequest = Array.isArray(approvals) && approvals.length > 0 ? approvals[0] : null;
174
- return { content, approvalRequest };
207
+
208
+ return {
209
+ content,
210
+ approvalRequest: processedApprovalRequest
211
+ };
175
212
  } catch (error) {
176
- // If approval endpoint unavailable, return content only
177
- return { content, approvalRequest: null, warning: error.message };
213
+ console.error('Error checking approval status:', error);
214
+ throw error;
178
215
  }
179
216
  }
180
217
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peopl-health/nexus",
3
- "version": "1.5.3",
3
+ "version": "1.5.4",
4
4
  "description": "Core messaging and assistant library for WhatsApp communication platforms",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -67,7 +67,7 @@
67
67
  "baileys": "^6.4.0",
68
68
  "express": "4.21.2",
69
69
  "openai": "^4.0.0",
70
- "twilio": "^5.6.0"
70
+ "twilio": "5.6.0"
71
71
  },
72
72
  "devDependencies": {
73
73
  "@types/node": "^20.5.0",