Skip to content

refactor(channels): Deduplicate send_response across messaging channels - #94

Merged
xinghaohuang91 merged 2 commits into
mainfrom
refactor/dedupe-send-response
Aug 4, 2026
Merged

refactor(channels): Deduplicate send_response across messaging channels#94
xinghaohuang91 merged 2 commits into
mainfrom
refactor/dedupe-send-response

Conversation

@xinghaohuang91

@xinghaohuang91 xinghaohuang91 commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Summary

SMS, RCS, WhatsApp, and Chat each had a nearly-identical send_response() implementation (type/session/participant validation, building ActionChannelSettings, constructing the SendMessageActionRequest, calling create_action, and logging). This consolidates the shared logic into MessagingChannel.send_response() in src/tac/channels/messaging.py, leaving one overridable hook — _build_channel_settings() — for the one real behavioral difference: Chat requires channel_id (raises RuntimeError if missing), while SMS/RCS/WhatsApp treat it as optional.

Net effect: ~370 lines of duplicated logic removed from sms.py/rcs.py/whatsapp.py/chat.py, with no changes to public API signatures.

Behavior changes (minor, non-functional):

  • Error/log messages now consistently use the wire channel name (SMS, RCS, WHATSAPP, CHAT) instead of a mix of that and a display form (WhatsApp, Chat) — two test assertions were updated to match.
  • The "sent response" log line now includes both to_address and channel_id for every channel (previously Chat only logged channel_id, others only logged to_address).

Also clarified the send_response() docstring: the shared base interface's type annotation allows str | AsyncGenerator[...] (to accommodate the Voice channel, which supports streaming), but messaging channels only ever accept str and raise TypeError for anything else, since they send a single complete message via the Conversation Orchestrator Send API and have no streaming path.

How to test

  • make check (lint + type-check + test) — all passing locally.
  • No behavior change to the public send_response() call signature or contract; existing channel tests (test_sms_channel.py, test_rcs_channel.py, test_whatsapp_channel.py, test_chat_channel.py) cover this path.

SDK Parity

  • Change is Python-specific (no TypeScript update needed) — this only reorganizes internal Python implementation, no public API or wire behavior change.

SMS, RCS, WhatsApp, and Chat each reimplemented an almost identical
send_response (validation, ActionChannelSettings building, Actions API
call, logging). Consolidate the shared logic into MessagingChannel,
with channel_settings construction as the one real per-channel override
point (chat requires channel_id; others treat it as optional).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 30, 2026 17:25

Copilot AI 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.

Pull request overview

Note

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Refactors messaging channels to remove duplicated send_response() logic by centralizing it in MessagingChannel, while keeping per-channel customization via _build_channel_settings() (notably: Chat requires channel_id).

Changes:

  • Introduces shared MessagingChannel.send_response() and default _build_channel_settings() implementation.
  • Removes per-channel send_response() duplicates from SMS/RCS/WhatsApp/Chat; Chat overrides _build_channel_settings() to require channel_id.
  • Updates tests to expect standardized error messages using wire channel names.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/tac/channels/messaging.py Adds shared send_response() and default ActionChannelSettings construction hook
src/tac/channels/chat.py Replaces custom send_response() with _build_channel_settings() requiring channel_id
src/tac/channels/sms.py Removes duplicated send_response() implementation in favor of base behavior
src/tac/channels/rcs.py Removes duplicated send_response() implementation in favor of base behavior
src/tac/channels/whatsapp.py Removes duplicated send_response() implementation in favor of base behavior
tests/test_chat_channel.py Updates assertion to match standardized error message
tests/test_whatsapp_channel.py Updates assertion to match standardized error message

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/tac/channels/messaging.py
Comment thread src/tac/channels/messaging.py
…ing channels

Messaging channels (SMS/RCS/WhatsApp/Chat) only support a single
complete string response, unlike the Voice channel which supports
streaming. Document why the type-annotated AsyncGenerator branch is
rejected at runtime, addressing PR review feedback.

Copilot AI 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.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.

@xinghaohuang91
xinghaohuang91 merged commit f351274 into main Aug 4, 2026
17 checks passed
@xinghaohuang91
xinghaohuang91 deleted the refactor/dedupe-send-response branch August 4, 2026 17:32
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.

3 participants