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

feat: Allow to disable callback timeout completely

Clémence Lesnée9a4a1b800fd
diff --git a/README.md b/README.md
index 39f610a..91440ea 100644
--- a/README.md
+++ b/README.md
@@ -474,7 +474,7 @@ Conversation options are represented as features. They can be configured from Ap
|-|-|-|-|
| `answer_hard_timeout_sec` | The hard timeout for the bot answer in secs. | `int` | 60 |
| `answer_soft_timeout_sec` | The soft timeout for the bot answer in secs. | `int` | 30 |
-| `callback_timeout_hour` | The timeout for a callback in hours. Minimum of 1. | `int` | 3 |
+| `callback_timeout_hour` | The timeout for a callback in hours. Set 0 to disable. | `int` | 3 |
| `phone_silence_timeout_sec` | Amount of silence in secs to trigger a warning message from the assistant. | `int` | 20 |
| `recognition_retry_max` | TThe maximum number of retries for voice recognition. Minimum of 1. | `int` | 3 |
| `recording_enabled` | Whether call recording is enabled. | `bool` | false |
diff --git a/app/helpers/features.py b/app/helpers/features.py
index 1d5bcca..cfe79f4 100644
--- a/app/helpers/features.py
+++ b/app/helpers/features.py
@@ -42,12 +42,11 @@ async def answer_soft_timeout_sec(scheduler: Scheduler) -> int:
async def callback_timeout_hour(scheduler: Scheduler) -> int:
"""
- The timeout for a callback in hours. Minimum of 1.
+ The timeout for a callback in hours. Set 0 to disable.
"""
return await _default(
default=24,
key="callback_timeout_hour",
- min_incl=1,
scheduler=scheduler,
type_res=int,
)
@@ -131,7 +130,6 @@ async def recognition_retry_max(scheduler: Scheduler) -> int:
"""
The maximum number of retries for voice recognition. Minimum of 1.
"""
- return 1
return await _default(
default=3,
key="recognition_retry_max",
diff --git a/app/persistence/cosmos_db.py b/app/persistence/cosmos_db.py
index 576dfdd..55e805d 100644
--- a/app/persistence/cosmos_db.py
+++ b/app/persistence/cosmos_db.py
@@ -247,6 +247,11 @@ class CosmosDbStore(IStore):
) -> CallStateModel | None:
logger.debug("Loading last call for %s", phone_number)
+ timeout = await callback_timeout_hour(scheduler)
+ if timeout < 1 and callback_timeout:
+ logger.debug("Callback timeout if off, skipping search")
+ return None
+
# Try cache
cache_key = self._cache_key_phone_number(phone_number)
cached = await self._cache.get(cache_key)
@@ -259,7 +264,7 @@ class CosmosDbStore(IStore):
# Filter by timeout if needed
extra_where = ""
if callback_timeout:
- extra_where = f"AND c.created_at >= DATETIMEADD('hh', -{await callback_timeout_hour(scheduler)}, GETCURRENTDATETIME())"
+ extra_where = f"AND c.created_at >= DATETIMEADD('hh', -{timeout}, GETCURRENTDATETIME())"
# Try live
call = None
@@ -288,9 +293,7 @@ class CosmosDbStore(IStore):
if call:
await self._cache.set(
key=cache_key,
- ttl_sec=max(await callback_timeout_hour(scheduler), 1)
- * 60
- * 60, # Ensure at least 1 hour
+ ttl_sec=timeout * 60 * 60, # Ensure at least 1 hour
value=call.model_dump_json(),
)