Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added interrupt digits handling. #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 78 additions & 2 deletions src/mg/PAGI/Node/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Node
* Any of the available DTMF digits in a classic telephone.
* @var string
*/
const DTMF_ANY = '0123456789*#';
const DTMF_ANY = '#*0123456789';
/**
* DTMF digit '*'
* @var string
Expand All @@ -63,7 +63,7 @@ class Node
* DTMF digits which are integers (numbers)
* @var string
*/
const DTMF_NUMERIC = '1234567890';
const DTMF_NUMERIC = '0123456789';
/**
* DTMF digits non numeric
* @var string
Expand Down Expand Up @@ -344,6 +344,49 @@ class Node
*/
private $_playOnNoInputInLastAttempt = false;


/**
* Add specific keys for interruption.
*
* @var string One of the DTMF constants
* @return Node
*/
public function addValidInterruptDigit($digit)
{
if (!$this->_promptsCanBeInterrupted) {
return $this;
}

if (false !== strpos($this->_validInterruptDigits, $digit)) {
return $this;
}

$digits = array_unique(str_split($this->_validInterruptDigits.$digit));
sort($digits);

$this->_validInterruptDigits = '';
foreach($digits as $interrupt_digit) {
switch($interrupt_digit) {
case self::DTMF_0:
case self::DTMF_1:
case self::DTMF_2:
case self::DTMF_3:
case self::DTMF_4:
case self::DTMF_5:
case self::DTMF_6:
case self::DTMF_7:
case self::DTMF_8:
case self::DTMF_9:
case self::DTMF_HASH:
case self::DTMF_STAR:
$this->_validInterruptDigits .= $interrupt_digit;
break;
}
}

return $this;
}

/**
* Make pre prompt messages not interruptable
*
Expand All @@ -368,6 +411,29 @@ public function dontAcceptPrePromptInputAsInput()
return $this;
}

/**
* Clear the digits with which a prompt can be interrupted.
*
* @return Node
*/
public function clearInterruptDigits()
{
$this->_validInterruptDigits = self::DTMF_NONE;
return $this;
}

/**
* Make prompt messages interruptable.
*
* @return Node
*/
public function interruptablePrompts()
{
$this->_promptsCanBeInterrupted = true;
$this->_validInterruptDigits = self::DTMF_ANY;
return $this;
}

/**
* Make prompt messages not interruptable.
*
Expand All @@ -380,6 +446,16 @@ public function unInterruptablePrompts()
return $this;
}

/**
* Returns whether this node is interruptable.
*
* @return Node
*/
public function isInterruptable()
{
return $this->_promptsCanBeInterrupted;
}

/**
* Specify an optional message to play when the user did not enter any
* input at all. By default, will NOT be played if this happens in the last
Expand Down