Skip to content

Commit 7ec551e

Browse files
author
Sergey Kasatkin
committed
Update waitForDigit
1 parent 1ad1c76 commit 7ec551e

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

src/AGI/Handler.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace gietos\AGI;
44

5+
use Exception;
6+
57
/**
68
* PHP AGI Functions for Asterisk
79
* fork from https://github.com/d4rkstar/phpagi
@@ -681,13 +683,21 @@ public function verbose($message, $level = 1)
681683
*
682684
* @link http://www.voip-info.org/wiki-wait+for+digit
683685
* @param integer $timeout in millisecons. Use -1 for the timeout value if you want the call to wait indefinitely.
684-
* @return array, see evaluate for return information. ['result'] is 0 if wait completes with no
685-
* digit received, otherwise a decimal value of the DTMF tone. Use chr() to convert to
686-
* ASCII.
686+
* @return int Digit received
687+
* @throws Exception
687688
*/
688689
public function waitForDigit($timeout = -1)
689690
{
690-
return $this->evaluate("WAIT FOR DIGIT $timeout");
691+
$result = $this->evaluate("WAIT FOR DIGIT $timeout");
692+
if ($result['code'] != '200') {
693+
throw new Exception('Error while executing WAIT FOR DIGIT cmd');
694+
}
695+
696+
if ($result['result'] == '0') {
697+
return null;
698+
}
699+
700+
return chr($result['result']);
691701
}
692702

693703
/**

0 commit comments

Comments
 (0)