Skip to content

Commit

Permalink
Allow re-enabling barge-in for all prompts
Browse files Browse the repository at this point in the history
  • Loading branch information
benlangfeld committed May 1, 2015
1 parent 863b5c5 commit 7611beb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
10 changes: 9 additions & 1 deletion lib/adhearsion-ivr/ivr_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ def prompts
@prompts ||= []
end

def barge(val = nil)
if val.nil?
@barge || false
else
@barge = val
end
end

# maximum number of attempts to prompt the caller for input
def max_attempts(num = nil)
if num
Expand Down Expand Up @@ -122,7 +130,7 @@ def run
deliver_prompt true
end

def deliver_prompt(interruptible = false)
def deliver_prompt(interruptible = self.class.barge)
prompt = prompts[@errors] || prompts.last
prompt = instance_exec(&prompt) if prompt.respond_to? :call
logger.debug "Prompt: #{prompt.inspect}"
Expand Down
29 changes: 24 additions & 5 deletions spec/adhearsion-ivr/ivr_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@
let(:controller_class) do
expected_prompts = self.expected_prompts
apology_announcement = self.apology_announcement
barge_in = self.barge_in

Class.new(Adhearsion::IVRController) do
expected_prompts.each do |prompt|
prompts << prompt
end

barge barge_in

on_complete do |result|
say "Let's go to #{result.utterance}"
end
Expand Down Expand Up @@ -46,6 +49,7 @@ def grammar

let(:expected_prompts) { [SecureRandom.uuid, SecureRandom.uuid, SecureRandom.uuid] }
let(:apology_announcement) { "Sorry, I couldn't understand where you would like to go. I'll put you through to a human." }
let(:barge_in) { nil }

let(:expected_grammar) { :some_grammar }

Expand Down Expand Up @@ -93,13 +97,28 @@ def grammar
let(:result) { noinput_result }

context 'followed by a match' do
before do
controller.should_receive(:ask).once.with(expected_prompts[1], grammar: expected_grammar, mode: :voice, interruptible: false).and_return match_result
context 'with default barge behaviour' do
before do
controller.should_receive(:ask).once.with(expected_prompts[1], grammar: expected_grammar, mode: :voice, interruptible: false).and_return match_result
end

it 're-prompts using the next prompt, and then passes the second Result to the on_complete block' do
controller.should_receive(:say).once.with "Let's go to Paris"
controller.run
end
end

it 're-prompts using the next prompt, and then passes the second Result to the on_complete block' do
controller.should_receive(:say).once.with "Let's go to Paris"
controller.run
context 'with barge-in enabled' do
let(:barge_in) { true }

before do
controller.should_receive(:ask).once.with(expected_prompts[1], grammar: expected_grammar, mode: :voice, interruptible: true).and_return match_result
end

it 're-prompts using the next prompt, and then passes the second Result to the on_complete block' do
controller.should_receive(:say).once.with "Let's go to Paris"
controller.run
end
end
end

Expand Down

0 comments on commit 7611beb

Please sign in to comment.