Skip to content

feat(whatsapp): B-Twilio-2 slice 1 — WABA transport adapter (dormant, flag-off; SMS send generalized) - #69

Merged
supmo668 merged 1 commit into
mainfrom
mangyinm/b-twilio-2-waba-transport
Jul 15, 2026
Merged

supmo668 merged 1 commit into
mainfrom
mangyinm/b-twilio-2-waba-transport

Conversation

@supmo668

@supmo668 supmo668 commented Jul 15, 2026 •

Copy link
Copy Markdown

Slice 1 of the Baileys→WABA migration (incremental landing per CTO directive): generalizes the landed Twilio send primitive to serve sms + whatsapp (same Messages.json; whatsapp: address prefix, idempotent + inbound bare-strip so WhatsApp STOP keys the same opt-out store). Lands DORMANT — nothing wired to the live Baileys channel; no live-channel behavior change. Slice 2 = dual-path flag + schema (with dormant prod-reject); slice 3 = cutover tooling. Cutover gated on Twilio test subaccount + E2E + explicit CTO go.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Improvements
    • Improved Twilio SMS delivery with more consistent message formatting and transport handling.
    • Added clearer handling for delivery failures, network issues, and invalid responses.
    • Protected sensitive authentication details from appearing in error results.
  • Bug Fixes
    • Corrected WhatsApp address formatting while preserving standard SMS addresses.
    • Improved normalization of inbound WhatsApp addresses for reliable message routing.
  • Tests
    • Added coverage for successful delivery, failures, network errors, authentication, and address formatting.

…er (WhatsApp send via Twilio, flag-off)

Generalizes the B-Twilio-1 send primitive to serve both SMS and WhatsApp (WABA) via Twilio — same Messages.json endpoint, only the address prefix differs. transport.ts: sendTwilioMessage (channel-parametrized: scoped-API-key auth, form-encode, discriminated result, secret hygiene — all shared), twilioAddress (whatsapp: prefix, idempotent), bareAddress (inbound strip for opt-out keying/routing so a STOP from whatsapp:+1... opts out the same peer). send.ts now delegates to it (SMS transport) — public API + landed tests unchanged (delegation parity, send.test 8/8 green). Vendor-agnostic rail holds: only this extension is Twilio-aware. FLAG-OFF: nothing wired to the live Baileys whatsapp channel — lands dormant + safe. 12 red-first transport tests incl. WABA send prefixing + no-leak. Full twilio suite 90/90; tsgo+lint+fmt clean. Next: slice 2 (dual-path flag + config schema, Baileys default).

Generated-With: Claude Code
Co-Authored-By: cto <[email protected]>
Co-Authored-By: Claude <[email protected]>
@coderabbitai

coderabbitai Bot commented Jul 15, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The Twilio REST implementation moves into a shared transport supporting SMS and WhatsApp address handling, typed results, authentication, response parsing, and error normalization. sendSms now delegates to that transport, with comprehensive transport tests.

Changes

Twilio transport extraction

Layer / File(s) Summary
Shared transport and address contracts
extensions/twilio/src/transport.ts
Adds Twilio transport types, address formatting helpers, authenticated form POST handling, response parsing, and normalized failure results.
SMS sender delegation
extensions/twilio/src/send.ts
Re-exports transport types and forwards SMS message data and credentials to sendTwilioMessage.
Transport behavior tests
extensions/twilio/src/transport.test.ts
Covers SMS and WhatsApp formatting, request authentication, successful responses, HTTP errors, network errors, and secret redaction.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant sendSms
  participant sendTwilioMessage
  participant Twilio
  sendSms->>sendTwilioMessage: Forward SMS message and credentials
  sendTwilioMessage->>Twilio: POST form-encoded message with Basic auth
  Twilio-->>sendTwilioMessage: Return response JSON or error
  sendTwilioMessage-->>sendSms: Return SendMessageResult
Loading

Possibly related PRs

  • Syntropy-Health/openclaw#68: Introduces the earlier Twilio sendSms REST implementation that this change refactors into the shared transport.

Poem

I’m a bunny with messages to send,
Now one transport handles each friend.
SMS hops, WhatsApp prefixes with care,
Errors return safely, secrets stay rare.
Tests thump their feet: “The flow is sound!”
Carrots and clean requests all around!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is a brief summary and omits the required template sections, including verification, security, and compatibility details. Add the template sections: Summary bullets, change type/scope, linked issue, behavior, security, verification, compatibility, recovery, and risks.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is specific and accurately reflects the Twilio/WABA transport generalization and dormant flag-off scope.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch mangyinm/b-twilio-2-waba-transport

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown

⚠️ Formal models conformance drift detected

