Send a phone call from AI agent, in an API call. Or, directly call the bot from the configured phone number!
Python
refacto: Fix Communication Services working
Clémence Lesné9b4c3b56c3e4
diff --git a/Makefile b/Makefileindex 8f703ad..ad78ae9 100644--- a/Makefile+++ b/Makefile@@ -11,7 +11,7 @@ functionapp_location := swedencentralopenai_location := southcentralussearch_location := northeurope# App configuration-bot_phone_number ?= $(shell cat config.yaml | yq '.communication_service.phone_number')+bot_phone_number ?= $(shell cat config.yaml | yq '.communication_services.phone_number')event_subscription_name ?= $(shell echo '$(name)-$(bot_phone_number)' | tr -dc '[:alnum:]-')twilio_phone_number ?= $(shell cat config.yaml | yq '.sms.twilio.phone_number')# Bicep outputsdiff --git a/README.md b/README.mdindex b336fc0..ceae050 100644--- a/README.md+++ b/README.md@@ -143,7 +143,7 @@ graph LRai_search[("RAG\n(AI Search)")]app["App"]communication_service_sms["SMS gateway\n(Communication Services)"]- communication_service["Call gateway\n(Communication Services)"]+ communication_services["Call gateway\n(Communication Services)"]constent_safety["Moderation\n(Content Safety)"]db[("Conversations and claims\n(Cosmos DB or SQLite)")]event_grid[("Broker\n(Event Grid)")]@@ -152,7 +152,7 @@ graph LRtranslation["Translation\n(Cognitive Services)"]end- app -- Answer with text --> communication_service+ app -- Answer with text --> communication_servicesapp -- Ask for translation --> translationapp -- Few-shot training --> ai_searchapp -- Generate completion --> gpt@@ -160,16 +160,16 @@ graph LRapp -- Save conversation --> dbapp -- Send SMS report --> communication_service_smsapp -- Test for profanity --> constent_safety- app -- Transfer to agent --> communication_service+ app -- Transfer to agent --> communication_servicesapp -. Watch .-> event_grid- communication_service -- Notifies --> event_grid- communication_service -- Transfer to --> agent- communication_service -. Send voice .-> user+ communication_services -- Notifies --> event_grid+ communication_services -- Transfer to --> agent+ communication_services -. Send voice .-> usercommunication_service_sms -- Send SMS --> user- user -- Call --> communication_service+ user -- Call --> communication_services```### Sequence diagram@@ -257,7 +257,7 @@ workflow:bot_name: Robertlang: {}-communication_service:+communication_services:phone_number: "+33612345678"sms: {}@@ -300,7 +300,7 @@ workflow:bot_company: Contosobot_name: Robert-communication_service:+communication_services:access_key: xxxendpoint: https://xxx.france.communication.azure.comphone_number: "+33612345678"diff --git a/bicep/app.bicep b/bicep/app.bicepindex 49630f4..df6db7f 100644--- a/bicep/app.bicep+++ b/bicep/app.bicep@@ -51,10 +51,10 @@ var config = {lang: localConfig.workflow.initiate.lang}}- communication_service: {+ communication_services: {access_key: communicationServices.listKeys().primaryKeyendpoint: communicationServices.properties.hostName- phone_number: localConfig.communication_service.phone_number+ phone_number: localConfig.communication_services.phone_numberqueue_name: communicationServicesQueue.name}sms: localConfig.sms@@ -356,7 +356,7 @@ resource assignmentEventgridTopicQueueSender 'Microsoft.Authorization/roleAssignresource eventgridSubscriptionCall 'Microsoft.EventGrid/systemTopics/eventSubscriptions@2024-06-01-preview' = {parent: eventgridTopic- name: '${prefix}-${replace(localConfig.communication_service.phone_number, '+', '')}'+ name: '${prefix}-${replace(localConfig.communication_services.phone_number, '+', '')}'properties: {eventDeliverySchema: 'EventGridSchema'deliveryWithResourceIdentity: {@@ -379,7 +379,7 @@ resource eventgridSubscriptionCall 'Microsoft.EventGrid/systemTopics/eventSubscroperatorType: 'StringBeginsWith'key: 'data.to.PhoneNumber.Value'values: [- localConfig.communication_service.phone_number+ localConfig.communication_services.phone_number]}]@@ -391,7 +391,7 @@ resource eventgridSubscriptionCall 'Microsoft.EventGrid/systemTopics/eventSubscrresource eventgridSubscriptionSms 'Microsoft.EventGrid/systemTopics/eventSubscriptions@2024-06-01-preview' = {parent: eventgridTopic- name: '${prefix}-${replace(localConfig.communication_service.phone_number, '+', '')}-sms'+ name: '${prefix}-${replace(localConfig.communication_services.phone_number, '+', '')}-sms'properties: {eventDeliverySchema: 'EventGridSchema'deliveryWithResourceIdentity: {@@ -414,7 +414,7 @@ resource eventgridSubscriptionSms 'Microsoft.EventGrid/systemTopics/eventSubscrioperatorType: 'StringBeginsWith'key: 'data.to'values: [- localConfig.communication_service.phone_number+ localConfig.communication_services.phone_number]}]diff --git a/function_app.py b/function_app.pyindex ec6cbad..bf35d93 100644--- a/function_app.py+++ b/function_app.py@@ -269,7 +269,7 @@ async def call_post(initiate: CallInitiateModel) -> CallGetModel:@app.queue_trigger(arg_name="msg",connection="Storage",- queue_name=CONFIG.communication_service.queue_name,+ queue_name=CONFIG.communication_services.queue_name,)async def eventgrid_event_post(msg: func.QueueMessage) -> None:background_tasks = BackgroundTasks()diff --git a/helpers/config_models/communication_service.py b/helpers/config_models/communication_services.pysimilarity index 81%rename from helpers/config_models/communication_service.pyrename to helpers/config_models/communication_services.pyindex 64225f2..228ff79 100644--- a/helpers/config_models/communication_service.py+++ b/helpers/config_models/communication_services.py@@ -2,7 +2,7 @@ from helpers.pydantic_types.phone_numbers import PhoneNumberfrom pydantic import SecretStr, BaseModel-class CommunicationServiceModel(BaseModel):+class CommunicationServicesModel(BaseModel):access_key: SecretStrendpoint: strphone_number: PhoneNumberdiff --git a/helpers/config_models/prompts.py b/helpers/config_models/prompts.pyindex f437cdb..8ba8f93 100644--- a/helpers/config_models/prompts.py+++ b/helpers/config_models/prompts.py@@ -345,7 +345,7 @@ class LlmModel(BaseModel):self.default_system_tpl.format(bot_company=call.initiate.bot_company,bot_name=call.initiate.bot_name,- bot_phone_number=CONFIG.communication_service.phone_number,+ bot_phone_number=CONFIG.communication_services.phone_number,date=datetime.now(UTC).astimezone().strftime(diff --git a/helpers/config_models/root.py b/helpers/config_models/root.pyindex 9ae849c..8287ec5 100644--- a/helpers/config_models/root.py+++ b/helpers/config_models/root.py@@ -2,7 +2,7 @@ from helpers.config_models.ai_search import AiSearchModelfrom helpers.config_models.ai_translation import AiTranslationModelfrom helpers.config_models.cache import CacheModelfrom helpers.config_models.cognitive_service import CognitiveServiceModel-from helpers.config_models.communication_service import CommunicationServiceModel+from helpers.config_models.communication_services import CommunicationServicesModelfrom helpers.config_models.content_safety import ContentSafetyModelfrom helpers.config_models.database import DatabaseModelfrom helpers.config_models.llm import LlmModel@@ -31,7 +31,9 @@ class RootModel(BaseSettings):ai_translation: AiTranslationModelcache: CacheModel = CacheModel() # Object is fully defined by defaultcognitive_service: CognitiveServiceModel- communication_service: CommunicationServiceModel+ communication_services: CommunicationServicesModel = Field(+ serialization_alias="communication_service", # Compatibility with v5+ )content_safety: ContentSafetyModeldatabase: DatabaseModel = DatabaseModel() # Object is fully defined by defaultllm: LlmModeldiff --git a/helpers/config_models/sms.py b/helpers/config_models/sms.pyindex eae1275..99c8ea8 100644--- a/helpers/config_models/sms.py+++ b/helpers/config_models/sms.py@@ -24,7 +24,7 @@ class CommunicationServiceModel(BaseModel, frozen=True):from persistence.communication_services import CommunicationServicesSmsfrom helpers.config import CONFIG- return CommunicationServicesSms(CONFIG.communication_service)+ return CommunicationServicesSms(CONFIG.communication_services)class TwilioModel(BaseModel, frozen=True):diff --git a/persistence/communication_services.py b/persistence/communication_services.pyindex 8cf0388..8c628f1 100644--- a/persistence/communication_services.py+++ b/persistence/communication_services.py@@ -2,7 +2,7 @@ from azure.communication.sms import SmsSendResultfrom azure.communication.sms.aio import SmsClientfrom azure.core.exceptions import ClientAuthenticationError, HttpResponseErrorfrom contextlib import asynccontextmanager-from helpers.config_models.communication_service import CommunicationServiceModel+from helpers.config_models.communication_services import CommunicationServicesModelfrom helpers.logging import build_loggerfrom helpers.pydantic_types.phone_numbers import PhoneNumberfrom models.readiness import ReadinessStatus@@ -14,9 +14,9 @@ _logger = build_logger(__name__)class CommunicationServicesSms(ISms):- _config: CommunicationServiceModel+ _config: CommunicationServicesModel- def __init__(self, config: CommunicationServiceModel):+ def __init__(self, config: CommunicationServicesModel):_logger.info(f"Using Communication Services from number {config.phone_number}")self._config = config