Merge pull request #2726 from pipecat-ai/mb/twilio-serializer-cleanup
Fixup for TwilioFrameSerializer
This commit is contained in:
@@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
|
- Added support to `TwilioFrameSerializer` for `region` and `edge` settings.
|
||||||
|
|
||||||
- Added support for using universal `LLMContext` with:
|
- Added support for using universal `LLMContext` with:
|
||||||
|
|
||||||
- `LLMLogObserver`
|
- `LLMLogObserver`
|
||||||
|
|||||||
@@ -76,25 +76,31 @@ class TwilioFrameSerializer(FrameSerializer):
|
|||||||
edge: Twilio edge location (e.g., "sydney", "dublin"). Must be specified with region.
|
edge: Twilio edge location (e.g., "sydney", "dublin"). Must be specified with region.
|
||||||
params: Configuration parameters.
|
params: Configuration parameters.
|
||||||
"""
|
"""
|
||||||
if not call_sid or not account_sid or not auth_token:
|
self._params = params or TwilioFrameSerializer.InputParams()
|
||||||
missing = []
|
|
||||||
|
# Validate hangup-related parameters if auto_hang_up is enabled
|
||||||
|
if self._params.auto_hang_up:
|
||||||
|
# Validate required credentials
|
||||||
|
missing_credentials = []
|
||||||
if not call_sid:
|
if not call_sid:
|
||||||
missing.append("call_sid")
|
missing_credentials.append("call_sid")
|
||||||
if not account_sid:
|
if not account_sid:
|
||||||
missing.append("account_sid")
|
missing_credentials.append("account_sid")
|
||||||
if not auth_token:
|
if not auth_token:
|
||||||
missing.append("auth_token")
|
missing_credentials.append("auth_token")
|
||||||
|
|
||||||
raise ValueError(
|
if missing_credentials:
|
||||||
f"Cannot hang up Twilio call: missing required parameters: {', '.join(missing)}"
|
raise ValueError(
|
||||||
)
|
f"auto_hang_up is enabled but missing required parameters: {', '.join(missing_credentials)}"
|
||||||
|
)
|
||||||
|
|
||||||
if (region and not edge) or (edge and not region):
|
# Validate region and edge are both provided if either is specified
|
||||||
raise ValueError(
|
if (region and not edge) or (edge and not region):
|
||||||
"Both edge and region parameters are required if one is set. "
|
raise ValueError(
|
||||||
f"Twilio's FQDN format requires both: api.{{edge}}.{{region}}.twilio.com. "
|
"Both edge and region parameters are required if one is set. "
|
||||||
f"Got: region='{region}', edge='{edge}'"
|
f"Twilio's FQDN format requires both: api.{{edge}}.{{region}}.twilio.com. "
|
||||||
)
|
f"Got: region='{region}', edge='{edge}'"
|
||||||
|
)
|
||||||
|
|
||||||
self._stream_sid = stream_sid
|
self._stream_sid = stream_sid
|
||||||
self._call_sid = call_sid
|
self._call_sid = call_sid
|
||||||
@@ -102,7 +108,6 @@ class TwilioFrameSerializer(FrameSerializer):
|
|||||||
self._auth_token = auth_token
|
self._auth_token = auth_token
|
||||||
self._region = region
|
self._region = region
|
||||||
self._edge = edge
|
self._edge = edge
|
||||||
self._params = params or TwilioFrameSerializer.InputParams()
|
|
||||||
|
|
||||||
self._twilio_sample_rate = self._params.twilio_sample_rate
|
self._twilio_sample_rate = self._params.twilio_sample_rate
|
||||||
self._sample_rate = 0 # Pipeline input rate
|
self._sample_rate = 0 # Pipeline input rate
|
||||||
|
|||||||
Reference in New Issue
Block a user