refactor(channels): return uppercase Twilio channel type from get_channel_name#83
refactor(channels): return uppercase Twilio channel type from get_channel_name#83xinghaohuang91 wants to merge 1 commit into
Conversation
…nnel_name
get_channel_name() now returns the uppercase ChannelType Literal ("SMS",
"VOICE", etc.) matching Twilio's channel enum, instead of a lowercase str.
This removes the get_channel_type_upper() method and all the .upper()/.lower()
conversions scattered across webhook filtering, API payloads, and session
storage — the channel string now speaks one consistent form end to end.
- Centralize the duplicated channel Literal into a shared ChannelType alias
- Type session.channel and get_channel_name() as ChannelType
- BREAKING: ConversationSession.channel is now uppercase (e.g. "SMS" not "sms")
There was a problem hiding this comment.
Pull request overview
Note
Copilot couldn't run its full agentic review because no GitHub Actions runner was available. Make sure your repository has a runner available to run Copilot's review, or add a copilot-setup-steps.yml file specifying one with the runs-on attribute. See the docs for more details.
This PR standardizes channel identifiers across the Python SDK by having get_channel_name() and ConversationSession.channel use Twilio’s uppercase channel enum (via a shared ChannelType Literal), removing ad-hoc casing conversions and a now-redundant helper.
Changes:
- Introduced a shared
ChannelTypealias and updated models to use it for channel fields. - Refactored channels to have
get_channel_name()return uppercaseChannelTypeand removedget_channel_type_upper(). - Updated tests and the dashboard example to expect/use uppercase channel strings consistently.
Reviewed changes
Copilot reviewed 29 out of 29 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
src/tac/models/conversation.py |
Adds shared ChannelType Literal and reuses it in multiple model fields. |
src/tac/models/session.py |
Types ConversationSession.channel as ChannelType with uppercase examples. |
src/tac/models/memory.py |
Replaces duplicated channel Literal[...] with shared ChannelType. |
src/tac/models/tac.py |
Replaces duplicated channel Literal[...] with shared ChannelType. |
src/tac/channels/base.py |
Makes get_channel_name() return ChannelType and removes .upper() usage for filtering/logging. |
src/tac/channels/messaging.py |
Removes get_channel_type_upper() and uses get_channel_name() for initiation. |
src/tac/channels/{sms,rcs,whatsapp,chat}.py |
Updates get_channel_name() implementations to return uppercase ChannelType. |
src/tac/channels/voice/channel.py |
Updates get_channel_name() to return "VOICE" as ChannelType. |
src/tac/tools/handoff.py |
Updates voice channel comparison to "VOICE". |
getting_started/examples/features/dashboard/dashboard.py |
Removes dead channel fallback and directly returns session.channel. |
tests/* |
Updates expectations/fixtures from lowercase to uppercase channel strings and removes get_channel_type_upper() assertions. |
Comments suppressed due to low confidence (1)
src/tac/channels/messaging.py:1
- The class docstring still states
get_channel_name()returns a lowercase channel name, but the refactor changes it to return uppercase Twilio channel types viaChannelType(e.g.,"SMS","RCS","WHATSAPP","CHAT"). Update this bullet (and any similar doc text in this file) to match the new contract so developers don’t implement/compare against lowercase values.
"""MessagingChannel base class for messaging channels (SMS, RCS, WhatsApp, Chat)."""
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
get_channel_name()now returns the uppercaseChannelTypeLiteral ("SMS","VOICE","RCS","WHATSAPP","CHAT") that matches Twilio's channel enum, instead of a lowercasestr. This lets the channel string flow through webhook filtering, API payloads, and session storage in a single consistent form — no more.upper()/.lower()juggling and no type-checker friction atParticipantAddress(channel=...).What changed:
get_channel_type_upper()and every.upper()/.lower()conversion on the channel name.Literal, previously duplicated across 5 model fields, into one sharedChannelTypealias inmodels/conversation.py.ConversationSession.channelandget_channel_name()asChannelType.session.channelis now always populated, so the lowercase fallback helper was dead code).ConversationSession.channelandget_channel_name()now return uppercase (e.g."SMS"not"sms"). Consumers comparingsession.channel == "voice"must switch to"VOICE".Type of Change
Checklist
SDK Parity
This is the Python SDK. This change affects shared channel-type behavior — the TypeScript SDK should be reviewed for parity.