Skip to content

Commit

Permalink
fixing repeatability headers to be in correct format (Azure#31256)
Browse files Browse the repository at this point in the history
Co-authored-by: Min Woo Lee 🧊 <77083090+minwoolee-ms@users.noreply.github.com>
  • Loading branch information
minwoolee-msft and minwoolee-msft authored Jul 21, 2023
1 parent 55420bd commit b3faf3b
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
from ._utils import (
serialize_phone_identifier,
serialize_identifier,
serialize_communication_user_identifier
serialize_communication_user_identifier,
process_repeatability_first_sent
)
if TYPE_CHECKING:
from ._models import (
Expand Down Expand Up @@ -205,6 +206,8 @@ def create_call(
custom_context=user_custom_context
)

process_repeatability_first_sent(kwargs)

result = self._client.create_call(
create_call_request=create_call_request,
**kwargs)
Expand Down Expand Up @@ -274,6 +277,8 @@ def create_group_call(
custom_context=user_custom_context,
)

process_repeatability_first_sent(kwargs)

result = self._client.create_call(
create_call_request=create_call_request,
**kwargs)
Expand Down Expand Up @@ -322,6 +327,8 @@ def answer_call(
operation_context=operation_context
)

process_repeatability_first_sent(kwargs)

result = self._client.answer_call(
answer_call_request=answer_call_request,
**kwargs)
Expand Down Expand Up @@ -352,6 +359,8 @@ def redirect_call(
sip_headers=target_participant.sip_headers
) if target_participant.sip_headers or target_participant.voip_headers else None

process_repeatability_first_sent(kwargs)

redirect_call_request = RedirectCallRequest(
incoming_call_context=incoming_call_context,
target=serialize_identifier(target_participant.target),
Expand Down Expand Up @@ -386,6 +395,8 @@ def reject_call(
call_reject_reason=call_reject_reason
)

process_repeatability_first_sent(kwargs)

self._client.reject_call(
reject_call_request=reject_call_request,
**kwargs)
Expand Down Expand Up @@ -460,6 +471,8 @@ def start_recording(
channel_affinity = channel_affinity_internal
)

process_repeatability_first_sent(kwargs)

recording_state_result = self._call_recording_client.start_recording(
start_call_recording = start_recording_request, **kwargs)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
from ._api_versions import DEFAULT_VERSION
from ._utils import (
serialize_phone_identifier,
serialize_identifier
serialize_identifier,
process_repeatability_first_sent
)
from ._models import (
CallParticipant,
Expand Down Expand Up @@ -184,6 +185,7 @@ def hang_up(self, is_for_everyone: bool, **kwargs) -> None:
"""

if is_for_everyone:
process_repeatability_first_sent(kwargs)
self._call_connection_client.terminate_call(
self._call_connection_id,
**kwargs)
Expand Down Expand Up @@ -258,6 +260,8 @@ def transfer_call_to_participant(
custom_context=user_custom_context, operation_context=operation_context,
callback_uri_override=callback_url_override)

process_repeatability_first_sent(kwargs)

if transferee is not None:
request.transferee=serialize_identifier(transferee)

Expand Down Expand Up @@ -304,6 +308,8 @@ def add_participant(
operation_context=operation_context,
callback_uri_override=callback_url_override)

process_repeatability_first_sent(kwargs)

response = self._call_connection_client.add_participant(
self._call_connection_id,
add_participant_request,
Expand Down Expand Up @@ -336,6 +342,8 @@ def remove_participant(
participant_to_remove=serialize_identifier(target_participant),
operation_context=operation_context, callback_uri_override=callback_url_override)

process_repeatability_first_sent(kwargs)

response = self._call_connection_client.remove_participant(
self._call_connection_id,
remove_participant_request,
Expand Down Expand Up @@ -661,6 +669,8 @@ def mute_participants(
target_participants=[serialize_identifier(target_participant)],
operation_context=operation_context)

process_repeatability_first_sent(kwargs)

response = self._call_connection_client.mute(
self._call_connection_id,
mute_participants_request,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# license information.
# --------------------------------------------------------------------------
from typing import Dict, Any, Union
from datetime import datetime
from ._shared.models import (
CommunicationIdentifier,
CommunicationUserIdentifier,
Expand All @@ -18,6 +19,16 @@
PhoneNumberIdentifierModel
)

def process_repeatability_first_sent(keywords):
if 'headers' in keywords:
if 'Repeatability-First-Sent' not in keywords['headers']:
keywords['headers']['Repeatability-First-Sent'] = get_repeatability_timestamp()
else:
keywords['headers'] = {'Repeatability-First-Sent': get_repeatability_timestamp()}

def get_repeatability_timestamp():
return datetime.utcnow().strftime('%a, %d %b %Y %H:%M:%S GMT')

def serialize_identifier(
identifier:CommunicationIdentifier
) -> Dict[str, Any]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
from .._utils import (
serialize_phone_identifier,
serialize_identifier,
serialize_communication_user_identifier
serialize_communication_user_identifier,
process_repeatability_first_sent
)
if TYPE_CHECKING:
from .._models import (
Expand Down Expand Up @@ -193,6 +194,8 @@ async def create_call(
custom_context=user_custom_context
)

process_repeatability_first_sent(kwargs)

result = await self._client.create_call(
create_call_request=create_call_request,
**kwargs)
Expand Down Expand Up @@ -261,6 +264,8 @@ async def create_group_call(
custom_context=user_custom_context,
)

process_repeatability_first_sent(kwargs)

result = await self._client.create_call(
create_call_request=create_call_request,
**kwargs)
Expand Down Expand Up @@ -308,6 +313,8 @@ async def answer_call(
operation_context=operation_context
)

process_repeatability_first_sent(kwargs)

result = await self._client.answer_call(
answer_call_request=answer_call_request,
**kwargs)
Expand Down Expand Up @@ -344,6 +351,8 @@ async def redirect_call(
custom_context=user_custom_context
)

process_repeatability_first_sent(kwargs)

await self._client.redirect_call(
redirect_call_request=redirect_call_request,
**kwargs)
Expand Down Expand Up @@ -372,6 +381,8 @@ async def reject_call(
call_reject_reason=call_reject_reason
)

process_repeatability_first_sent(kwargs)

await self._client.reject_call(
reject_call_request=reject_call_request,
**kwargs)
Expand Down Expand Up @@ -446,6 +457,8 @@ async def start_recording(
channel_affinity = channel_affinity_internal
)

process_repeatability_first_sent(kwargs)

recording_state_result = await self._call_recording_client.start_recording(
start_call_recording = start_recording_request, **kwargs)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
from .._api_versions import DEFAULT_VERSION
from .._utils import (
serialize_phone_identifier,
serialize_identifier
serialize_identifier,
process_repeatability_first_sent
)
from .._models import (
CallParticipant,
Expand Down Expand Up @@ -174,6 +175,7 @@ async def hang_up(self, is_for_everyone: bool, **kwargs) -> None:
"""

if is_for_everyone:
process_repeatability_first_sent(kwargs)
await self._call_connection_client.terminate_call(
self._call_connection_id,
**kwargs)
Expand Down Expand Up @@ -248,6 +250,8 @@ async def transfer_call_to_participant(
custom_context=user_custom_context, operation_context=operation_context,
callback_uri_override=callback_url_override)

process_repeatability_first_sent(kwargs)

if transferee is not None:
request.transferee = serialize_identifier(transferee)

Expand Down Expand Up @@ -294,6 +298,8 @@ async def add_participant(
operation_context=operation_context,
callback_uri_override=callback_url_override)

process_repeatability_first_sent(kwargs)

response = await self._call_connection_client.add_participant(
self._call_connection_id,
add_participant_request,
Expand Down Expand Up @@ -326,6 +332,8 @@ async def remove_participant(
participant_to_remove=serialize_identifier(target_participant),
operation_context=operation_context, callback_uri_override=callback_url_override)

process_repeatability_first_sent(kwargs)

response = await self._call_connection_client.remove_participant(
self._call_connection_id,
remove_participant_request,
Expand Down Expand Up @@ -648,6 +656,8 @@ async def mute_participants(
target_participants=[serialize_identifier(target_participant)],
operation_context=operation_context)

process_repeatability_first_sent(kwargs)

response = await self._call_connection_client.mute(
self._call_connection_id,
mute_participants_request,
Expand Down

0 comments on commit b3faf3b

Please sign in to comment.