Skip to content

Commit 05085ca

Browse files
Added mute participant SDK method (Azure#30856)
1 parent b394cd1 commit 05085ca

File tree

5 files changed

+111
-4
lines changed

5 files changed

+111
-4
lines changed

sdk/communication/azure-communication-callautomation/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ Call Automation enables developers to build call workflows. Personalise customer
1616
- Download recordings.
1717
- Parse various events happening in the call, such as CallConnected and PlayCompleted event.
1818
- Start/Stop continuous DTMF recognition by subscribing/unsubscribing to tones.
19-
- Send DTMF tones to a participant in the call.
19+
- Send DTMF tones to a participant in the call.
20+
- Mute participants in the call.

sdk/communication/azure-communication-callautomation/azure/communication/callautomation/_call_connection_client.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
CallConnectionProperties,
2121
AddParticipantResult,
2222
RemoveParticipantResult,
23-
TransferCallResult
23+
TransferCallResult,
24+
MuteParticipantsResult,
2425
)
2526
from ._generated._client import AzureCommunicationCallAutomationService
2627
from ._generated.models import (
@@ -36,6 +37,7 @@
3637
SpeechOptions,
3738
PlayOptions,
3839
RecognizeOptions,
40+
MuteParticipantsRequest,
3941
)
4042
from ._generated.models._enums import RecognizeInputType
4143
from ._shared.utils import (
@@ -568,3 +570,33 @@ def send_dtmf(
568570
self._call_connection_id,
569571
send_dtmf_request,
570572
**kwargs)
573+
574+
@distributed_trace
575+
def mute_participants(
576+
self,
577+
target_participant: 'CommunicationIdentifier',
578+
*,
579+
operation_context: Optional[str] = None,
580+
**kwargs
581+
) -> MuteParticipantsResult:
582+
"""Mute participants from the call using identifier.
583+
584+
:param target_participant: Participant to be muted from the call. Only ACS Users are supported. Required.
585+
:type target_participant: ~azure.communication.callautomation.CommunicationIdentifier
586+
:keyword operation_context: Used by customers when calling mid-call actions to correlate the request to the
587+
response event.
588+
:paramtype operation_context: str
589+
:return: MuteParticipantsResult
590+
:rtype: ~azure.communication.callautomation.MuteParticipantsResult
591+
:raises ~azure.core.exceptions.HttpResponseError:
592+
"""
593+
mute_participants_request = MuteParticipantsRequest(
594+
target_participants=[serialize_identifier(target_participant)],
595+
operation_context=operation_context)
596+
597+
response = self._call_connection_client.mute(
598+
self._call_connection_id,
599+
mute_participants_request,
600+
**kwargs)
601+
602+
return MuteParticipantsResult._from_generated(response) # pylint:disable=protected-access

sdk/communication/azure-communication-callautomation/azure/communication/callautomation/_models.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
RemoveParticipantResponse as RemoveParticipantResultRest,
4444
TransferCallResponse as TransferParticipantResultRest,
4545
RecordingStateResponse as RecordingStateResultRest,
46+
MuteParticipantsResponse as MuteParticipantsResultRest,
4647
)
4748

4849
class CallInvite(object):
@@ -571,3 +572,22 @@ def __init__(
571572

572573
def _to_generated(self):
573574
return ChoiceInternal(label=self.label, phrases=self.phrases, tone=self.tone)
575+
576+
class MuteParticipantsResult(object):
577+
"""The response payload for muting participants from the call.
578+
579+
:ivar operation_context: The operation context provided by client.
580+
:vartype operation_context: str
581+
"""
582+
def __init__(
583+
self,
584+
*,
585+
operation_context: Optional[str] = None,
586+
**kwargs
587+
) -> None:
588+
super().__init__(**kwargs)
589+
self.operation_context = operation_context
590+
591+
@classmethod
592+
def _from_generated(cls, mute_participants_result_generated: 'MuteParticipantsResultRest'):
593+
return cls(operation_context=mute_participants_result_generated.operation_context)

sdk/communication/azure-communication-callautomation/azure/communication/callautomation/aio/_call_connection_client_async.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
CallConnectionProperties,
2222
AddParticipantResult,
2323
RemoveParticipantResult,
24-
TransferCallResult
24+
TransferCallResult,
25+
MuteParticipantsResult,
2526
)
2627
from .._generated.aio import AzureCommunicationCallAutomationService
2728
from .._generated.models import (
@@ -37,6 +38,7 @@
3738
SpeechOptions,
3839
PlayOptions,
3940
RecognizeOptions,
41+
MuteParticipantsRequest,
4042
)
4143
from .._generated.models._enums import RecognizeInputType
4244
from .._shared.utils import (
@@ -573,6 +575,36 @@ async def send_dtmf(
573575
send_dtmf_request,
574576
**kwargs)
575577

578+
@distributed_trace_async
579+
async def mute_participants(
580+
self,
581+
target_participant: 'CommunicationIdentifier',
582+
*,
583+
operation_context: Optional[str] = None,
584+
**kwargs
585+
) -> MuteParticipantsResult:
586+
"""Mute participants from the call using identifier.
587+
588+
:param target_participant: Participant to be muted from the call. Only ACS Users are supported. Required.
589+
:type target_participant: ~azure.communication.callautomation.CommunicationIdentifier
590+
:keyword operation_context: Used by customers when calling mid-call actions to correlate the request to the
591+
response event.
592+
:paramtype operation_context: str
593+
:return: MuteParticipantsResult
594+
:rtype: ~azure.communication.callautomation.MuteParticipantsResult
595+
:raises ~azure.core.exceptions.HttpResponseError:
596+
"""
597+
mute_participants_request = MuteParticipantsRequest(
598+
target_participants=[serialize_identifier(target_participant)],
599+
operation_context=operation_context)
600+
601+
response = await self._call_connection_client.mute(
602+
self._call_connection_id,
603+
mute_participants_request,
604+
**kwargs)
605+
606+
return MuteParticipantsResult._from_generated(response) # pylint:disable=protected-access
607+
576608
async def __aenter__(self) -> "CallConnectionClient":
577609
await self._client.__aenter__()
578610
return self

sdk/communication/azure-communication-callautomation/tests/test_call_connection_client.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,4 +173,26 @@ def mock_send(*_, **__):
173173
raise
174174

175175
self.assertFalse(raised, 'Expected is no exception raised')
176-
self.assertEqual(self.operation_context, response.operation_context)
176+
self.assertEqual(self.operation_context, response.operation_context)
177+
178+
def test_mute_participants(self):
179+
raised = False
180+
181+
def mock_send(*_, **__):
182+
return mock_response(status_code=202, json_payload={
183+
"operationContext": self.operation_context})
184+
185+
call_connection = CallConnectionClient(
186+
endpoint="https://endpoint",
187+
credential=AzureKeyCredential("fakeCredential=="),
188+
call_connection_id=self.call_connection_id,
189+
transport=Mock(send=mock_send))
190+
user = CommunicationUserIdentifier(self.communication_user_id)
191+
try:
192+
response = call_connection.mute_participants(user)
193+
except:
194+
raised = True
195+
raise
196+
197+
self.assertFalse(raised, 'Expected is no exception raised')
198+
self.assertEqual(self.operation_context, response.operation_context)

0 commit comments

Comments
 (0)