Skip to content

Commit

Permalink
Balaji - added sip channel to dial tag
Browse files Browse the repository at this point in the history
  • Loading branch information
balaji committed Nov 20, 2012
1 parent 8c1c686 commit f055fb8
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 94 deletions.
1 change: 0 additions & 1 deletion asterisk-scripts/flash-verboice-agi.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@


$callerid = strlen($agi['callerid']) == 9 ? "".$agi['callerid'] : "000".$agi['callerid'];
#$callerid = '540923923';
$callback_url = "http://localhost/ghana-national-web/outgoing/call";

if(($response = HttpClient::quickGet($callback_url."?callerid=".$callerid)) < 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ context.path=ghana-national-web
callcenter.dtmf.timeout=20
callcenter.dtmf.finishonkey=#
callcenter.no.of.digits.in.motech.id=7
country.code=233
country.code=233
sip.channel.name=sip_channel
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public class IVRCallCenterNoMapping extends MotechBaseDataObject {
private Time endTime;
@JsonProperty
private boolean nurseLine;
@JsonProperty
private boolean sipChannel;

public IVRCallCenterNoMapping() {
}
Expand Down Expand Up @@ -80,4 +82,13 @@ public IVRCallCenterNoMapping nurseLine(boolean b) {
this.nurseLine = b;
return this;
}

public boolean isSipChannel() {
return sipChannel;
}

public IVRCallCenterNoMapping sipChannel(boolean sipChannel) {
this.sipChannel = sipChannel;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.motechproject.decisiontree.model.Node;
import org.motechproject.decisiontree.model.Transition;
import org.motechproject.ghana.national.builder.IVRCallbackUrlBuilder;
import org.motechproject.ghana.national.domain.IVRCallCenterNoMapping;
import org.motechproject.ghana.national.domain.IVRClipManager;
import org.motechproject.ghana.national.domain.ivr.AudioPrompts;
import org.motechproject.ghana.national.domain.mobilemidwife.Language;
Expand All @@ -15,6 +16,7 @@
import org.motechproject.model.Time;
import org.motechproject.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
Expand All @@ -35,6 +37,9 @@ public class ConnectToCallCenterTransition extends Transition {
@JsonProperty
private boolean nurseLine;

@Value("#{ghanaNationalProperties['sip.channel.name']}")
private String sipChannelName;

// Required for Ektorp
public ConnectToCallCenterTransition() {
}
Expand All @@ -56,14 +61,17 @@ public Node getDestinationNode(String input, FlowSession session) {

public Node getAsNode(Language language, String callerPhoneNumber) {
DayOfWeek dayOfWeek = DayOfWeek.getDayOfWeek(DateUtil.today().dayOfWeek().get());
String callCenterPhoneNumber = ivrCallCenterNoMappingService.getCallCenterPhoneNumber(language, dayOfWeek, new Time(DateUtil.now().toLocalTime()), nurseLine);
IVRCallCenterNoMapping mapping = ivrCallCenterNoMappingService.getCallCenterPhoneNumber(language, dayOfWeek, new Time(DateUtil.now().toLocalTime()), nurseLine);

if (callCenterPhoneNumber == null) {
if (mapping == null) {
return new Node().addPrompts(new AudioPrompt().setAudioFileUrl(ivrClipManager.urlFor(AudioPrompts.CALL_CENTER_DIAL_FAILED.value(), Language.EN)));
}

DialPrompt callCenterDialPrompt = new DialPrompt(callCenterPhoneNumber);
DialPrompt callCenterDialPrompt = new DialPrompt(mapping.getPhoneNumber());
callCenterDialPrompt.setCallerId(callerPhoneNumber);
if (mapping.isSipChannel()) {
callCenterDialPrompt.setChannel(sipChannelName);
}
callCenterDialPrompt.setAction(ivrCallbackUrlBuilder.callCenterDialStatusUrl(language, callerPhoneNumber, nurseLine));
return new Node().addPrompts(callCenterDialPrompt);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public List<IVRCallCenterNoMapping> allMappings() {
}

@View(name = "find_by_lang_day_and_time", map = "function(doc) { if(doc.type === 'IVRCallCenterNoMapping') emit([doc.language, doc.dayOfWeek, doc.startTime, doc.endTime], doc) }")
public IVRCallCenterNoMapping findByLangDayAndTime(Language language, DayOfWeek dayOfWeek, Time startTime, Time endTime) {
IVRCallCenterNoMapping findByLangDayAndTime(Language language, DayOfWeek dayOfWeek, Time startTime, Time endTime) {
if (language == null || dayOfWeek == null || startTime == null || endTime == null) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ public IvrCallCenterNoMappingService(AllIvrCallCenterNoMappings allIvrCallCenter
this.allIvrCallCenterNoMappings = allIvrCallCenterNoMappings;
}

public String getCallCenterPhoneNumber(Language language, DayOfWeek dayOfWeek, Time time, boolean nurseLine){
public IVRCallCenterNoMapping getCallCenterPhoneNumber(Language language, DayOfWeek dayOfWeek, Time time, boolean nurseLine){
List<IVRCallCenterNoMapping> allMappings = allIvrCallCenterNoMappings.allMappings();
for (IVRCallCenterNoMapping mapping : allMappings) {
if((nurseLine ? mapping.isNurseLine() : language.equals(mapping.getLanguage()))
&& mapping.getDayOfWeek().equals(dayOfWeek)
&& fallsBetweenIncludingBounds(time, mapping.getStartTime(), mapping.getEndTime()))
return mapping.getPhoneNumber();
return mapping;
}
logger.warn("Unable to find a call center number for the provided criteria, " + language + ", " + dayOfWeek + ", " + time);
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ public void shouldReturnTheCallCenterThatMatchedTheProvidedCriteria() {
new IVRCallCenterNoMapping().phoneNumber("phone_no3").language(Language.EN).dayOfWeek(DayOfWeek.Tuesday).startTime(new Time(10, 10)).endTime(new Time(10, 30))
));

assertThat(ivrCallCenterNoMappingService.getCallCenterPhoneNumber(Language.EN, DayOfWeek.Monday, new Time(10, 10), false), is(equalTo("phone_no1")));
assertThat(ivrCallCenterNoMappingService.getCallCenterPhoneNumber(Language.EN, DayOfWeek.Monday, new Time(10, 15), false), is(equalTo("phone_no1")));
assertThat(ivrCallCenterNoMappingService.getCallCenterPhoneNumber(Language.EN, DayOfWeek.Monday, new Time(10, 30), false), is(equalTo("phone_no1")));
assertThat(ivrCallCenterNoMappingService.getCallCenterPhoneNumber(Language.EN, DayOfWeek.Monday, new Time(10, 31), false), is(equalTo("phone_no2")));
assertThat(ivrCallCenterNoMappingService.getCallCenterPhoneNumber(Language.EN, DayOfWeek.Monday, new Time(11, 30), false), is(equalTo("phone_no2")));
assertThat(ivrCallCenterNoMappingService.getCallCenterPhoneNumber(Language.EN, DayOfWeek.Monday, new Time(10, 10), false).getPhoneNumber(), is(equalTo("phone_no1")));
assertThat(ivrCallCenterNoMappingService.getCallCenterPhoneNumber(Language.EN, DayOfWeek.Monday, new Time(10, 15), false).getPhoneNumber(), is(equalTo("phone_no1")));
assertThat(ivrCallCenterNoMappingService.getCallCenterPhoneNumber(Language.EN, DayOfWeek.Monday, new Time(10, 30), false).getPhoneNumber(), is(equalTo("phone_no1")));
assertThat(ivrCallCenterNoMappingService.getCallCenterPhoneNumber(Language.EN, DayOfWeek.Monday, new Time(10, 31), false).getPhoneNumber(), is(equalTo("phone_no2")));
assertThat(ivrCallCenterNoMappingService.getCallCenterPhoneNumber(Language.EN, DayOfWeek.Monday, new Time(11, 30), false).getPhoneNumber(), is(equalTo("phone_no2")));
assertThat(ivrCallCenterNoMappingService.getCallCenterPhoneNumber(Language.EN, DayOfWeek.Monday, new Time(9, 30), false), is(nullValue()));
assertThat(ivrCallCenterNoMappingService.getCallCenterPhoneNumber(Language.EN, DayOfWeek.Tuesday, new Time(10, 30), false), is(equalTo("phone_no3")));
assertThat(ivrCallCenterNoMappingService.getCallCenterPhoneNumber(null, DayOfWeek.Monday, new Time(10, 30), true), is(equalTo("phone_no4")));
assertThat(ivrCallCenterNoMappingService.getCallCenterPhoneNumber(Language.EN, DayOfWeek.Tuesday, new Time(10, 30), false).getPhoneNumber(), is(equalTo("phone_no3")));
assertThat(ivrCallCenterNoMappingService.getCallCenterPhoneNumber(null, DayOfWeek.Monday, new Time(10, 30), true).getPhoneNumber(), is(equalTo("phone_no4")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ omod.identifier.service.port=8080
omod.identifier.service.path=openmrs/ms/identifier/
omod.user.name=admin
omod.user.password=P@ssw0rd
facility.default.message.cron=0 0 8 ? * SUN
facility.default.message.cron=0 0 8 ? * SUN
sip.channel.name=sip_channel
Loading

0 comments on commit f055fb8

Please sign in to comment.