Sending POST data when you hang up Twilio

I have an application that works with Twilio. The idea is that you call the twilio phone number, answer and give you menu options. After you press a number, it will send the message data, and then hang up (this part is working correctly). The problem I ran into is to find out if there is a way to send message data if the user just freezes as soon as twilio answers ... I found the following code in my 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 that you need to wait until the end of the message to collect before the timeout. Is there a way to do this as soon as it starts, if the user hangs up, he will do something like go to the redirect tag?

Thank!

: , process_gather.php ?

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

, if (! empty ($ Completed)) - ( , , )

+3
1

- URL- StatusCallback. URL .

, Twilio POST ( GET) URL , . CallStatus completed.

URL- , ( `/process_gather.php 'script), .

. cookie : , Twilio ( StatusCallback), cookie, . .

PHP /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 /status_callback.php, URL- StatusCallback Twilio Account:

<?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.
}
?>
+9

Source: https://habr.com/ru/post/1777479/


All Articles