@@ -169,19 +169,18 @@ public class App
169
169
// Play audio to participants in the call
170
170
CallMedia callMedia = callConnection. getCallMedia();
171
171
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.
185
184
String callConnectionId = event. getCallConnectionId();
186
185
CallConnection callConnection = client. getCallConnection(callConnectionId);
187
186
// Invite other participants to the call
@@ -192,7 +191,7 @@ public class App
192
191
.setOperationContext(UUID . randomUUID(). toString())
193
192
.setSourceCallerId(new PhoneNumberIdentifier (" [phoneNumber]" ));
194
193
callConnection. addParticipants(options);
195
- }
194
+ }
196
195
}
197
196
return " " ;
198
197
});
@@ -240,8 +239,8 @@ Now, given that all setup is completed, you can test your application:
240
239
1 . Call the number you acquired in the prerequisites section of this guide.
241
240
2 . The incoming call event is sent to the application’s ` /api/incomingCall ` endpoint. Application answers the call using Call Automation SDK.
242
241
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.
245
244
6 . Application adds a participant to the call (web app user created earlier in this quickstart).
246
245
7 . User accepts the invitation to join the call.
247
246
8 . ` AddParticipantsSucceeded ` event is delivered to ` /api/callback ` endpoint.
0 commit comments