From 7ec551e21d7496e772f3a5991d3c314ab1ffcc10 Mon Sep 17 00:00:00 2001 From: Sergey Kasatkin Date: Tue, 24 Jan 2017 11:50:01 +0300 Subject: [PATCH] Update waitForDigit --- src/AGI/Handler.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/AGI/Handler.php b/src/AGI/Handler.php index cb83472..3d5b58e 100644 --- a/src/AGI/Handler.php +++ b/src/AGI/Handler.php @@ -2,6 +2,8 @@ namespace gietos\AGI; +use Exception; + /** * PHP AGI Functions for Asterisk * fork from https://github.com/d4rkstar/phpagi @@ -681,13 +683,21 @@ public function verbose($message, $level = 1) * * @link http://www.voip-info.org/wiki-wait+for+digit * @param integer $timeout in millisecons. Use -1 for the timeout value if you want the call to wait indefinitely. - * @return array, see evaluate for return information. ['result'] is 0 if wait completes with no - * digit received, otherwise a decimal value of the DTMF tone. Use chr() to convert to - * ASCII. + * @return int Digit received + * @throws Exception */ public function waitForDigit($timeout = -1) { - return $this->evaluate("WAIT FOR DIGIT $timeout"); + $result = $this->evaluate("WAIT FOR DIGIT $timeout"); + if ($result['code'] != '200') { + throw new Exception('Error while executing WAIT FOR DIGIT cmd'); + } + + if ($result['result'] == '0') { + return null; + } + + return chr($result['result']); } /**