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

fix: Cache key invalidation for call searched by phone number

Clémence Lesnéa0e35cd5d40d
diff --git a/persistence/cosmos_db.py b/persistence/cosmos_db.py
index 16dddfa..b9f2d4c 100644
--- a/persistence/cosmos_db.py
+++ b/persistence/cosmos_db.py
@@ -131,8 +131,16 @@ class CosmosDbStore(IStore):
# Update cache
if res:
- cache_key = self._cache_key_call_id(call.call_id)
- await self._cache.aset(cache_key, call.model_dump_json())
+ cache_key_id = self._cache_key_call_id(call.call_id)
+ await self._cache.aset(
+ cache_key_id, call.model_dump_json()
+ ) # Update for ID
+ cache_key_phone_number = self._cache_key_phone_number(
+ call.initiate.phone_number
+ )
+ await self._cache.adel(
+ cache_key_phone_number
+ ) # Invalidate for phone number because we don't know if it's the same call
return res
diff --git a/persistence/sqlite.py b/persistence/sqlite.py
index de7c6b6..465c089 100644
--- a/persistence/sqlite.py
+++ b/persistence/sqlite.py
@@ -102,8 +102,14 @@ class SqliteStore(IStore):
await db.commit()
# Update cache
- cache_key = self._cache_key_call_id(call.call_id)
- await self._cache.aset(cache_key, data)
+ cache_key_id = self._cache_key_call_id(call.call_id)
+ await self._cache.aset(cache_key_id, data) # Update for ID
+ cache_key_phone_number = self._cache_key_phone_number(
+ call.initiate.phone_number
+ )
+ await self._cache.adel(
+ cache_key_phone_number
+ ) # Invalidate for phone number because we don't know if it's the same call
return True