Skip to content

Commit

Permalink
AgiCommand support for AsyncAGIExec
Browse files Browse the repository at this point in the history
  • Loading branch information
lpradovera committed May 27, 2015
1 parent bf53599 commit 2b99249
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def execute
end

def handle_ami_event(event)
if event.name == 'AsyncAGI' && event['SubEvent'] == 'Exec'
if (event.name == 'AsyncAGI' && event['SubEvent'] == 'Exec') || event.name == 'AsyncAGIExec'
send_complete_event success_reason(event)
if @component_node.name == 'ASYNCAGI BREAK' && @call.channel_var('PUNCHBLOCK_END_ON_ASYNCAGI_BREAK')
@call.handle_hangup_event nil, event.best_time
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,21 @@ module Asterisk
"Result" => ami_event_result
end

let(:ami_event_ast13) do
RubyAMI::Event.new 'AsyncAGIExec',
"Channel" => channel,
"CommandId" => component_id,
"Command" => "EXEC ANSWER",
"Result" => ami_event_result
end

let :expected_complete_reason do
Punchblock::Component::Asterisk::AGI::Command::Complete::Success.new :code => 200,
:result => 123,
:data => 'timeout'
end

it 'should send a complete event' do
def should_send_complete_event
subject.handle_ami_event ami_event

complete_event = original_command.complete_event 0.5
Expand All @@ -139,14 +147,27 @@ module Asterisk
expect(complete_event.reason).to eq(expected_complete_reason)
end

it 'should send a complete event' do
should_send_complete_event
end

context 'with an AsyncAGIExec event' do
let(:ami_event) { ami_event_ast13 }

it 'should send a complete event' do
should_send_complete_event
end
end

context 'when the result contains illegal characters in the AGI response' do
let (:ami_event_result) { '$' }
let :expected_complete_reason do
Punchblock::Component::Asterisk::AGI::Command::Complete::Success.new :code => -1,
:result => nil,
:data => nil
end
it 'treats it as a failure with code -1' do

def treat_as_failure
subject.handle_ami_event ami_event

complete_event = original_command.complete_event 0.5
Expand All @@ -156,6 +177,18 @@ module Asterisk
expect(complete_event.component_id).to eq(component_id.to_s)
expect(complete_event.reason).to eq(expected_complete_reason)
end

it 'treats it as a failure with code -1' do
treat_as_failure
end

context 'with an AsyncAGIExec event' do
let(:ami_event) { ami_event_ast13 }

it 'treats it as a failure with code -1' do
treat_as_failure
end
end
end

context "when the command was ASYNCAGI BREAK" do
Expand Down
2 changes: 1 addition & 1 deletion spec/punchblock/translator/asterisk_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ module Translator

context 'with an Asterisk 13 AsyncAGIStart event' do
let :ami_event do
RubyAMI::Event.new 'AsyncAGIStart',
RubyAMI::Event.new 'AsyncAGIStart',
'Channel' => "SIP/1234-00000000",
'Env' => "agi_request%3A%20async%0Aagi_channel%3A%20SIP%2F1234-00000000%0Aagi_language%3A%20en%0Aagi_type%3A%20SIP%0Aagi_uniqueid%3A%201320835995.0%0Aagi_version%3A%201.8.4.1%0Aagi_callerid%3A%205678%0Aagi_calleridname%3A%20Jane%20Smith%0Aagi_callingpres%3A%200%0Aagi_callingani2%3A%200%0Aagi_callington%3A%200%0Aagi_callingtns%3A%200%0Aagi_dnid%3A%201000%0Aagi_rdnis%3A%20unknown%0Aagi_context%3A%20default%0Aagi_extension%3A%201000%0Aagi_priority%3A%201%0Aagi_enhanced%3A%200.0%0Aagi_accountcode%3A%20%0Aagi_threadid%3A%204366221312%0A%0A"
end
Expand Down

0 comments on commit 2b99249

Please sign in to comment.