Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

can now configure the "no input" message to be played on last input a…

…ttempt
  • Loading branch information...
commit 51b633cba95b736f829937d0f4659983e4736339 1 parent 43da0f5
@marcelog authored
Showing with 49 additions and 4 deletions.
  1. +21 −4 src/mg/PAGI/Node/Node.php
  2. +28 −0 test/node/Test_Node.php
View
25 src/mg/PAGI/Node/Node.php
@@ -339,6 +339,12 @@ class Node
private $_executeAfterFailedValidation = null;
/**
+ * Play "no input" message in last attempt too.
+ * @var boolean
+ */
+ private $_playOnNoInputInLastAttempt = false;
+
+ /**
* Make pre prompt messages not interruptable
*
* @return Node
@@ -376,8 +382,8 @@ public function unInterruptablePrompts()
/**
* Specify an optional message to play when the user did not enter any
- * input at all. Will NOT be played if this happens in the last allowed
- * attempt.
+ * input at all. By default, will NOT be played if this happens in the last
+ * allowed attempt.
*
* @param string $filename Sound file to play.
*
@@ -389,6 +395,17 @@ public function playOnNoInput($filename)
return $this;
}
+ /**
+ * Forces to play "no input" message on last attempt too.
+ *
+ * @return Node
+ */
+ public function playNoInputMessageOnLastAttempt()
+ {
+ $this->_playOnNoInputInLastAttempt = true;
+ return $this;
+ }
+
/**
* Optional message to play when the user exhausted all the available
* attempts to enter a valid input.
@@ -1218,11 +1235,11 @@ public function run()
$this->logDebug("Cancelled node, quitting");
break;
}
- // dont play on last attempt
+ // dont play on last attempt by default
if (
$this->_onNoInputMessage !== null
&& !$this->hasInput()
- && $attempts != ($this->_totalAttemptsForInput - 1)
+ && ($this->_playOnNoInputInLastAttempt || $attempts != ($this->_totalAttemptsForInput - 1))
) {
$this->addPrePromptMessage($this->_onNoInputMessage);
continue;
View
28 test/node/Test_Node.php
@@ -584,6 +584,34 @@ public function can_play_on_no_input()
$this->assertEquals($node->getTotalInputAttemptsUsed(), 2);
}
+ /**
+ * @test
+ */
+ public function can_play_on_no_input_on_last_attempt()
+ {
+ $node = $this->createNode();
+ $node->getClient()
+ ->onStreamFile(false)
+ ->onStreamFile(false)
+ ->onStreamFile(false)
+ ->onStreamFile(false)
+ ->assert('streamFile', array('you-have', Node::DTMF_ANY))
+ ->assert('streamFile', array('try-again', Node::DTMF_ANY))
+ ->assert('streamFile', array('you-have', Node::DTMF_ANY))
+ ->assert('streamFile', array('try-again', Node::DTMF_ANY))
+ ;
+ $node
+ ->maxAttemptsForInput(2)
+ ->playOnNoInput('try-again')
+ ->saySound('you-have')
+ ->playNoInputMessageOnLastAttempt()
+ ->run()
+ ;
+ $this->assertTrue($node->isComplete());
+ $this->assertEquals($node->getInput(), '');
+ $this->assertFalse($node->hasInput());
+ $this->assertEquals($node->getTotalInputAttemptsUsed(), 2);
+ }
/**
* @test
*/
Please sign in to comment.
Something went wrong with that request. Please try again.