2017-12-19 9 views
1

私はTwilio Voice APIで遊んでいて、留守番電話/人間が検出されるたびにアプリケーションにコールバックURLを持っています。私がプレイしようとしているmp3はTwiml Runtime Binでうまく動作します。しかし、アプリケーションがTwimlで応答すると、twilioは常に音楽を再生するのではなくURLを暗唱します。Twilio Voice APIはMP3音楽を再生する代わりにmp3 URLを暗唱します

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(); 
} 
+0

問題は、「コンテンツタイプ:text/xmlで」を追加し、レスポンスヘッダとあった、あなたはそれをソートしてしまった – Chinmay

+1

がうれしい問題を修正しました!私は実際にこれを下記の答えとして追加し、それを受け入れることをお勧めします。同じ問題を抱えている場合は、他の人がソリューションを見やすくなります。 – philnash

答えて

0
@RequestMapping(method = RequestMethod.POST, produces = "application/xml") 
public ResponseEntity<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(); 
     } 
    } 
    HttpHeaders headers = new HttpHeaders(); 
    //Add the content-type:text/html in response header 
    headers.add(HttpHeaders.CONTENT_TYPE, "text/xml"); 

    ResponseEntity<String> response = ResponseEntity.ok() 
      .headers(headers) 
      .body(voiceResponse.toXml()); 
    return response; 
} 
関連する問題