From 477038a052abbce4c62b70b126a65cb9241cac09 Mon Sep 17 00:00:00 2001 From: Noa Flaherty Date: Mon, 23 Feb 2026 20:42:41 -0500 Subject: [PATCH] fix: sms_doctor readiness call, send_test assistantId, and Twilio error body handling Co-Authored-By: Claude --- assistant/src/daemon/handlers/config.ts | 9 ++++++--- gateway/src/http/routes/sms-deliver.ts | 5 +++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/assistant/src/daemon/handlers/config.ts b/assistant/src/daemon/handlers/config.ts index 10f9d9b48aa..aa4a09906be 100644 --- a/assistant/src/daemon/handlers/config.ts +++ b/assistant/src/daemon/handlers/config.ts @@ -1895,7 +1895,10 @@ export async function handleTwilioConfig( const raw = loadRawConfig(); const smsSection = (raw?.sms ?? {}) as Record; - const from = (smsSection.phoneNumber as string | undefined) + const assistantId = msg.assistantId as string | undefined; + const assistantMapping = (smsSection.assistantPhoneNumbers as Record | undefined) ?? {}; + const from = (assistantId && assistantMapping[assistantId]) + || (smsSection.phoneNumber as string | undefined) || getSecureKey('credential:twilio:phone_number') || ''; if (!from) { @@ -1923,7 +1926,7 @@ export async function handleTwilioConfig( 'Content-Type': 'application/json', ...(bearerToken ? { Authorization: `Bearer ${bearerToken}` } : {}), }, - body: JSON.stringify({ to, text }), + body: JSON.stringify({ to, text, ...(assistantId ? { assistantId } : {}) }), signal: AbortSignal.timeout(30_000), }); @@ -1995,7 +1998,7 @@ export async function handleTwilioConfig( const readinessIssues: string[] = []; try { const readinessService = getReadinessService(); - const snapshot = await readinessService.getReadiness('sms', { includeRemote: false }); + const [snapshot] = await readinessService.getReadiness('sms', false); readinessReady = snapshot.ready; for (const r of snapshot.reasons) { readinessIssues.push(r.text); diff --git a/gateway/src/http/routes/sms-deliver.ts b/gateway/src/http/routes/sms-deliver.ts index 087a4f5ef61..e97f47ad368 100644 --- a/gateway/src/http/routes/sms-deliver.ts +++ b/gateway/src/http/routes/sms-deliver.ts @@ -42,11 +42,12 @@ async function sendTwilioSms( if (!response.ok) { // Try to parse structured error details from the Twilio error body let errorText: string; + const rawBody = await response.text().catch(() => ""); try { - const errBody = await response.json() as Record; + const errBody = JSON.parse(rawBody) as Record; errorText = `Twilio Messages API error ${response.status}: code=${errBody.code ?? "unknown"} message=${errBody.message ?? "unknown"}`; } catch { - errorText = `Twilio Messages API error ${response.status}: ${await response.text().catch(() => "")}`; + errorText = `Twilio Messages API error ${response.status}: ${rawBody}`; } throw new Error(errorText); }