Skip to content

Commit

Permalink
can now configure the "no input" message to be played on last input a…
Browse files Browse the repository at this point in the history
…ttempt
  • Loading branch information
marcelog committed Apr 3, 2012
1 parent 43da0f5 commit 51b633c
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/mg/PAGI/Node/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,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
*
Expand Down Expand Up @@ -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.
*
Expand All @@ -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.
Expand Down Expand Up @@ -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;
Expand Down
28 changes: 28 additions & 0 deletions test/node/Test_Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit 51b633c

Please sign in to comment.