fix: Telnyx, catch error when user has hung up the call first
This commit is contained in:
@@ -93,6 +93,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
- Fixed an edge case where if the user interrupted the bot but no new aggregation
|
- Fixed an edge case where if the user interrupted the bot but no new aggregation
|
||||||
was received, the bot would not resume speaking.
|
was received, the bot would not resume speaking.
|
||||||
|
|
||||||
|
- Fixed an issue with `TelnyxFrameSerializer` where it would throw an exception
|
||||||
|
when the user hung up the call.
|
||||||
|
|
||||||
- Fixed an issue with `ElevenLabsTTSService` where the context was not being
|
- Fixed an issue with `ElevenLabsTTSService` where the context was not being
|
||||||
closed.
|
closed.
|
||||||
|
|
||||||
|
|||||||
@@ -196,8 +196,31 @@ class TelnyxFrameSerializer(FrameSerializer):
|
|||||||
async with session.post(endpoint, headers=headers) as response:
|
async with session.post(endpoint, headers=headers) as response:
|
||||||
if response.status == 200:
|
if response.status == 200:
|
||||||
logger.info(f"Successfully terminated Telnyx call {call_control_id}")
|
logger.info(f"Successfully terminated Telnyx call {call_control_id}")
|
||||||
|
elif response.status == 422:
|
||||||
|
# Handle the case where the call has already ended
|
||||||
|
# Error code 90018: "Call has already ended"
|
||||||
|
# Source: https://developers.telnyx.com/api/errors/90018
|
||||||
|
try:
|
||||||
|
error_data = await response.json()
|
||||||
|
if any(
|
||||||
|
error.get("code") == "90018"
|
||||||
|
for error in error_data.get("errors", [])
|
||||||
|
):
|
||||||
|
logger.debug(
|
||||||
|
f"Telnyx call {call_control_id} was already terminated"
|
||||||
|
)
|
||||||
|
return
|
||||||
|
except:
|
||||||
|
pass # Fall through to log the raw error
|
||||||
|
|
||||||
|
# Log other 422 errors
|
||||||
|
error_text = await response.text()
|
||||||
|
logger.error(
|
||||||
|
f"Failed to terminate Telnyx call {call_control_id}: "
|
||||||
|
f"Status {response.status}, Response: {error_text}"
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
# Get the error details for better debugging
|
# Log other errors
|
||||||
error_text = await response.text()
|
error_text = await response.text()
|
||||||
logger.error(
|
logger.error(
|
||||||
f"Failed to terminate Telnyx call {call_control_id}: "
|
f"Failed to terminate Telnyx call {call_control_id}: "
|
||||||
|
|||||||
Reference in New Issue
Block a user