当您挂断 Twilio 时提交 POST 数据
我有一个与 Twilio 一起运行的应用程序。这个想法是,你拨打一个电话号码,twilio 会接听并给你菜单选项。一旦你按下一个数字,它就会提交发布数据,然后挂断(这部分工作正常)我遇到的问题是找出如果用户在 twilio 后立即挂断,是否有办法提交发布数据答案...我在他们的文档中找到了以下代码。
<?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>
这样做的问题是您需要等到消息结束才能收集超时。有没有办法让它一开始,如果用户挂断,它就会执行诸如转到重定向标记之类的操作?
谢谢!
编辑:那么在 process_gather.php 页面上,我可以将完成的状态保存为变量吗?
$Completed = $_POST["completed"]; //which would set $Completed == 'completed'
然后在该页面中我基本上可以说 if if(!empty($Completed)) 做某事 (我必须将其融入我的逻辑,但我只是想确保我了解总体思路)
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决此问题的最佳方法是使用 StatusCallback URL。您可以在帐户的号码配置中为入站呼叫设置此 URL,或者通过出站呼叫的可选参数设置此 URL。
调用完成后,Twilio 将 POST(或 GET)到包含所有 与正常请求期间传递的相同变量。
CallStatus
变量将设置为completed
。如果在您从用户获得输入(到您的“/process_gather.php”脚本)之前调用该 URL,那么它们就会挂断。
注意:您可以使用 cookie 来管理呼叫中的会话状态:Twilio 在同一呼叫期间发出的所有请求(以及 StatusCallback 请求)将包含您发送的任何 cookie。这允许您使用会话变量来跟踪呼叫进度。
/proces_gather.php
的 PHP 示例:/status_callback.php
的 PHP 示例,应将其配置为 Twilio 帐户屏幕中电话号码的 StatusCallback URL: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 tocompleted
.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 Example for
/status_callback.php
, which should be configured as the StatusCallback URL for the phone number in the Twilio Account screen: