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

perf: Cache cal model on create

Clémence Lesnéba84017c8f0f
diff --git a/app/persistence/cosmos_db.py b/app/persistence/cosmos_db.py
index 5275410..72f5391 100644
--- a/app/persistence/cosmos_db.py
+++ b/app/persistence/cosmos_db.py
@@ -241,13 +241,20 @@ class CosmosDbStore(IStore):
# Persist
try:
async with self._use_client() as db:
- raw = await db.create_item(body=data)
- return CallStateModel.model_validate(raw)
+ await db.create_item(body=data)
except CosmosHttpResponseError:
logger.exception("Error accessing CosmosDB")
except ValidationError:
logger.debug("Parsing error", exc_info=True)
+ # Update cache
+ cache_key = self._cache_key_call_id(call.call_id)
+ await self._cache.set(
+ key=cache_key,
+ ttl_sec=await callback_timeout_hour(),
+ value=call.model_dump_json(),
+ )
+
return call
async def call_search_one(self, phone_number: str) -> CallStateModel | None: