Skip to content

Commit

Permalink
feat: Avoid IVR if a single language is configured
Browse files Browse the repository at this point in the history
  • Loading branch information
clemlesne committed Sep 26, 2024
1 parent e8d1649 commit 0fcc4b7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
2 changes: 2 additions & 0 deletions function_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,9 @@ async def _trainings_callback(_call: CallStateModel) -> None:
await on_call_connected(
call=call,
client=automation_client,
post_callback=_post_callback,
server_call_id=server_call_id,
trainings_callback=_trainings_callback,
)

elif event_type == "Microsoft.Communication.CallDisconnected": # Call hung up
Expand Down
24 changes: 22 additions & 2 deletions helpers/call_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ async def on_new_call(
async def on_call_connected(
call: CallStateModel,
client: CallAutomationClient,
post_callback: Callable[[CallStateModel], Awaitable[None]],
server_call_id: str,
trainings_callback: Callable[[CallStateModel], Awaitable[None]],
) -> None:
logger.info("Call connected, asking for language")
call.recognition_retry = 0 # Reset recognition retry counter
Expand All @@ -102,7 +104,10 @@ async def on_call_connected(
)
await asyncio.gather(
_handle_ivr_language(
call=call, client=client
call=call,
client=client,
post_callback=post_callback,
trainings_callback=trainings_callback,
), # First, every time a call is answered, confirm the language
_db.call_aset(
call
Expand Down Expand Up @@ -578,9 +583,24 @@ def _validate(


async def _handle_ivr_language(
client: CallAutomationClient,
call: CallStateModel,
client: CallAutomationClient,
post_callback: Callable[[CallStateModel], Awaitable[None]],
trainings_callback: Callable[[CallStateModel], Awaitable[None]],
) -> None:
# If only one language is available, skip the IVR
if len(CONFIG.conversation.initiate.lang.availables) == 1:
short_code = CONFIG.conversation.initiate.lang.availables[0].short_code
logger.info("Only one language available, selecting %s by default", short_code)
await on_ivr_recognized(
call=call,
client=client,
label=short_code,
post_callback=post_callback,
trainings_callback=trainings_callback,
)
return

tones = [
DtmfTone.ONE,
DtmfTone.TWO,
Expand Down

0 comments on commit 0fcc4b7

Please sign in to comment.