@@ -0,0 +1,2260 @@
+package org.motechproject.ScheduleTrackingDemo.listeners;%0A%0A%0Aimport org.motechproject.ivr.event.IVREventDelegate;%0Aimport org.motechproject.ivr.model.CallDetailRecord;%0Aimport org.motechproject.model.MotechEvent;%0Aimport org.motechproject.outbox.api.VoiceOutboxService;%0Aimport org.motechproject.outbox.api.model.MessagePriority;%0Aimport org.motechproject.outbox.api.model.OutboundVoiceMessage;%0Aimport org.motechproject.outbox.api.model.VoiceMessageType;%0Aimport org.motechproject.server.event.annotations.MotechListener;%0Aimport org.motechproject.server.voxeo.web.IvrController;%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0Aimport org.springframework.beans.factory.annotation.Autowired;%0A%0Apublic class CallResultListener %7B%0A%0A%09private static Logger logger = LoggerFactory%0A%09%09%09.getLogger(CallResultListener.class);%0A%0A%0A%09@Autowired%0A%09private VoiceOutboxService outboxService;%0A%0A%09//For demo purposes, successful calls are also stored in the outbox%0A%09@MotechListener(subjects = %7B%22CALL_BUSY%22 , %22CALL_FAIL%22, %22CALL_NO_ANSWER%22, %22CALL_SUCCESS%22%7D)%0A%09public void execute(MotechEvent event) %7B%0A%09%09System.out.println(%22Handling event: %22 + event.getSubject());%0A%09%09logger.debug(%22Handled call event%22);%0A%0A%09%09//if (!event.getSubject().equals(%22CALL_SUCCESS%22)) %7B //Call was not successful, store in outbox%0A%0A%09%09%09String externalId = (String) event.getParameters().get(IvrController.CALL_RESULT_ID);%0A%09%09%09%0A%09%09%09CallDetailRecord cdr = (CallDetailRecord) event.getParameters().get(IVREventDelegate.CALL_DETAIL_RECORD_KEY);%0A%0A%0A%09%09%09OutboundVoiceMessage outboundVoiceMessage = new OutboundVoiceMessage();%0A%09%09%09outboundVoiceMessage.setPartyId(cdr.getPhoneNumber()); //Content is identified by phone number for now%0A%0A%0A%09%09%09VoiceMessageType voiceMessageType = new VoiceMessageType();%0A%09%09%09voiceMessageType.setCanBeReplayed(true);%0A%09%09%09voiceMessageType.setCanBeSaved(true);%0A%09%09%09voiceMessageType.setPriority(MessagePriority.MEDIUM);%0A%09%09%09%0A%09%09%09//Template work-around for now, template name is based on the content%0A%09%09%09%0A%09%09%09String content = (String) event.getParameters().get(IvrController.CALL_CONTENT);%0A%09%09%09String template = content.replace(%22.xml%22, %22%22);%0A%09%09%09voiceMessageType.setTemplateName(template);%0A%0A%0A%09%09%09outboundVoiceMessage.setVoiceMessageType(voiceMessageType);%0A%0A%09%09%09outboxService.addMessage(outboundVoiceMessage);%0A%0A%09%09%7D%0A%09%7D%0A%0A%0A

Call result listener listens on call result events raised by Voxeo