The formal models extracted constants (generated/*) do not match this openclaw PR.

This check is informational (not blocking merges yet).
See the formal-models-conformance-drift artifact for the diff.

If this change is intentional, follow up by updating the formal models repo or regenerating the extracted artifacts there.

@supmo668
supmo668 merged commit 323dea7 into main Jul 15, 2026
18 of 23 checks passed
@supmo668
supmo668 deleted the mangyinm/b-twilio-2-waba-transport branch July 15, 2026 08:27

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@extensions/twilio/src/transport.ts`:
- Around line 79-86: Update the Twilio request around doFetch to apply a
configurable timeout via an abort signal, ensuring stalled connections are
cancelled. When the timeout expires, return the existing { ok: false, status:
null } result, while preserving normal response handling and existing error
behavior for other failures.
- Around line 87-100: Update the failure handling in the transport request flow
to redact every occurrence of auth.apiKeySecret from both caught exception
messages and HTTP response-derived messages before returning the { ok: false }
result. Apply the same fail-closed sanitization after JSON message extraction
and raw-body fallback, preserving status values and successful responses
unchanged.
- Around line 91-103: Update the response handling around both response.text()
calls in the transport request flow to catch rejected response-stream reads and
return the existing { ok: false } result shape with an appropriate error
message. Preserve the current JSON message extraction for successfully read
error bodies and the successful response path when its body is readable.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 4eacc4fb-4744-470d-afc1-01f9424b696e

📥 Commits

Reviewing files that changed from the base of the PR and between 26961d0 and 6ef7010.

📒 Files selected for processing (3)
  • extensions/twilio/src/send.ts
  • extensions/twilio/src/transport.test.ts
  • extensions/twilio/src/transport.ts

Comment on lines +79 to +86
response = await doFetch(url, {
method: "POST",
headers: {
Authorization: `Basic ${basic}`,
"Content-Type": "application/x-www-form-urlencoded",
},
body: form,
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Bound the Twilio request with a timeout.

No abort signal or timeout is applied, so a stalled Twilio connection can leave this promise pending indefinitely. Add a configurable timeout and return the existing { ok: false, status: null } result when it expires.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@extensions/twilio/src/transport.ts` around lines 79 - 86, Update the Twilio
request around doFetch to apply a configurable timeout via an abort signal,
ensuring stalled connections are cancelled. When the timeout expires, return the
existing { ok: false, status: null } result, while preserving normal response
handling and existing error behavior for other failures.

Comment on lines +87 to +100
} catch (err) {
return { ok: false, status: null, error: err instanceof Error ? err.message : String(err) };
}

if (!response.ok) {
const text = await response.text();
let message = text;
try {
const parsed = JSON.parse(text) as { message?: string };
if (parsed.message) message = parsed.message;
} catch {
// non-JSON body — surface the raw text
}
return { ok: false, status: response.status, error: message };

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

Redact the API-key secret from every surfaced error.

Thrown messages and raw HTTP bodies are returned verbatim. Either can contain auth.apiKeySecret, violating the stated fail-closed secret-hygiene contract. Redact the known secret or return normalized messages before constructing the failure result.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@extensions/twilio/src/transport.ts` around lines 87 - 100, Update the failure
handling in the transport request flow to redact every occurrence of
auth.apiKeySecret from both caught exception messages and HTTP response-derived
messages before returning the { ok: false } result. Apply the same fail-closed
sanitization after JSON message extraction and raw-body fallback, preserving
status values and successful responses unchanged.

Comment on lines +91 to +103
if (!response.ok) {
const text = await response.text();
let message = text;
try {
const parsed = JSON.parse(text) as { message?: string };
if (parsed.message) message = parsed.message;
} catch {
// non-JSON body — surface the raw text
}
return { ok: false, status: response.status, error: message };
}

const text = await response.text();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Handle response-body read failures without throwing.

Both response.text() calls are outside error handling. A rejected response stream therefore escapes the discriminated-result contract instead of returning { ok: false }.

Proposed fix
+  let text: string;
+  try {
+    text = await response.text();
+  } catch {
+    return { ok: false, status: response.status, error: "unable to read Twilio response body" };
+  }
+
   if (!response.ok) {
-    const text = await response.text();
     let message = text;
     // ...
   }

-  const text = await response.text();
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (!response.ok) {
const text = await response.text();
let message = text;
try {
const parsed = JSON.parse(text) as { message?: string };
if (parsed.message) message = parsed.message;
} catch {
// non-JSON body — surface the raw text
}
return { ok: false, status: response.status, error: message };
}
const text = await response.text();
let text: string;
try {
text = await response.text();
} catch {
return { ok: false, status: response.status, error: "unable to read Twilio response body" };
}
if (!response.ok) {
let message = text;
try {
const parsed = JSON.parse(text) as { message?: string };
if (parsed.message) message = parsed.message;
} catch {
// non-JSON body — surface the raw text
}
return { ok: false, status: response.status, error: message };
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@extensions/twilio/src/transport.ts` around lines 91 - 103, Update the
response handling around both response.text() calls in the transport request
flow to catch rejected response-stream reads and return the existing { ok: false
} result shape with an appropriate error message. Preserve the current JSON
message extraction for successfully read error bodies and the successful
response path when its body is readable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant