Send a phone call from AI agent, in an API call. Or, directly call the bot from the configured phone number!
Python
fix: Catch early call hangup error
Clémence Lesné687e0016b450
diff --git a/main.py b/main.pyindex 7f97427..12db2dd 100644--- a/main.py+++ b/main.py@@ -20,7 +20,7 @@ from azure.communication.callautomation import (from azure.communication.sms import SmsClientfrom azure.core.credentials import AzureKeyCredentialfrom azure.core.exceptions import ClientAuthenticationError-from azure.core.exceptions import ResourceNotFoundError+from azure.core.exceptions import ResourceNotFoundError, HttpResponseErrorfrom azure.core.messaging import CloudEventfrom azure.eventgrid import EventGridEvent, SystemEventNamesfrom azure.identity import DefaultAzureCredential@@ -573,6 +573,11 @@ async def handle_play()except ResourceNotFoundError:_logger.debug(f"Call hung up before playing ({call.call_id})")+ except HttpResponseError as e:+ if e.status_code == 8528:+ _logger.debug(f"Call hung up before playing ({call.call_id})")+ else:+ raise easync def gpt_completion(system: str, call: CallModel, max_tokens: int) -> str:@@ -1089,6 +1094,11 @@ async def handle_recognize_media()except ResourceNotFoundError:_logger.debug(f"Call hung up before recognizing ({call.call_id})")+ except HttpResponseError as e:+ if e.status_code == 8528:+ _logger.debug(f"Call hung up before playing ({call.call_id})")+ else:+ raise easync def handle_media(@@ -1104,6 +1114,11 @@ async def handle_media()except ResourceNotFoundError:_logger.debug(f"Call hung up before playing ({call.call_id})")+ except HttpResponseError as e:+ if e.status_code == 8528:+ _logger.debug(f"Call hung up before playing ({call.call_id})")+ else:+ raise easync def handle_hangup(client: CallConnectionClient, call: CallModel) -> None:@@ -1112,6 +1127,11 @@ async def handle_hangup(client: CallConnectionClient, call: CallModel) -> None:client.hang_up(is_for_everyone=True)except ResourceNotFoundError:_logger.debug(f"Call already hung up ({call.call_id})")+ except HttpResponseError as e:+ if e.status_code == 8528:+ _logger.debug(f"Call hung up before playing ({call.call_id})")+ else:+ raise ecall.messages.append(MessageModel(