Not a problem. You won't need everything here but here is the base source file for the VXML I listed:
package com.avaya.ReceiveAsrTestService;
import java.net.URI;
import java.util.Date;
import java.util.Map;
import java.util.UUID;
import com.avaya.collaboration.call.Call;
import com.avaya.collaboration.call.CallListener;
import com.avaya.collaboration.call.CallTerminationCause;
import com.avaya.collaboration.call.MediaType;
import com.avaya.collaboration.call.Participant;
import com.avaya.collaboration.call.TheCallListener;
import com.avaya.collaboration.call.speech.search.SpeechFactory;
import com.avaya.collaboration.call.speech.search.SpeechService;
import com.avaya.collaboration.call.speech.voicexml.VoiceXMLDialogCause;
import com.avaya.collaboration.call.speech.voicexml.VoiceXMLDialogItem;
import com.avaya.collaboration.call.speech.voicexml.VoiceXMLDialogListener;
import com.avaya.collaboration.util.logger.Logger;
import com.avaya.collaboration.eventing.EventMetaData;
import com.avaya.collaboration.eventing.EventProducer;
import com.avaya.collaboration.eventing.EventingFactory;
import com.avaya.zephyr.platform.dal.api.ServiceDescriptor;
import com.avaya.zephyr.platform.dal.api.ServiceUtil;
import com.avaya.collaboration.dal.factory.CollaborationDataFactory;
import com.avaya.collaboration.businessdata.api.ServiceData;
@TheCallListener
public class AsrCallListener implements CallListener, VoiceXMLDialogListener {
private final Logger logger;
private SpeechService speechService;
private int maxPrompts = 1;
public AsrCallListener() {
logger = Logger.getLogger(AsrCallListener.class);
}
@Override
public void callAlerting(final Participant alertingParty) {
logger.finest("callAlerting invoked. AlertingParty=" + alertingParty);
}
@Override
public void callAnswered(final Call call) {
final String phase = call.isCallingPhase() ? " calling phase "
: " called phase ";
if (logger.isFinestEnabled()) {
logger.finest("callAnswered ENTER invoked in" + phase);
}
maxPrompts = readNumberOfPromptsAttribute();
final UUID requestIdVxmlCalled = voiceXMLDialog(call.getCallingParty());
logger.finer("call answered adding call=" + call
+ " requestId=" + requestIdVxmlCalled);
VxmlCallData.addCall(requestIdVxmlCalled, call);
logger.finer("call answered adding counter=" + call
+ " counter=1");
VxmlCallData.addCounter(call, 1);
logger.finer("starting dialog with request ID= "
+ requestIdVxmlCalled);
logger.finest("dialogEvent EXIT");
}
@Override
public void callTerminated(Call call, CallTerminationCause cause) {
logger.finest("callTerminated ENTER");
if (cause != CallTerminationCause.ABANDONED
&& cause != CallTerminationCause.AFTER_ANSWER) {
callFailed(call, cause);
}
logger.finest("callTerminated EXIT");
}
@Override
public void callOriginated(Call call) {
}
private void callFailed(final Call call, CallTerminationCause cause) {
logger.finest("callFailed ENTER");
logger.finest("Call failed with cause "
+ (cause == null ? "unknown" : cause.getValue()));
logger.finest("callFailed EXIT");
}
@Override
public void callIntercepted(final Call call) {
logger.finest("callIntercepted ENTER");
call.enableMediaBeforeAnswer();
logger.fine("callIntercepted from "
+ call.getCallingParty().getAddress() + " (name = "
+ call.getCallingParty().getDisplayName() + ") to "
+ call.getCalledParty().getAddress() + " (name = "
+ call.getCalledParty().getDisplayName());
logger.finest("callIntercepted EXIT");
}
private UUID voiceXMLDialog(final Participant participant) {
logger.finer("vxmlDialog ENTER " + participant.getDisplayName());
URI voiceXMLScript = null;
try {
voiceXMLScript = new URI(
"http://10.135.47.16/services/ReceiveAsrTestService/scripts/TTSASRtest.vxml");
// "http://info.dr.avaya.com/~ikes/vxml/TTSASRtest.vxml");
} catch (Exception e) {
logger.warn("Failed to create URI for VoiceXML script");
return null;
}
logger.finest("set script to
http://10.135.47.16/services/ReceiveAsrTestService/scripts/TTSASRtest.vxml");
// logger.finest("set script to
http://info.dr.avaya.com/~ikes/vxml/TTSASRtest.vxml");
final VoiceXMLDialogItem voiceXMLDialogItem = SpeechFactory
.createVoiceXMLDialogItem().setVoiceXMLScript(voiceXMLScript);
UUID requestId = getSpeechService().startVoiceXMLDialog(participant,
voiceXMLDialogItem, this);
logger.finest("voiceXMLDIalog new request ID is " + requestId);
logger.finer(" vxmlDialog EXIT");
return requestId;
}
private void sendEvent(String body) {
final EventMetaData filterData = EventingFactory.createEventMetaData();
final String eventBody = body;
final String eventVersion = "1.0.0.0";
final EventProducer publisher =
EventingFactory.createEventProducer("ASR",
"ASR_RECEIVED",
filterData, eventBody, eventVersion);
publisher.publish();
}
@Override
public void dialogEvent(UUID requestId, Map<String, Object> names,
VoiceXMLDialogCause cause) {
logger.finest("dialogEvent ENTER, cause is " + cause
+ " request ID = " + requestId);
final Call call = VxmlCallData.getCallByRequestId(requestId);
Integer count = VxmlCallData.getCounterByCall(call);
Date date = new Date(System.currentTimeMillis());
if (names != null) {
logger.finest("names is not null");
final StringBuilder sb = new StringBuilder();
for (String key : names.keySet()) {
sb.append("\n\t" + key + " " + names.get(key));
}
String songName = sb.toString().replace("song%24.utterance ", "");
songName = songName
.replace("msml.dialog.exit msml.dialog.exit", "");
songName = songName.replaceAll("\n", "");
songName = songName.replaceAll("\r", "");
songName = songName.replaceAll("\t", "");
logger.finest("Received requestId = " + requestId
+ " for call = " + call + " ucid = " + call.getUCID()
+ " count = " + count + " namelist = " + songName
+ " cause = " + cause
);
logger.info(";" + date + ";" + songName + ";" + call.getUCID()
+ ";" + count + ";" + requestId);
logger.finest("Publishing event");
sendEvent(songName + "," + call.getUCID());
} else {
logger.info("names is null");
}
logger.finer("dialog event removing call=" + call
+ " requestId=" + requestId);
VxmlCallData.removeCall(requestId);
logger.finer("dialogEvent EXIT UUID is: " + requestId);
logger.finest("COUNT is " + count);
if (count < maxPrompts) {
final UUID newRequestId = voiceXMLDialog(call.getCallingParty());
logger.finest("starting dialog with request ID= "
+ newRequestId + " count=" + count + " call= " + call);
logger.finest("dialog event adding call=" + call
+ " requestId=" + newRequestId);
VxmlCallData.addCall(newRequestId, call);
count++;
logger.finer("dialog event removing counter call ="
+ call);
VxmlCallData.removeCounter(call);
logger.finer("dialog event adding counter call=" + call
+ " counter=" + count);
VxmlCallData.addCounter(call, count);
} else {
logger.fine(""
+ "Dropping call= " + call + " count = " + count);
logger.info(";" + date + ";Dropping call;" + call.getUCID() + ";"
+ count + "; ;");
call.drop();
}
}
@Override
public void mediaDetected(Participant partySendingMedia,
MediaType mediaTypeDetected) {
logger.finest("dialogEvent ENTER");
logger.finer(partySendingMedia.getDisplayName()
+ " mediaTypeDetected = " + mediaTypeDetected);
logger.finest("About call the VoiceXML dialog");
}
@Override
public void addParticipantFailed(Call call, Participant failedParticipant,
CallTerminationCause cause) {
}
private SpeechService getSpeechService() {
if (speechService == null) {
speechService = SpeechFactory.createSpeechService();
}
return speechService;
}
private int readNumberOfPromptsAttribute() {
String numPromptsStr = "1";
int numPrompts = 1;
ServiceDescriptor svc = ServiceUtil.getServiceDescriptor();
if (svc == null)
{
throw new IllegalStateException("Couldn't get service descriptor");
}
final ServiceData svcData = CollaborationDataFactory.getServiceData(svc.getName(), svc.getVersion());
try
{
numPromptsStr = svcData.getServiceAttribute("numPrompts");
numPrompts = Integer.parseInt(numPromptsStr);
}
catch(NumberFormatException nfe)
{
logger.error("NumberFormatException and so using default num_prompts = " + numPrompts);
}
catch (Exception e)
{
logger.error("Exception while getting service attribute num_prompts ", e);
}
logger.info("num_prompts is " + numPrompts);
return numPrompts;
}
}