Skip to content

Commit 1088ca1

Browse files
committed
Update README.md with Sample Code Snippets.
1 parent f688888 commit 1088ca1

File tree

1 file changed

+207
-19
lines changed
  • sdk/communication/azure-communication-callingserver

1 file changed

+207
-19
lines changed

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

Lines changed: 207 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Azure Communication CallingServer Package client library for Python
22

3-
This package contains a Python SDK for Azure Communication Services for CallingServer.
3+
This package contains a Python SDK for Azure Communication Services of CallingServer.
44
Read more about Azure Communication Services [here](https://docs.microsoft.com/azure/communication-services/overview)
55

66

@@ -22,43 +22,231 @@ pip install azure-communication-callingserver
2222

2323
## Key concepts
2424

25-
`CallingServerClient` provides the functionality to make call connection, join call connection or initialize a server call.
25+
`CallingServerClient` provides the functionality to create a call connection, join call connection or join a call with CallLocator.
26+
Performing more functionality over the eastablised call.
2627

2728
## Examples
2829

2930
The following section provides several code snippets covering some of the most common Azure Communication Services tasks, including:
3031

31-
- [Client Initialization](#client-initialization)
32-
- [Make a call to a phone number recipient](#make-a-call-to-a-phone-number-recipient)
32+
Call Connection Client APIs:
33+
- [Client initialization](#client-initialization)
34+
- [Create a call connection](#create-a-call-connection)
35+
- [Add participant](#add-participant)
36+
- [Remove participant](#remove-participant)
37+
- [Play audio in the call connection](#play-audio-in-the-call-connection)
38+
- [Cancel all media operations in the call connection](#cancel-all-media-operations-in-the-call-connection)
39+
- [Hang up the call connection](#hang-up-the-call-connection)
3340

34-
### Client Initialization
41+
Calling Server Client APIs:
42+
- [Client initialization](#client-initialization)
43+
- [Create a server Call](#create-a-call-connection)
44+
- [Add participant with calllocator to the server call](#add-participant-with-calllocator-to-the-server-call)
45+
- [Remove participant with calllocator from the server call](#remove-participant-with-calllocator-from-the-server-call)
46+
- [Play audio with calllocator in the server call](#play-audio-with-calllocator-in-the-server-call)
47+
- [Hang up the call connection](#hang-up-the-call-connection)
3548

36-
To initialize the CallingServer Client, the connection string can be used to instantiate.
49+
### Client initialization
50+
51+
To initialize the CallingServer Client, the connection string can be used to instantiate. Alternatively, you can also use Azure Active Directory-managed identities authentication using DefaultAzureCredential.
3752

3853
```Python
39-
from azure.communication.callingserver import CallingServerClient
54+
from azure.communication.callingserver.aio import CallingServerClient
4055

41-
connection_str = "endpoint=ENDPOINT;accessKey=KEY"
56+
connection_string = "endpoint=ENDPOINT;accessKey=KEY"
4257
callingserver_client = CallingServerClient.from_connection_string(connection_string)
43-
4458
```
4559

46-
### Make a call to a phone number recipient
60+
```Python
61+
# To use Azure Active Directory Authentication (DefaultAzureCredential) make sure to have
62+
# AZURE_TENANT_ID, AZURE_CLIENT_ID and AZURE_CLIENT_SECRET as env variables.
63+
# see here: https://docs.microsoft.com/en-us/dotnet/api/azure.identity.environmentcredential?view=azure-dotnet
64+
from azure.identity import DefaultAzureCredential
4765

66+
endpoint = "https://<RESOURCE_NAME>.communication.azure.com"
67+
callingserver_client = CallingServerClient(endpoint, DefaultAzureCredential())
68+
```
69+
70+
### Create a call connection
4871
Once the client is initialized, the `createCallConnection` method can be invoked:
4972

5073
```Python
51-
from azure.communication.callingserver import CreateCallOptions
74+
from azure.communication.callingserver import (
75+
CreateCallOptions,
76+
CommunicationUserIdentifier,
77+
PhoneNumberIdentifier
78+
)
79+
80+
call_connection_async = callingserver_client.create_call_connection(
81+
source=CommunicationUserIdentifier("<from-phone-number>"),
82+
targets=[PhoneNumberIdentifier("<to-phone-number>")],
83+
call_options=CreateCallOptions("<...>"))
84+
```
85+
86+
- `source`: The source identity.
87+
- `targets`: The target identities.
88+
- `call_options`: The create call options.
89+
90+
### Add participant
91+
Once the call is establised, the `add_participant` method can be invoked:
92+
93+
```Python
94+
from azure.communication.callingserver import (
95+
CommunicationUserIdentifier
96+
)
97+
98+
add_participant_result = await call_connection_async.add_participant(
99+
participant=CommunicationUserIdentifier("<user-id>")
100+
)
101+
```
102+
103+
- `participant`: The participant to be added to the call.
104+
105+
### Remove participant
106+
Once the participant_id is provided, the `remove_participant` method can be invoked:
107+
108+
```Python
109+
await call_connection_async.remove_participant(participant_id)
110+
```
111+
112+
- `participant_id`: The participant to be removed from the call.
113+
114+
### Play audio in the call connection
115+
Once the call is establised, the `play_audio` method can be invoked:
116+
117+
```Python
118+
from azure.communication.callingserver import (
119+
PlayAudioOptions
120+
)
121+
122+
play_audio_result = await call_connection_async.play_audio(
123+
audio_file_uri="<audio-file-uri>",
124+
play_audio_options=PlayAudioOptions"<...>"))
125+
)
126+
```
127+
128+
- `audio_file_uri`: The uri of the audio file.
129+
- `play_audio_options`: The playAudio options.
130+
131+
### Cancel all media operations in the call connection
132+
Once the call is establised, the `cancel_all_media_operations` method can be invoked:
133+
134+
```Python
135+
from azure.communication.callingserver import (
136+
PlayAudioOptions
137+
)
138+
139+
cancel_all_media_operations_result = await call_connection_async.cancel_all_media_operations()
140+
```
141+
142+
### Hang up the call connection
143+
Once the call is establised, the `hang_up` method can be invoked:
144+
145+
```Python
146+
await call_connection_async.hang_up()
147+
```
148+
149+
### Create a server Call
150+
The call will be establised after the `join_call` method get invoked:
151+
152+
```Python
153+
from azure.communication.callingserver import (
154+
CommunicationUserIdentifier,
155+
JoinCallOptions,
156+
ServerCallLocator
157+
)
158+
159+
call_locator = ServerCallLocator("<server-call-id>")
160+
call_connection = await call_connection_async.join_call(
161+
call_locator=call_locator,
162+
source=CommunicationUserIdentifier("<user-id>"),
163+
join_call_options=JoinCallOptions"<...>"))
164+
)
165+
```
166+
167+
- `call_locator`: The callLocator contains the call id.
168+
- `source`: The source identity which join the call.
169+
- `play_audio_options`: The joinCall options.
170+
171+
### Add participant with calllocator to the server call
172+
Once the call is establised, the `add_participant` method can be invoked:
173+
174+
```Python
175+
from azure.communication.callingserver import (
176+
CommunicationUserIdentifier,
177+
ServerCallLocator
178+
)
179+
180+
call_locator = ServerCallLocator("<server-call-id>")
181+
add_participant_result = await callingserver_client.add_participant(
182+
call_locator=call_locator,
183+
participant=CommunicationUserIdentifier("<user-id>")
184+
callback_uri="<callback-uri>"
185+
)
186+
```
52187

53-
sms_responses = callingserver_client.createCallConnection(
54-
source="<from-phone-number>",
55-
targets="<to-phone-number-1>",
56-
createCallOptions=Something)
188+
- `call_locator`: The callLocator contains the call id.
189+
- `participant`: The participant to be added to the call.
190+
- `callback_uri`: The callback uri.
191+
192+
### Remove participant with callLocator from the server call
193+
Once the participant_id is provided, the `remove_participant` method can be invoked:
194+
195+
```Python
196+
from azure.communication.callingserver import (
197+
CommunicationUserIdentifier,
198+
ServerCallLocator
199+
)
200+
201+
await callingserver_client.remove_participant(
202+
call_locator=call_locator,
203+
participant=CommunicationUserIdentifier("<user-id>")
204+
callback_uri="<callback-uri>"
205+
)
206+
```
207+
208+
- `call_locator`: The callLocator contains the call id.
209+
- `participant`: The participant to be removed from the call.
210+
- `callback_uri`: The callback uri.
211+
212+
### Play audio with callLocator in the server call
213+
Once the call is establised, the `play_audio` method can be invoked:
214+
215+
```Python
216+
from azure.communication.callingserver import (
217+
PlayAudioOptions,
218+
ServerCallLocator
219+
)
220+
221+
call_locator = ServerCallLocator("<server-call-id>")
222+
play_audio_result = await callingserver_client.play_audio(
223+
call_locator=call_locator,
224+
audio_file_uri="<audio-file-uri>",
225+
play_audio_options=PlayAudioOptions"<...>"))
226+
)
227+
```
228+
229+
- `call_locator`: The callLocator contains the call id.
230+
- `audio_file_uri`: The uri of the audio file.
231+
- `play_audio_options`: The playAudio options.
232+
233+
### Cancel media operations with calllocator in the server call
234+
Once the call is establised, the `cancel_media_operation` method can be invoked:
235+
236+
```Python
237+
from azure.communication.callingserver import (
238+
ServerCallLocator
239+
)
240+
241+
call_locator = ServerCallLocator("<server-call-id>")
242+
cancel_all_media_operations_result = await call_connection_async.cancel_media_operation(
243+
call_locator=call_locator,
244+
media_operation_id=media_operation_id
245+
)
57246
```
58247

59-
- `from_`: Something.
60-
- `to`: Something.
61-
- `createCallOptions`: Something.
248+
- `audio_file_uri`: The callLocator contains the call id.
249+
- `media_operation_id`: The operationId of the media operation to cancel.
62250

63251

64252
## Troubleshooting
@@ -67,7 +255,7 @@ Running into issues? This section should contain details as to what to do there.
67255

68256
## Next steps
69257

70-
More sample code should go here, along with links out to the appropriate example tests.
258+
More sample code should go under samples folder, along with links out to the appropriate example tests.
71259

72260
## Provide Feedback
73261

0 commit comments

Comments
 (0)