public class SampleMediaCall extends Object
TheCallListener
and either implements CallListener
or extends
CallListenerAbstract
. This class is a "listener" that allows you to intercept a call.
Next, you must implement a "media listener" class that either implements MediaListener
or extends MediaListenerAbstract
.
This class allows you to be notified when important events related to playing an announcement have occurred. Specifically, if you "play"
an announcement (without collecting digit presses by the caller), then the method playCompleted will be called after the playout
of the announcement is done. If you "prompt" with an announcement and "collect" digit presses from the caller, then the
digitsCollected method will be called to indicate that the "prompt and collect" interaction with the caller has completed. (Note
that the sample below does not illustrate the use of the "play" of an announcement; instead it illustrates the use of
"prompt and collect".)
In the callIntercepted method shown below, various properties are set that determine how the announcement will function. Included
are the following:
@TheCallListener public class SampleMediaCall extends CallListenerAbstract { private final Logger logger = Logger.getLogger(SampleMediaCall.class); private Call myCall; private UUID myId; @Override public void callIntercepted(final Call call) { try { final MyListener mediaListener = new MyListener(); final MediaService mediaService = MediaFactory.createMediaService(); myCall = call; final PlayItem playItem = MediaFactory .createPlayItem() .setSource( "http://www.example.com", "http://www.mycompany.com/contact_info.wav") .setInterruptible(true).setIterateCount(1); final DigitOptions digitOptions = MediaFactory.createDigitOptions() .setNumberOfDigits(1).setTerminationKey("*") .setTimeout(60000); final Participant participant = call.getCallingParty(); myId = mediaService.promptAndCollect(participant, playItem, digitOptions, mediaListener); } catch (final URISyntaxException e) { logger.error("Bad file URI ", e); } // // Since an announcement is being played to the caller, // the set up of the call will be automatically suspended. // In the listener methods below we'll take the final action // (allow the call) after the digit is collected. // } private class MyListener extends MediaListenerAbstract { @Override public void playCompleted(final UUID requestId, final PlayOperationCause cause) { if (!myId.equals(requestId)) { logger.warn(requestId + " message dropped because it was not " + myId); return; } logger.fine(myCall.getId() + " Done playing prompt." + cause); myCall.drop(); } @Override public void digitsCollected(final UUID requestId, final String digits, final DigitCollectorOperationCause cause) { if (!myId.equals(requestId)) { logger.warn(requestId + " message dropped because it was not " + myId); myCall.drop(); return; } logger.fine(myCall.getId() + " Received digits, now allow call. " + cause); if (digits == null || digits.length() == 0) { logger.fine(myCall.getId() + " No selection was made and so the call will be diverted. "); final String operatorExtension = "0"; myCall.divertTo(operatorExtension); return; } myCall.allow(); } } }
Copyright © 2023 Avaya. All rights reserved.