I am playing with Twilio Voice API and have a callback URL to my application whenever an answering machine/human is detected. The mp3 I am trying to play works fine through Twiml Runtime Bin. However, when application responds with the Twiml, twilio always recites the URL instead of playing the music.
public void makeOutBoundCall()
{
Twilio.init(TWILIO_ACCOUNT_SID, TWILIO_ACCOUNT_TOKEN);
CallCreator callCreator = new CallCreator(TWILIO_ACCOUNT_SID, new PhoneNumber(TO_NUMBER),
new PhoneNumber(TWILIO_NUMBER),
URI.create(APP_URL + TwilioVoiceApplication.TWILIO_AMD_CALLBACL_URL))
.setMachineDetection("DetectMessageEnd")
.setMachineDetectionTimeout(20000);
callCreator.create();
}
@RequestMapping(method = RequestMethod.POST)
public String amdCallback(@RequestParam Map<String, String> queryMap) throws Exception
{
// Default behavior hangup the call
Hangup hangup = new Hangup();
VoiceResponse voiceResponse = new VoiceResponse.Builder().hangup(hangup)
.build();
if (queryMap.containsKey("AnsweredBy"))
{
if (queryMap.get("AnsweredBy")
.equals("human"))
{
voiceResponse = new VoiceResponse.Builder()
.say(new Say.Builder("Hello Monkey").build())
.play(new Play.Builder("http://demo.twilio.com/hellomonkey/monkey.mp3")
.build())
.build();
}
}
return voiceResponse.toString();
}