2016-10-07 2 views
0

나는 전화 번호가 올라올 때까지 각 번호로 전화를 걸어 숫자 목록을 순환시키는 데 관심이 있습니다. 목록의 끝에 도달하면, 처음부터 N 번 다시 시작하십시오.전화가 응답 될 때까지 전화 번호를 통해 Twilio 순환

<Response> 
    <Dial action="hangup.php" timeout="5"> 
     <Number url="greet.php"> 
      123-456-7890 
     </Number> 
    </Dial> 
    <Dial action="hangup.php" timeout="5"> 
     <Number url="greet.php"> 
      223-456-7890 
     </Number> 
    </Dial> 
</Response> 

루프 N 시간에 대한 응답을위한 어떤 방법이 있나요, 또는 솔루션은 단순히 하드 코드 응답 블록 내 다이얼 요소 N 시간은 다음과 같습니다

내 스크립트는 다음과 같습니다?

답변

1

"<Redirect>"을 사용해보세요. 하지만 조심스럽게 사용하여 무한 루프에 빠지지 않도록하십시오 (모든 루프의 경우처럼 항상 그렇습니다)

아직이 코드를 NodeJS에서 테스트하지 않았지만 방법 <Redirect>의 생각은 잠재적으로 당신이

const maxRetries = 10; 

app.get('/loopOnThisTwiml', 
function(i_Req,o_Res) 
    { 

     var counter = i_Req.query.loopCounter ; 
     if(!counter) 
     { 
      counter = 0 ; 
     } 
     else 
     { 
      counter = counter+1; 
      } 

     var ivrTwimlResp = new twilio.TwimlResponse(); 
     var thisTwimlUrl = "/loopOnThisTwiml?loopCounter=" + counter ; 

     ivrTwilRes.dial({callerId:'+1xxxxxxxxx',action:"hangup.php",method:"GET",timeout:"5"}, 
      function() 
       { 
         this.number('+11234567890',{url:"/greet.php",method:"GET"}); 
       } 
      ) 
      .dial({callerId:'+1xxxxxxxxx',action:"hangup.php",method:"GET",timeout:"5"}, 
         function() 
          { 
           this.number('+12234567890',{url:"/greet.php",method:"GET"}); 
          } 
        ); 

     if(counter < maxRetries) 
     { 
      ivrTwilRes.redirect({ method : 'GET' } , thisTwimlUrl); 
     } 

     o_Res.set('Content-Type','text/xml'); 
     o_Res.send(ivrTwimlResp.toString()); 
    } 
); 

을 필요로 무엇을 달성하는 데 사용할 수 위의 코드 TwiML 귀하의 질문에 언급하고 카운터 (maxRetries)에 도달 할 때까지 같은 TwiML에"<Redirect>"를 추가 생성; maxRetries는 전역 상수로 정의됩니다.

귀하의 질문에있는 TwiML은 연속적으로 전화를 걸고 다른 번호보다 한 번호를 선호 할 때 유용합니다. 동시에 여러 번호로 전화를 걸고 다른 사람이 전화를 받도록하려는 경우 Simulring을 볼 수도 있습니다.

+0

흥미로운 접근법. 이 새로운 단점은 각 HTTP 요청이 만들어지기 때문에 각주기 사이에 약간의 대기 시간이 있다는 것입니다. – levi

관련 문제