Skip to content

Commit ea1c054

Browse files
authored
Update callflow-for-customer-interactions-java.md
update java code to add recognize and test scenario
1 parent de91d65 commit ea1c054

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

articles/communication-services/quickstarts/voice-video-calling/includes/call-automation/callflow-for-customer-interactions-java.md

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -169,19 +169,18 @@ public class App
169169
// Play audio to participants in the call
170170
CallMedia callMedia = callConnection.getCallMedia();
171171
FileSource fileSource = new FileSource().setUri("<Audio file URL>");
172-
PlayOptions playOptions = new PlayOptions.setLoop(false);
173-
callMedia.playToAllWithResponse(fileSource, playOptions);
174-
} else if (event.getClass() == CallDisconnectedEvent.class) {
175-
// Call disconnected, perform some custom logic
176-
} else if (event.getClass() == AddParticipantsSucceededEvent.class) {
177-
// CommunicationUser was added to the call
178-
} else if (event.getClass() == AddParticipantsFailedEvent.class) {
179-
// CommunicationUser failed to be added to the call
180-
} else if (event.getClass() == ParticipantsUpdatedEvent.class) {
181-
// Participant list of the call is updated
182-
} else if (event.getClass() == PlayCompleted.class) {
183-
PlayCompleted event = (PlayCompleted) acsEvent;
184-
// Add participant to the call after audio has completed playing.
172+
CommunicationIdentifier targetParticipant = new PhoneNumberIdentifier("<Target-Participant-Phone-Number>");
173+
CallMediaRecognizeOptions recognizeDtmfOptions= new CallMediaRecognizeDtmfOptions(targetParticipant, 3)
174+
.setInterToneTimeoutInSeconds(2)
175+
.setStopTones(Collections.singletonList(Tone.POUND))
176+
.setInterruptPromptAndStartRecognition(true)
177+
.setInitialSilenceTimeoutInSeconds(5)
178+
.setPlayPrompt(fileSource)
179+
.setStopCurrentOperations(true);
180+
callMedia.startRecognizing(recognizeDtmfOptions);
181+
} else if (event.getClass() == RecognizeCompleted.class) {
182+
RecognizeCompleted event = (RecognizeCompleted) acsEvent;
183+
// Add participant to the call after recognize has completed playing.
185184
String callConnectionId = event.getCallConnectionId();
186185
CallConnection callConnection = client.getCallConnection(callConnectionId);
187186
// Invite other participants to the call
@@ -192,7 +191,7 @@ public class App
192191
.setOperationContext(UUID.randomUUID().toString())
193192
.setSourceCallerId(new PhoneNumberIdentifier("[phoneNumber]"));
194193
callConnection.addParticipants(options);
195-
}
194+
}
196195
}
197196
return "";
198197
});
@@ -240,8 +239,8 @@ Now, given that all setup is completed, you can test your application:
240239
1. Call the number you acquired in the prerequisites section of this guide.
241240
2. The incoming call event is sent to the application’s `/api/incomingCall` endpoint. Application answers the call using Call Automation SDK.
242241
3. `CallConnected` event is delivered to `/api/callback` endpoint.
243-
4. Play audio on a loop to all participants on the call.
244-
5. When the audio file has played, a `PlayCompleted` event is received.
242+
4. Play audio and request user input from targeted phone number.
243+
5. When the input has been received and recognized, a `RecognizeCompleted` event is received.
245244
6. Application adds a participant to the call (web app user created earlier in this quickstart).
246245
7. User accepts the invitation to join the call.
247246
8. `AddParticipantsSucceeded` event is delivered to `/api/callback` endpoint.

0 commit comments

Comments
 (0)