Skip to content

Commit 5ccf37f

Browse files
authored
Update play-audio-with-ai-csharp.md
add deserialization code snippets
1 parent c33f657 commit 5ccf37f

File tree

1 file changed

+43
-21
lines changed

1 file changed

+43
-21
lines changed

articles/communication-services/how-tos/call-automation/includes/play-audio-with-ai-csharp.md

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -150,27 +150,36 @@ Assert.AreEqual(202, playResponse.Status) // The request was accepted.
150150

151151
Your application receives action lifecycle event updates on the callback URL that was provided to Call Automation service at the time of answering the call. An example of a successful play event update.
152152

153-
```json
154-
[{
155-
"id": "704a7a96-4d74-4ebe-9cd0-b7cc39c3d7b1",
156-
"source": "calling/callConnections/<callConnectionId>/PlayCompleted",
157-
"type": "Microsoft.Communication.PlayCompleted",
158-
"data": {
159-
"resultInfo": {
160-
"code": 200,
161-
"subCode": 0,
162-
"message": "Action completed successfully."
163-
},
164-
"type": "playCompleted",
165-
"callConnectionId": "<callConnectionId>",
166-
"serverCallId": "<serverCallId>",
167-
"correlationId": "<correlationId>"
168-
},
169-
"time": "2022-08-12T03:13:25.0252763+00:00",
170-
"specversion": "1.0",
171-
"datacontenttype": "application/json",
172-
"subject": "calling/callConnections/<callConnectionId>/PlayCompleted"
173-
}]
153+
### Example of how you can deserialize the *PlayCompleted* event:
154+
155+
``` csharp
156+
if (@event is PlayCompleted { OperationContext: "PlayAudio" })
157+
{
158+
var playCompletedEvent = (PlayCompleted)@event;
159+
160+
if (ReasonCode.CompletedSuccessfully.Equals(playCompletedEvent.ReasonCode))
161+
{
162+
//Play audio succeeded, take action on success.
163+
await callConnection.HangUpAsync(forEveryone: true);
164+
}
165+
}
166+
```
167+
168+
### Example of how you can deserialize the *PlayFailed* event:
169+
170+
``` csharp
171+
if (@event is PlayFailed { OperationContext: "PlayAudio" })
172+
{
173+
var playFailedEvent = (PlayFailed)@event;
174+
175+
if (ReasonCode.PlayDownloadFailed.Equals(playFailedEvent.ReasonCode) ||
176+
ReasonCode.PlayInvalidFileFormat.Equals(playFailedEvent.ReasonCode))
177+
{
178+
//Play audio failed, Take some action on failed event.
179+
logger.LogInformation($"PlayFailed event received for call connection id: {@event.CallConnectionId}");
180+
await callConnection.HangUpAsync(forEveryone: true);
181+
}
182+
}
174183
```
175184

176185
To learn more about other supported events, visit the [Call Automation overview document](../../../concepts/call-automation/call-automation.md#call-automation-webhook-events).
@@ -184,3 +193,16 @@ var callMedia = callAutomationClient.GetCallConnection(<callConnectionId>).GetCa
184193
var cancelResponse = await callMedia.CancelAllMediaOperations();
185194
Assert.AreEqual(202, cancelResponse.Status) // The request was accepted.
186195
```
196+
197+
### Example of how you can deserialize the *PlayCanceled* event:
198+
199+
``` csharp
200+
if (@event is PlayCanceled { OperationContext: "PlayAudio" })
201+
{
202+
var playFailedEvent = (PlayCanceled)@event;
203+
204+
logger.LogInformation($"PlayCanceled event received for call connection id: {@event.CallConnectionId}");
205+
//Take action on recognize canceled operation
206+
await callConnection.HangUpAsync(forEveryone: true);
207+
}
208+
```

0 commit comments

Comments
 (0)