Skip to content

Commit

Permalink
[BUGFIX] Support all response codes from UniMRCP
Browse files Browse the repository at this point in the history
Maps all MRCP specified codes to Rayo
  • Loading branch information
Jared Davis authored and benlangfeld committed Oct 1, 2014
1 parent 320c1e8 commit c26a249
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 22 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# [develop](https://github.com/adhearsion/punchblock)
* Feature: Support recognition-timeout settings on UniMRCP-based ASR on Asterisk
* Feature: Implement redirect command on Asterisk
* Bugfix: Complete 1-to-1 mapping of UniMRCP RECOG_COMPLETION_CAUSE values to Punchblock::Complete events

# [v2.5.3](https://github.com/adhearsion/punchblock/compare/v2.5.2...v2.5.3) - [2014-09-22](https://rubygems.org/gems/punchblock/versions/2.5.3)
* Bugfix: Prevent Asterisk translator death due to dead DTMF recognizers ([#221](https://github.com/adhearsion/punchblock/pull/221), [adhearsion/adhearsion#479](https://github.com/adhearsion/adhearsion/issues/479))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,15 @@ def complete
raise UniMRCPError
else
send_complete_event case @call.channel_var('RECOG_COMPLETION_CAUSE')
when '000'
when '000', '008', '012'
nlsml = RubySpeech.parse URI.decode(@call.channel_var('RECOG_RESULT'))
Punchblock::Component::Input::Complete::Match.new nlsml: nlsml
when '001'
when '001', '003', '013', '014', '015'
Punchblock::Component::Input::Complete::NoMatch.new
when '002'
when '002', '011'
Punchblock::Component::Input::Complete::NoInput.new
when '004', '005', '006', '007', '009', '010', '016'
raise UniMRCPError
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def expect_app_with_options(app, options)
end

context "when MRCPRecog completes" do
context "with a match" do
shared_context "with a match" do
let :expected_nlsml do
RubySpeech::NLSML.draw do
interpretation grammar: 'session:grammar-0', confidence: 0.43 do
Expand All @@ -201,39 +201,69 @@ def expect_app_with_options(app, options)
end
end

context "with a nomatch cause" do
let(:recog_completion_cause) { '001' }
context "with a match cause" do
%w{000 008 012}.each do |code|
context "when the MRCP recognition response code is #{code}" do
let(:recog_completion_cause) { code }

it 'should send a nomatch complete event' do
expected_complete_reason = Punchblock::Component::Input::Complete::NoMatch.new
expect(mock_call).to receive(:execute_agi_command).and_return code: 200, result: 1
subject.execute
expect(original_command.complete_event(0.1).reason).to eq(expected_complete_reason)
it_behaves_like 'with a match'
end
end
end

context "with a noinput cause" do
let(:recog_completion_cause) { '002' }

it 'should send a nomatch complete event' do
expected_complete_reason = Punchblock::Component::Input::Complete::NoInput.new
expect(mock_call).to receive(:execute_agi_command).and_return code: 200, result: 1
subject.execute
expect(original_command.complete_event(0.1).reason).to eq(expected_complete_reason)
context "with a nomatch cause" do
%w{001 003 013 014 015}.each do |code|
context "with value #{code}" do
let(:recog_completion_cause) { code }

it 'should send a nomatch complete event' do
expected_complete_reason = Punchblock::Component::Input::Complete::NoMatch.new
expect(mock_call).to receive(:execute_agi_command).and_return code: 200, result: 1
subject.execute
expect(original_command.complete_event(0.1).reason).to eq(expected_complete_reason)
end
end
end
end

context "when the RECOG_STATUS variable is set to 'ERROR'" do
let(:recog_status) { 'ERROR' }
context "with a noinput cause" do
%w{002 011}.each do |code|
context "with value #{code}" do
let(:recog_completion_cause) { code }

specify do
expected_complete_reason = Punchblock::Component::Input::Complete::NoInput.new
expect(mock_call).to receive(:execute_agi_command).and_return code: 200, result: 1
subject.execute
expect(original_command.complete_event(0.1).reason).to eq(expected_complete_reason)
end
end
end
end

it "should send an error complete event" do
shared_context 'should send an error complete event' do
specify do
expect(mock_call).to receive(:execute_agi_command).and_return code: 200, result: 1
subject.execute
complete_reason = original_command.complete_event(0.1).reason
expect(complete_reason).to be_a Punchblock::Event::Complete::Error
expect(complete_reason.details).to eq("Terminated due to UniMRCP error")
end
end

context 'with an error cause' do
%w{004 005 006 007 009 010 016}.each do |code|
context "when the MRCP recognition response code is #{code}" do
let(:recog_completion_cause) { code }
it_behaves_like 'should send an error complete event'
end
end
end

context "when the RECOG_STATUS variable is set to 'ERROR'" do
let(:recog_status) { 'ERROR' }
it_behaves_like 'should send an error complete event'
end
end

context "when we get a RubyAMI Error" do
Expand Down

0 comments on commit c26a249

Please sign in to comment.