doukanwa6872 2010-11-29 15:33
浏览 83
已采纳

挂断Twilio时提交POST数据

I have an application that runs with Twilio. The idea is that you will call a phone number twilio will answer and give you menu options. Once you press a digit it will submit the post data and then hang up (That part all works correctly) The problem I'm having is finding out if there is a way to submit post data if the user just hangs up as soon as twilio answers... I found the following code on their documentation.

<?xml version="1.0" encoding="UTF-8"?>
<!-- page located at http://example.com/gather_hints.xml -->
<Response>
 <Gather action="/process_gather.php" method="GET">
     <Say>Enter something, or not</Say>
 </Gather>
 <Redirect method="GET">
     /process_gather.php?Digits=TIMEOUT
 </Redirect>
</Response>

The problem with this is you need to wait until the end of the message for gather to time out. Is there a way to make it so as soon as starts, if the user hangs up it'll do something like go to the redirect tag?

Thanks!

Edit: So on the process_gather.php page, I can save the completed status as a variable?

$Completed = $_POST["completed"]; //which would set $Completed == 'completed'

and then in that page I can just basically say if if(!empty($Completed)) do something (I have to work it into my logic, but I just want to make sure I get the general idea)

  • 写回答

1条回答 默认 最新

  • douzhuo6931 2010-11-29 22:31
    关注

    The best way to solve this is by using the StatusCallback URL. You can set this URL for inbound calls in the Number configuration in your account, or through an optional argument for outbound calls.

    When the call completes, Twilio will POST (or GET) to the URL with all the same variables it passes during a normal request. The CallStatus variable will be set to completed.

    If that URL is called before you get input from the user (to your `/process_gather.php' script), then they hung up.

    Note: You can use cookies to manage session state within a call: all requests made by Twilio during the same call (and the StatusCallback request) will contain any cookies you send. This allows you to use a session variable to track call progress.

    PHP Example for /proces_gather.php:

     <?php 
     session_start(); 
     // adds it to our session 
     $_SESSION['gather_result']=$_POST["Digits"]; 
     // then do whatever else you want your gather script to do.
     ?> 
    

    PHP Example for /status_callback.php, which should be configured as the StatusCallback URL for the phone number in the Twilio Account screen:

    <?php
    session_start();
    //check for gather_result
    if(isset($_SESSION['gather_result'])){
      //user did enter digits
    } else {
      //do whatever you want to do if the user entered no digits.
    }
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度