Skip to content

Commit 7c00f55

Browse files
committed
Add get_call api.
1 parent f9672e5 commit 7c00f55

File tree

9 files changed

+237
-31
lines changed

9 files changed

+237
-31
lines changed

sdk/communication/azure-communication-callingserver/README.md

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ from azure.communication.callingserver import (
9696
)
9797

9898
add_participant_result = await call_connection_async.add_participant(
99-
participant=CommunicationUserIdentifier("<user-id>")
99+
participant=CommunicationUserIdentifier("<id>")
100100
)
101101
```
102102

@@ -106,10 +106,12 @@ add_participant_result = await call_connection_async.add_participant(
106106
Once the participant_id is provided, the `remove_participant` method can be invoked:
107107

108108
```Python
109-
await call_connection_async.remove_participant(participant_id)
109+
await call_connection_async.remove_participant(
110+
participant=CommunicationUserIdentifier("<id>")
111+
)
110112
```
111113

112-
- `participant_id`: The participant to be removed from the call.
114+
- `participant`: The identifier of participant to be removed from the call.
113115

114116
### Play audio in the call connection
115117
Once the call is establised, the `play_audio` method can be invoked:
@@ -132,10 +134,6 @@ play_audio_result = await call_connection_async.play_audio(
132134
Once the call is establised, the `cancel_all_media_operations` method can be invoked:
133135

134136
```Python
135-
from azure.communication.callingserver import (
136-
PlayAudioOptions
137-
)
138-
139137
cancel_all_media_operations_result = await call_connection_async.cancel_all_media_operations()
140138
```
141139

@@ -159,7 +157,7 @@ from azure.communication.callingserver import (
159157
call_locator = ServerCallLocator("<server-call-id>")
160158
call_connection = await callingserver_client.join_call(
161159
call_locator=call_locator,
162-
source=CommunicationUserIdentifier("<user-id>"),
160+
source=CommunicationUserIdentifier("<id>"),
163161
join_call_options=JoinCallOptions"<...>"))
164162
)
165163
```
@@ -180,7 +178,7 @@ from azure.communication.callingserver import (
180178
call_locator = ServerCallLocator("<server-call-id>")
181179
add_participant_result = await callingserver_client.add_participant(
182180
call_locator=call_locator,
183-
participant=CommunicationUserIdentifier("<user-id>")
181+
participant=CommunicationUserIdentifier("<id>")
184182
callback_uri="<callback-uri>"
185183
)
186184
```
@@ -200,14 +198,12 @@ from azure.communication.callingserver import (
200198

201199
await callingserver_client.remove_participant(
202200
call_locator=call_locator,
203-
participant=CommunicationUserIdentifier("<user-id>")
204-
callback_uri="<callback-uri>"
201+
participant=CommunicationUserIdentifier("<id>")
205202
)
206203
```
207204

208205
- `call_locator`: The callLocator contains the call id.
209206
- `participant`: The participant to be removed from the call.
210-
- `callback_uri`: The callback uri.
211207

212208
### Play audio with callLocator in the server call
213209
Once the call is establised, the `play_audio` method can be invoked:

sdk/communication/azure-communication-callingserver/azure/communication/callingserver/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from ._call_connection import CallConnection
1010
from ._callingserver_client import CallingServerClient
11-
from ._generated.models import (AddParticipantResult,
11+
from ._generated.models import (AddParticipantResult, CallConnectionProperties,
1212
CancelAllMediaOperationsRequest,
1313
CancelAllMediaOperationsResult,
1414
CreateCallRequest, PhoneNumberIdentifierModel,
@@ -33,6 +33,7 @@
3333
__all__ = [
3434
'AddParticipantResult',
3535
'CancelAllMediaOperationsRequest',
36+
'CallConnectionProperties',
3637
'CallConnection',
3738
'CallingServerClient',
3839
'CancelAllMediaOperationsResult',

sdk/communication/azure-communication-callingserver/azure/communication/callingserver/_call_connection.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@
1616
PlayAudioRequestConverter,
1717
PlayAudioToParticipantRequestConverter
1818
)
19-
from ._generated.models import (AddParticipantResult,
20-
CancelAllMediaOperationsResult,
21-
PhoneNumberIdentifierModel,
22-
PlayAudioResult)
19+
from ._generated.models import (
20+
AddParticipantResult,
21+
CallConnectionProperties,
22+
CancelAllMediaOperationsResult,
23+
PhoneNumberIdentifierModel,
24+
PlayAudioResult
25+
)
2326
from ._shared.models import CommunicationIdentifier
2427

2528
if TYPE_CHECKING:
@@ -36,6 +39,17 @@ def __init__(
3639
self.call_connection_id = call_connection_id
3740
self._call_connection_client = call_connection_client
3841

42+
@distributed_trace()
43+
def get_call(
44+
self,
45+
**kwargs # type: Any
46+
): # type: (...) -> CallConnectionProperties
47+
48+
return self._call_connection_client.get_call(
49+
call_connection_id=self.call_connection_id,
50+
**kwargs
51+
)
52+
3953
@distributed_trace()
4054
def hang_up(
4155
self,

sdk/communication/azure-communication-callingserver/azure/communication/callingserver/_communication_identifier_serializer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def deserialize_identifier(identifier_model):
4646
raw_id = identifier_model.raw_id
4747

4848
if identifier_model.communication_user:
49-
return CommunicationUserIdentifier(raw_id, raw_id=raw_id)
49+
return CommunicationUserIdentifier(identifier_model.communication_user.id, raw_id=raw_id)
5050
if identifier_model.phone_number:
5151
return PhoneNumberIdentifier(identifier_model.phone_number.value, raw_id=raw_id)
5252
if identifier_model.microsoft_teams_user:

sdk/communication/azure-communication-callingserver/azure/communication/callingserver/aio/_call_connection_async.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,13 @@
2121
PlayAudioRequestConverter,
2222
PlayAudioToParticipantRequestConverter
2323
)
24-
from .._generated.models import (AddParticipantResult,
25-
CancelAllMediaOperationsResult,
26-
PhoneNumberIdentifierModel, PlayAudioResult)
24+
from .._generated.models import (
25+
AddParticipantResult,
26+
CallConnectionProperties,
27+
CancelAllMediaOperationsResult,
28+
PhoneNumberIdentifierModel,
29+
PlayAudioResult
30+
)
2731
from .._shared.models import CommunicationIdentifier
2832
from .._generated.aio._azure_communication_calling_server_service import \
2933
AzureCommunicationCallingServerService # pylint: disable=unused-import
@@ -44,6 +48,16 @@ def __init__(
4448
self._call_connection_client = call_connection_client
4549
self._callingserver_service_client = callingserver_service_client
4650

51+
@distributed_trace_async()
52+
async def get_call(
53+
self,
54+
**kwargs: Any
55+
) -> CallConnectionProperties:
56+
return await self._call_connection_client.get_call(
57+
call_connection_id=self.call_connection_id,
58+
**kwargs
59+
)
60+
4761
@distributed_trace_async()
4862
async def hang_up(
4963
self,

sdk/communication/azure-communication-callingserver/tests/test_call_connection.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,46 @@
1818

1919
class TestCallConnection(unittest.TestCase):
2020

21+
@parameterized.expand(CallConnectionUnitTestUtils.data_source_test_get_call())
22+
def test_get_call_succeed(
23+
self,
24+
test_name, # type: str
25+
call_connection_id, # type: str
26+
use_managed_identity = False, # type: bool
27+
):
28+
29+
call_connection = _mock_utils.create_mock_call_connection(
30+
call_connection_id,
31+
status_code=200,
32+
payload=_test_constants.GetCallResponsePayload,
33+
use_managed_identity=use_managed_identity
34+
)
35+
36+
result = call_connection.get_call()
37+
CallConnectionUnitTestUtils.verify_get_call_result(result)
38+
39+
@parameterized.expand(CallConnectionUnitTestUtils.data_source_test_get_call())
40+
def test_get_call_failed(
41+
self,
42+
test_name, # type: str
43+
call_connection_id, # type: str
44+
use_managed_identity = False, # type: bool
45+
):
46+
47+
call_connection = _mock_utils.create_mock_call_connection(
48+
call_connection_id,
49+
status_code=404,
50+
payload=_test_constants.ErrorPayload,
51+
use_managed_identity = use_managed_identity
52+
)
53+
54+
raised = False
55+
try:
56+
call_connection.get_call()
57+
except:
58+
raised = True
59+
assert raised == True
60+
2161
@parameterized.expand(CallConnectionUnitTestUtils.data_source_test_hang_up())
2262
def test_hang_up_succeed(
2363
self,

sdk/communication/azure-communication-callingserver/tests/test_call_connection_async.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,46 @@
1616

1717
from utils._unit_test_utils import CallConnectionUnitTestUtils
1818

19+
@parameterized.expand(CallConnectionUnitTestUtils.data_source_test_get_call())
20+
@pytest.mark.asyncio
21+
async def test_get_call_succeed(
22+
test_name, # type: str
23+
call_connection_id, # type: str
24+
use_managed_identity = False, # type: bool
25+
):
26+
27+
call_connection = _mock_utils_async.create_mock_call_connection(
28+
call_connection_id,
29+
status_code=200,
30+
payload=_test_constants.GetCallResponsePayload,
31+
use_managed_identity=use_managed_identity
32+
)
33+
34+
result = await call_connection.get_call()
35+
CallConnectionUnitTestUtils.verify_get_call_result(result)
36+
37+
@parameterized.expand(CallConnectionUnitTestUtils.data_source_test_get_call())
38+
@pytest.mark.asyncio
39+
async def test_get_call_failed(
40+
test_name, # type: str
41+
call_connection_id, # type: str
42+
use_managed_identity = False, # type: bool
43+
):
44+
45+
call_connection = _mock_utils_async.create_mock_call_connection(
46+
call_connection_id,
47+
status_code=404,
48+
payload=_test_constants.ErrorPayload,
49+
use_managed_identity = use_managed_identity
50+
)
51+
52+
raised = False
53+
try:
54+
await call_connection.get_call()
55+
except:
56+
raised = True
57+
assert raised == True
58+
1959
@parameterized.expand(CallConnectionUnitTestUtils.data_source_test_hang_up())
2060
@pytest.mark.asyncio
2161
async def test_hang_up_succeed(

sdk/communication/azure-communication-callingserver/tests/utils/_test_constants.py

Lines changed: 60 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
FAKE_ENDPOINT = "https://endpoint"
1919
FAKE_TOKEN = "Fake Token"
2020
CALL_SUBJECT = "testsubject"
21-
21+
OPERATION_ID = "dummyId"
2222
# System Environment Variables
2323
# Live Test Variables
2424
RESOURCE_IDENTIFIER = os.getenv(
@@ -45,7 +45,7 @@
4545
PHONE_NUMBER = "+14255550123"
4646
OPERATION_CONTEXT = "dummyOperationContext"
4747
ErrorPayload={
48-
"operationId": "dummyId",
48+
"operationId": OPERATION_ID,
4949
"status": "failed",
5050
"operationContext": OPERATION_CONTEXT,
5151
"resultInfo": {
@@ -62,21 +62,74 @@
6262
MEDIA_OPERATION_ID = "dummyMediaOperationId"
6363
USER_TO_USER_INFORMATION = "dummyUserToUserInformation"
6464

65+
SEVERCALL_ID = "aHKW9HM6Ly9jb252ZXJzYXRpb24tc2VydmljZS11cmwvYXBpL3YyL2VwL2NvbnYvc2Rjc3NlaVdiUV8wLVNCTE9peG1NWHRRP2k9OSZlPTYzNzU1MDY4NDM3MDUzNTAwMQ=="
66+
GROUPCALL_ID = "507ad2dc-5a40-4d85-b2d9-cf214d469638"
67+
68+
SERVER_CALL_LOCATOR = "serverCallLocator"
69+
GROUP_CALL_LOCATOR = "groupCallLocator"
70+
71+
COMMUNICATION_USER_Id_01 = "8:acs:b9612345-fd0b-480c-8fd2-cb58b70eab9f_acacdeb5-dba7-479b-ab45-5e76469d87b2"
72+
COMMUNICATION_USER_Id_02 = "8:acs:b9612345-fd0b-480c-8fd2-cb58b70eab9f_f95c7b38-6c4e-4898-93b3-2553402304d6"
73+
74+
COMMUNICATION_USER_KIND = "communication_user"
75+
PHONE_NUMBER_KIND = "phone_number"
76+
77+
CALL_STATE_CONNECTED = "connected"
78+
MEDIA_TYPES_AUDIO = "audio"
79+
MEDIA_TYPES_VIDEO = "video"
80+
CALLEVENTS_DTMFRECEIVED = "dtmfReceived"
81+
CALLEVENTS_PARTICIPANTSUPDATED = "participantsUpdated"
82+
83+
# GetCallResponsePayload
84+
GetCallResponsePayload = {
85+
"callConnectionId": CALL_ID,
86+
"source": {
87+
"communicationUser": {
88+
"id": COMMUNICATION_USER_Id_01
89+
}
90+
},
91+
"targets": [
92+
{
93+
"communicationUser": {
94+
"id": COMMUNICATION_USER_Id_02
95+
}
96+
},
97+
{
98+
"phoneNumber": {
99+
"value": PHONE_NUMBER
100+
}
101+
}
102+
],
103+
"callConnectionState": CALL_STATE_CONNECTED,
104+
"subject": CALL_SUBJECT,
105+
"callbackUri": AppCallbackUrl,
106+
"requestedMediaTypes": [
107+
MEDIA_TYPES_AUDIO,
108+
MEDIA_TYPES_VIDEO
109+
],
110+
"requestedCallEvents": [
111+
CALLEVENTS_DTMFRECEIVED,
112+
CALLEVENTS_PARTICIPANTSUPDATED
113+
],
114+
"callLocator": {
115+
"serverCallId": SEVERCALL_ID,
116+
"kind": SERVER_CALL_LOCATOR
117+
}
118+
}
119+
120+
65121
# CancelAllMediaOperaions
66122
CancelAllMediaOperaionsResponsePayload = {
67-
"operationId": "dummyId",
123+
"operationId": OPERATION_ID,
68124
"status": "completed",
69125
"operationContext": OPERATION_CONTEXT,
70126
}
71127

72-
SEVERCALL_ID = "b3ba87f4-9daf-4d0b-b95a-53d955a40577"
73-
GROUPCALL_ID = "507ad2dc-5a40-4d85-b2d9-cf214d469638"
74-
75128
# PlayAudio
76129
AUDIO_FILE_URI = "https://bot.contoso.io/audio/sample-message.wav"
77130
AUDIO_FILE_ID = "sampleAudioFileId"
78131
PlayAudioResponsePayload = {
79-
"operationId": "dummyId",
132+
"operationId": OPERATION_ID,
80133
"status": "running",
81134
"operationContext": OPERATION_CONTEXT
82135
}

0 commit comments

Comments
 (0)