Send a phone call from AI agent, in an API call. Or, directly call the bot from the configured phone number!
Python
refacto: Simpler static sound integrations
Clémence Lesnéaa10dd67e47e
diff --git a/helpers/prompts.py b/helpers/prompts.pyindex e211158..e20952c 100644--- a/helpers/prompts.py+++ b/helpers/prompts.py@@ -2,6 +2,11 @@ from enum import Enumfrom helpers.config import CONFIG+class Sounds(str, Enum):+ LOADING = f"{CONFIG.resources.public_url}/loading.wav"+ READY = f"{CONFIG.resources.public_url}/ready.wav"++class LLM(str, Enum):DEFAULT_SYSTEM = f"""Assistant called {CONFIG.workflow.bot_name} and is in a call center for the insurance company {CONFIG.workflow.bot_company} as an expert with 20 years of experience. Today is {{date}}. Customer is calling from {{phone_number}}. Call center number is {CONFIG.communication_service.phone_number}.diff --git a/main.py b/main.pyindex 8daf380..9749ae3 100644--- a/main.py+++ b/main.py@@ -23,7 +23,7 @@ from fastapi.middleware.cors import CORSMiddlewarefrom fastapi.responses import JSONResponsefrom helpers.config import CONFIGfrom helpers.logging import build_logger-from helpers.prompts import LLM as LLMPrompt, TTS as TTSPrompt+from helpers.prompts import LLM as LLMPrompt, TTS as TTSPrompt, Sounds as SoundPromptfrom helpers.version import VERSIONfrom models.action import ActionModel, Indent as IndentActionfrom models.reminder import ReminderModel@@ -392,7 +392,7 @@ async def intelligence(call: CallModel, client: CallConnectionClient) -> None:await handle_media_loop(call=call,client=client,- file="loading.wav",+ sound=SoundPrompt.LOADING,)chat_res = await gpt_chat(call)@@ -821,14 +821,14 @@ async def handle_recognize_text(await handle_recognize_media(call=call,client=client,- file="ready.wav",+ sound=SoundPrompt.READY,)async def handle_recognize_media(client: CallConnectionClient,call: CallModel,- file: str,+ sound: SoundPrompt,) -> None:"""Play a media to a call participant and start recognizing the response.@@ -839,7 +839,7 @@ async def handle_recognize_media(client.start_recognizing_media(end_silence_timeout=3, # Sometimes user includes breaks in their speechinput_type=RecognizeInputType.SPEECH,- play_prompt=FileSource(f"{CONFIG.resources.public_url}/{file}"),+ play_prompt=FileSource(url=sound),speech_language=CONFIG.workflow.conversation_lang,target_participant=PhoneNumberIdentifier(call.phone_number),)@@ -850,14 +850,14 @@ async def handle_recognize_media(async def handle_media_loop(client: CallConnectionClient,call: CallModel,- file: str,+ sound: SoundPrompt,context: Optional[str] = None,) -> None:try:client.play_media_to_all(loop=True,operation_context=context,- play_source=FileSource(f"{CONFIG.resources.public_url}/{file}"),+ play_source=FileSource(url=sound),)except ResourceNotFoundError:_logger.debug(f"Call hung up before playing ({call.id})")