Send a phone call from AI agent, in an API call. Or, directly call the bot from the configured phone number!
Python
ux: Loading sound while bot is processing
Clémence Lesnécc7804fee956
diff --git a/helpers/prompts.py b/helpers/prompts.pyindex f10349a..e211158 100644--- a/helpers/prompts.py+++ b/helpers/prompts.py@@ -65,6 +65,6 @@ class TTS(str, Enum):"Je suis désolé, j'ai rencontré une erreur. Pouvez-vous répéter votre demande ?")GOODBYE = f"Merci de votre appel, j'espère avoir pu vous aider. N'hésitez pas à rappeler, j'ai tout mémorisé. {CONFIG.workflow.bot_company} vous souhaite une excellente journée !"- HELLO = f"Bonjour, je suis {CONFIG.workflow.bot_name}, l'assistant {CONFIG.workflow.bot_company} ! Je suis spécialiste des sinistres. Lorsque vous entendrez un bip, c'est que je travaille. Mais d'abord, quel est l'objet de votre appel ?"+ HELLO = f"Bonjour, je suis {CONFIG.workflow.bot_name}, l'assistant {CONFIG.workflow.bot_company} ! Je suis spécialiste des sinistres. Je ne peux pas travailler et écouter en même temps. Lorsque je travaillerai, vous entendrez une petite musique. Après, au bip, ce sera à votre tour de parler. Je suis là pour vous aider. Quel est l'objet de votre appel ?"TIMEOUT_SILENCE = "Je suis désolé, je n'ai rien entendu. Si vous avez besoin d'aide, dites-moi comment je peux vous aider."- WELCOME_BACK = f"Bonjour, je suis {CONFIG.workflow.bot_name}, l'assistant {CONFIG.workflow.bot_company} ! Je vois que vous avez déjà appelé il y a moins de {CONFIG.workflow.conversation_timeout_hour} heures. Lorsque vous entendrez un bip, c'est que je travaille. Laissez-moi quelques secondes pour récupérer votre dossier..."+ WELCOME_BACK = f"Bonjour, je suis {CONFIG.workflow.bot_name}, l'assistant {CONFIG.workflow.bot_company} ! Je vois que vous avez déjà appelé il y a moins de {CONFIG.workflow.conversation_timeout_hour} heures. Laissez-moi quelques secondes pour récupérer votre dossier..."diff --git a/main.py b/main.pyindex a65ce27..8daf380 100644--- a/main.py+++ b/main.py@@ -283,11 +283,6 @@ async def call_event_post(request: Request, call_id: UUID) -> None:client=client,text=TTSPrompt.WELCOME_BACK,)- await handle_media(- call=call,- client=client,- file="acknowledge.mp3",- )await intelligence(call, client)elif event_type == "Microsoft.Communication.CallDisconnected": # Call hung up@@ -301,12 +296,6 @@ async def call_event_post(request: Request, call_id: UUID) -> None:speech_text = event.data["speechResult"]["speech"]_logger.info(f"Recognition completed ({call.id}): {speech_text}")- await handle_media(- call=call,- client=client,- file="acknowledge.mp3",- )-if speech_text is not None and len(speech_text) > 0:call.messages.append(CallMessageModel(content=speech_text, persona=CallPersona.HUMAN)@@ -319,12 +308,6 @@ async def call_event_post(request: Request, call_id: UUID) -> None:result_information = event.data["resultInformation"]error_code = result_information["subCode"]- await handle_media(- call=call,- client=client,- file="acknowledge.mp3",- )-# Error codes:# 8510 = Action failed, initial silence timeout reached# 8532 = Action failed, inter-digit silence timeout reached@@ -405,9 +388,22 @@ async def call_event_post(request: Request, call_id: UUID) -> None:async def intelligence(call: CallModel, client: CallConnectionClient) -> None:+ # Start loading sound+ await handle_media_loop(+ call=call,+ client=client,+ file="loading.wav",+ )+chat_res = await gpt_chat(call)_logger.info(f"Chat ({call.id}): {chat_res}")+ try:+ # Cancel loading sound+ client.cancel_all_media_operations()+ except ResourceNotFoundError:+ _logger.debug(f"Call hung up before playing ({call.id})")+if chat_res.intent == IndentAction.TALK_TO_HUMAN:await handle_play(call=call,@@ -825,7 +821,7 @@ async def handle_recognize_text(await handle_recognize_media(call=call,client=client,- file="ready.mp3",+ file="ready.wav",)@@ -851,7 +847,7 @@ async def handle_recognize_media(_logger.debug(f"Call hung up before recognizing ({call.id})")-async def handle_media(+async def handle_media_loop(client: CallConnectionClient,call: CallModel,file: str,@@ -859,6 +855,7 @@ async def handle_media() -> None:try:client.play_media_to_all(+ loop=True,operation_context=context,play_source=FileSource(f"{CONFIG.resources.public_url}/{file}"),)diff --git a/resources/acknowledge.mp3 b/resources/acknowledge.mp3deleted file mode 100644index 2babd96..0000000Binary files a/resources/acknowledge.mp3 and /dev/null differdiff --git a/resources/loading.wav b/resources/loading.wavnew file mode 100644index 0000000..c6e7232Binary files /dev/null and b/resources/loading.wav differdiff --git a/resources/ready.mp3 b/resources/ready.mp3deleted file mode 100644index c52cb62..0000000Binary files a/resources/ready.mp3 and /dev/null differdiff --git a/resources/ready.wav b/resources/ready.wavnew file mode 100644index 0000000..be543b1Binary files /dev/null and b/resources/ready.wav differ