Skip to content

Send a phone call from AI agent, in an API call. Or, directly call the bot from the configured phone number!

Python

chore: Code quality

Clémence Lesnéb711df3eb95d
diff --git a/app/helpers/call_utils.py b/app/helpers/call_utils.py
index 6cbebc4..84bed3e 100644
--- a/app/helpers/call_utils.py
+++ b/app/helpers/call_utils.py
@@ -140,9 +140,9 @@ async def _handle_play_text(
If `context` is provided, it will be used to track the operation.
"""
- logger.info("Playing text: %s", text)
+ logger.info("Playing TTS: %s", text)
try:
- assert call.voice_id, "Voice ID is required for playing text"
+ assert call.voice_id, "Voice ID is required to control the call"
async with _use_call_client(client, call.voice_id) as call_client:
await call_client.play_media(
operation_context=_context_builder({context}),
@@ -173,7 +173,7 @@ async def handle_media(
If `context` is provided, it will be used to track the operation.
"""
try:
- assert call.voice_id, "Voice ID is required for recognizing media"
+ assert call.voice_id, "Voice ID is required to control the call"
async with _use_call_client(client, call.voice_id) as call_client:
await call_client.play_media(
operation_context=_context_builder({context}),
@@ -404,7 +404,7 @@ async def handle_recognize_ivr(
"""
logger.info("Recognizing IVR: %s", text)
try:
- assert call.voice_id, "Voice ID is required for recognizing media"
+ assert call.voice_id, "Voice ID is required to control the call"
async with _use_call_client(client, call.voice_id) as call_client:
await call_client.start_recognizing_media(
choices=choices,
@@ -429,7 +429,7 @@ async def handle_hangup(
) -> None:
logger.info("Hanging up: %s", call.initiate.phone_number)
try:
- assert call.voice_id, "Voice ID is required for recognizing media"
+ assert call.voice_id, "Voice ID is required to control the call"
async with _use_call_client(client, call.voice_id) as call_client:
await call_client.hang_up(is_for_everyone=True)
except ResourceNotFoundError:
@@ -449,7 +449,7 @@ async def handle_transfer(
) -> None:
logger.info("Transferring call: %s", target)
try:
- assert call.voice_id, "Voice ID is required for recognizing media"
+ assert call.voice_id, "Voice ID is required to control the call"
async with _use_call_client(client, call.voice_id) as call_client:
await call_client.transfer_call_to_participant(
operation_context=_context_builder({context}),
diff --git a/app/helpers/config_models/conversation.py b/app/helpers/config_models/conversation.py
index 233d681..97608e0 100644
--- a/app/helpers/config_models/conversation.py
+++ b/app/helpers/config_models/conversation.py
@@ -186,12 +186,12 @@ def _field_to_pydantic(
def _type_to_pydantic(
data: ClaimTypeEnum,
) -> type | Annotated[Any, ...]:
- if data == ClaimTypeEnum.DATETIME:
- return datetime
- if data == ClaimTypeEnum.EMAIL:
- return EmailStr
- if data == ClaimTypeEnum.PHONE_NUMBER:
- return PhoneNumber
- if data == ClaimTypeEnum.TEXT:
- return str
- raise ValueError(f"Unsupported data: {data}")
+ match data:
+ case ClaimTypeEnum.DATETIME:
+ return datetime
+ case ClaimTypeEnum.EMAIL:
+ return EmailStr
+ case ClaimTypeEnum.PHONE_NUMBER:
+ return PhoneNumber
+ case ClaimTypeEnum.TEXT:
+ return str
diff --git a/app/models/call.py b/app/models/call.py
index 3fe244f..5447db9 100644
--- a/app/models/call.py
+++ b/app/models/call.py
@@ -51,10 +51,11 @@ class CallGetModel(BaseModel):
inverted_messages.reverse()
# Search for the first action we want
for message in inverted_messages:
- if message.action == MessageActionEnum.CALL:
- return True
- if message.action == MessageActionEnum.HANGUP:
- return False
+ match message.action:
+ case MessageActionEnum.CALL:
+ return True
+ case MessageActionEnum.HANGUP:
+ return False
# Otherwise, we assume the call is completed
return False
diff --git a/app/persistence/cosmos_db.py b/app/persistence/cosmos_db.py
index 7ce2cc5..e8c12b3 100644
--- a/app/persistence/cosmos_db.py
+++ b/app/persistence/cosmos_db.py
@@ -129,7 +129,6 @@ class CosmosDbStore(IStore):
# Update live
data = call.model_dump(mode="json", exclude_none=True)
data["id"] = str(call.call_id) # CosmosDB requires an id field
- logger.debug("Saving call %s: %s", call.call_id, data)
res = False
try:
async with self._use_client() as db: