public class SampleCallableService extends Object
Callable Services are defined as services which are invoked as a result of being directly called, as opposed to being invoked when an end user's address is used to originate/receive a call. The code below illustrates how a callable service can play an announcement and further divert the call or add participants to the call.
The concepts demonstrated are
@TheCallListener
public class SampleCallableService extends CallListenerAbstract
{
private Call myCall;
private final Logger logger = Logger.getLogger(SampleCallableService.class);
@Override
public void callIntercepted(final Call call)
{
// call.wasServiceCalled() tells the snap-in if the snap-in is invoked as a callable service.
if (call.wasServiceCalled())
{
logger.finer("callIntercepted - snap-in is configured as a callable service");
presentOptionsToUser(call);
}
else
{
logger.finer("callIntercepted - snap-in is sequenced.");
// Logic here is executed when snap-in is sequenced in Calling or Called phase.
}
}
private void presentOptionsToUser(final Call call)
{
try
{
final MyListener mediaListener = new MyListener();
final MediaService mediaService = MediaFactory.createMediaService();
myCall = call;
final PlayItem playItem = MediaFactory
.createPlayItem()
.setSource("http://www.mycompany.com/user_options.wav")
.setInterruptible(true).setIterateCount(1);
final DigitOptions digitOptions = MediaFactory.createDigitOptions()
.setNumberOfDigits(1).setTerminationKey("#")
.setTimeout(60000);
final Participant participant = call.getCallingParty();
mediaService.promptAndCollect(participant, playItem,
digitOptions, mediaListener);
}
catch (final URISyntaxException e)
{
logger.error("Bad file URI ", e);
}
}
private class MyListener extends MediaListenerAbstract
{
@Override
public void playCompleted(final UUID requestId,
final PlayOperationCause cause)
{
logger.fine(myCall.getId() + " Done playing prompt." + cause);
myCall.drop();
}
@Override
public void digitsCollected(final UUID requestId, final String digits,
final DigitCollectorOperationCause cause)
{
logger.fine(myCall.getId() + " Received digits. ");
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;
}
else if (digits.startsWith("1"))
{
final String divertExtension = "3000";
myCall.divertTo(divertExtension);
}
else if (digits.startsWith("2"))
{
final Participant firstParticipant = ParticipantFactory.create("3000");
// firstParticipant is added to call immediately.
myCall.addParticipant(firstParticipant);
// Please note that call.allow() is not needed since this is a callable service
}
}
}
}
Copyright © 2023 Avaya. All rights reserved.