Skip to content

Commit

Permalink
ux: Display day name in web UIs
Browse files Browse the repository at this point in the history
  • Loading branch information
clemlesne committed Jul 15, 2024
1 parent 23d5dca commit fb5008c
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ communication_services:
endpoint: https://xxx.france.communication.azure.com
phone_number: "+33612345678"
post_queue_name: post-33612345678
resource_id: xxx
sms_queue_name: sms-33612345678
cognitive_service:
Expand Down
33 changes: 31 additions & 2 deletions function_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
import json
from http import HTTPStatus
from os import getenv
from typing import Any, Optional
from typing import Any, Optional, Union
from urllib.parse import quote_plus, urljoin
from uuid import UUID

import azure.functions as func
import jwt
import mistune
from azure.communication.callautomation import PhoneNumberIdentifier
from azure.communication.callautomation.aio import CallAutomationClient
Expand Down Expand Up @@ -66,6 +67,10 @@
_automation_client: Optional[CallAutomationClient] = None
_source_caller = PhoneNumberIdentifier(CONFIG.communication_services.phone_number)
logger.info("Using phone number %s", CONFIG.communication_services.phone_number)
_communication_services_jwks_client = jwt.PyJWKClient(
cache_keys=True,
uri="https://acscallautomation.communication.azure.com/calling/keys",
)

# Persistences
_cache = CONFIG.cache.instance()
Expand Down Expand Up @@ -471,8 +476,28 @@ async def communicationservices_event_post(
No parameters are expected. The body is a list of JSON objects `CloudEvent`.
Returns a 204 No Content if the events are properly fomatted. Otherwise, returns a 400 Bad Request.
Returns a 204 No Content if the events are properly fomatted. A 401 Unauthorized if the JWT token is invalid. Otherwise, returns a 400 Bad Request.
"""
# Validate JWT token
service_jwt: Union[str, None] = req.headers.get("Authorization")
if not service_jwt:
return func.HttpResponse(status_code=HTTPStatus.UNAUTHORIZED)
service_jwt = str(service_jwt).replace("Bearer ", "")
try:
jwt.decode(
algorithms=["RS256"],
audience=CONFIG.communication_services.resource_id,
issuer="https://acscallautomation.communication.azure.com",
jwt=service_jwt,
key=_communication_services_jwks_client.get_signing_key_from_jwt(
service_jwt
).key,
)
except jwt.PyJWTError:
logger.warning("Invalid JWT token", exc_info=True)
return func.HttpResponse(status_code=HTTPStatus.UNAUTHORIZED)

# Validate request
try:
call_id = UUID(req.route_params["call_id"])
secret: str = req.route_params["secret"]
Expand All @@ -484,6 +509,8 @@ async def communicationservices_event_post(
return _validation_error(Exception("Invalid JSON format"))
if not events or not isinstance(events, list):
return _validation_error(Exception("Events must be a list"))

# Process events in parallel
await asyncio.gather(
*[
_communicationservices_event_worker(
Expand All @@ -496,6 +523,8 @@ async def communicationservices_event_post(
for event in events
]
)

# Return default response
return func.HttpResponse(status_code=HTTPStatus.NO_CONTENT)


Expand Down
1 change: 1 addition & 0 deletions helpers/config_models/communication_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ class CommunicationServicesModel(BaseModel):
endpoint: str
phone_number: PhoneNumber
post_queue_name: str
resource_id: str
sms_queue_name: str
trainings_queue_name: str
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ dependencies = [
"pydantic-extra-types==2.8.2", # Extra types for Pydantic
"pydantic-settings==2.3.3", # Application configuration management with Pydantic
"pydantic[email]==2.7.4", # Data serialization and validation, plus email validation
"pyjwt==2.8.0", # Secure inbound calls from Communication Services
"python-dotenv==1.0.1", # Load environment variables from .env file
"pytz==2024.1", # Time zone handling
"pyyaml==6.0.1", # YAML parser
Expand Down
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1702,6 +1702,7 @@ pyjwt[crypto]==2.8.0 \
--hash=sha256:57e28d156e3d5c10088e0c68abb90bfac3df82b40a71bd0daa20c65ccd5c23de \
--hash=sha256:59127c392cc44c2da5bb3192169a91f429924e17aff6534d70fdc02ab3e04320
# via
# call-center-ai (pyproject.toml)
# msal
# twilio
pylint==3.2.5 \
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1153,6 +1153,7 @@ pyjwt[crypto]==2.8.0 \
--hash=sha256:57e28d156e3d5c10088e0c68abb90bfac3df82b40a71bd0daa20c65ccd5c23de \
--hash=sha256:59127c392cc44c2da5bb3192169a91f429924e17aff6534d70fdc02ab3e04320
# via
# call-center-ai (pyproject.toml)
# msal
# twilio
python-dotenv==1.0.1 \
Expand Down

0 comments on commit fb5008c

Please sign in to comment.