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.
    }
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思