Skip to content

Commit

Permalink
feat: Allow to disable callback timeout completely
Browse files Browse the repository at this point in the history
  • Loading branch information
clemlesne committed Dec 12, 2024
1 parent 5c0c0e1 commit e9a4a1b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
4 changes: 1 addition & 3 deletions app/helpers/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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",
Expand Down
11 changes: 7 additions & 4 deletions app/persistence/cosmos_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,11 @@ async def call_search_one(
) -> 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)
Expand All @@ -259,7 +264,7 @@ async def call_search_one(
# 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
Expand Down Expand Up @@ -288,9 +293,7 @@ async def call_search_one(
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(),
)

Expand Down

0 comments on commit e9a4a1b

Please sign in to comment.