Manager API, call not answered but enter dialplan anyway?

I’m originating a call from the Asterisk Manager, and using DeadAGI when the call is hung up to update a database with the results of the call.

The result is ‘noack’ if the callee hung up, ‘ack’ if they pressed a number when propted, and ‘timeout’ if they forget to press anything.

This works.

However, I want a fourth result: ‘noans’ for when the call isn’t answered at all.

From what I can see, the dialplan isn’t even started if the phone isn’t answered, so of course it isn’t hungup, and my DeadAGI script isn’t called.

I’d rather not have to deal with this case in the Manager, as I then have database calls and code in seperate places.

Is there a simple solution to this I’ve missed? Or even a more complex answer?

can you use ${DIALSTATUS} handling in the context you start the call in ?

I should post my config.

Manager Actions:

[code]
Action: Login
Username: foo
Secret: bar

Action: Originate
Channel: IAX2/iaxuser@192.168.0.20
Context: test
Extension: s
Priority: 1
Timeout: 30000

Action: Logoff[/code]

Extensions.conf

[code]
[test]
exten => s,1,SetGlobalVar(STATUS=noack)
exten => s,2,Background(gaAck)
exten => s,3,WaitExten(10)

; press 2 to repeat
exten => 2,1,GoTo(s,1)

; press 3 to acknowledge
exten => 3,1,SetGlobalVar(STATUS=ack)
exten => 3,2,Playback(gaThanks)
exten => 3,3,Hangup

exten => t,1,SetGlobalVar(STATUS=timeout)
exten => t,2,Hangup

exten => i,1,Playback(invalid) ; "That’s not valid, try again"
exten => i,2,GoTo(s,1)

exten => h,1,DeadAGI,ack.php[/code]

baconbuttie: I don’t think the call even enters the context if the phone isn’t answered. If I’m wrong, can you elaborate?

I think I have half a solution.

Using the manager API I originate a call to an extension. That extension is then responsible for calling the desired number.

The problem is now inverted. If the call isn’t answered, all is fine; I get the expected ‘NOANSWER’ in the database.

If the call is answered, I get two entries. What’s happening seems to be that two calls are getting placed, and Asterisk is trying to bridge between them. When each call gets hung up, they both trigger the DeadAGI script.

What’s causing this, and how do I stop it?

The log of events recieved by the Manager client:

Asterisk Call Manager/1.0
Response: Success
Message: Authentication accepted
Response: Success             // I answer the phone
Message: Originate successfully queued
Event: Newchannel
Privilege: call,all
Channel: Local/15@test-d284,2
State: Ring
CallerID: <unknown>
CallerIDName: <unknown>
Uniqueid: 1175179682.13
Event: Newchannel
Privilege: call,all
Channel: Local/15@test-d284,1
State: Down
CallerID: <unknown>
CallerIDName: <unknown>
Uniqueid: 1175179682.12
Event: Newcallerid
Privilege: call,all
Channel: Local/15@test-d284,1
CallerID: <Unknown>
CallerIDName: <Unknown>
Uniqueid: 1175179682.12
CID-CallingPres: 0 (Presentation Allowed, Not Screened)
Event: Newexten
Privilege: call,all
Channel: Local/15@test-d284,2
Context: test
Extension: 15
Priority: 1
Application: Dial
AppData: IAX2/iaxuser@192.168.0.20|30
Uniqueid: 1175179682.13
Event: Newchannel
Privilege: call,all
Channel: IAX2/iaxuser-4
State: Down
CallerID: <unknown>
CallerIDName: <unknown>
Uniqueid: 1175179682.14
Event: Newchannel
Privilege: call,all
Channel: IAX2/iaxuser-4
State: Ringing
CallerID: <unknown>
CallerIDName: <unknown>
Uniqueid: 1175179682.14
Event: Dial
Privilege: call,all
Source: Local/15@test-d284,2
Destination: IAX2/iaxuser-4
CallerID: <unknown>
CallerIDName: <unknown>
SrcUniqueID: 1175179682.13
DestUniqueID: 1175179682.14
Event: Newcallerid
Privilege: call,all
Channel: IAX2/iaxuser-4
CallerID: 15
CallerIDName: <Unknown>
Uniqueid: 1175179682.14
CID-CallingPres: 0 (Presentation Allowed, Not Screened)
Event: Newstate
Privilege: call,all
Channel: IAX2/iaxuser-4
State: Up
CallerID: 15
CallerIDName: <unknown>
Uniqueid: 1175179682.14
Event: Newstate
Privilege: call,all
Channel: Local/15@test-d284,2
State: Up
CallerID: <unknown>
CallerIDName: <unknown>
Uniqueid: 1175179682.13
Event: Link
Privilege: call,all
Channel1: Local/15@test-d284,2
Channel2: IAX2/iaxuser-4
Uniqueid1: 1175179682.13
Uniqueid2: 1175179682.14
CallerID1: (null)
CallerID2: 15
Event: Newchannel
Privilege: call,all
Channel: Local/15@test-d284,1
State: Up
CallerID: <unknown>
CallerIDName: <unknown>
Uniqueid: 1175179682.12
Event: Newexten
Privilege: call,all
Channel: Local/15@test-d284,1
Context: test
Extension: s
Priority: 1
Application: SetGlobalVar
AppData: STATUS=noack
Uniqueid: 1175179682.12
Event: Newexten
Privilege: call,all
Channel: Local/15@test-d284,1
Context: test
Extension: s
Priority: 2
Application: BackGround
AppData: gaAck
Uniqueid: 1175179682.12
Event: Rename
Privilege: call,all
Oldname: IAX2/iaxuser-4
Newname: IAX2/iaxuser-4<MASQ>
Uniqueid: 1175179682.14
Event: Rename
Privilege: call,all
Oldname: Local/15@test-d284,1
Newname: IAX2/iaxuser-4
Uniqueid: 1175179682.12
Event: Rename
Privilege: call,all
Oldname: IAX2/iaxuser-4<MASQ>
Newname: Local/15@test-d284,1<ZOMBIE>
Uniqueid: 1175179682.14
Event: Unlink
Privilege: call,all
Channel1: Local/15@test-d284,2
Channel2: Local/15@test-d284,1<ZOMBIE>
Uniqueid1: 1175179682.13
Uniqueid2: 1175179682.14
CallerID1: (null)
CallerID2: (null)
Event: Hangup
Privilege: call,all
Channel: Local/15@test-d284,1<ZOMBIE>
Uniqueid: 1175179682.14
Cause: 16
Cause-txt: Normal Clearing
Event: Newexten
Privilege: call,all
Channel: Local/15@test-d284,2
Context: test
Extension: h
Priority: 1
Application: DeadAGI          // first call
AppData: ack.php
Uniqueid: 1175179682.13
Event: Hangup
Privilege: call,all
Channel: Local/15@test-d284,2
Uniqueid: 1175179682.13
Cause: 16
Cause-txt: Normal Clearing
Event: Newexten
Privilege: call,all
Channel: IAX2/iaxuser-4
Context: test
Extension: s
Priority: 3
Application: WaitExten          // dialplan waits for response
AppData: 10
Uniqueid: 1175179682.12
Event: Newexten                 // I press '3'
Privilege: call,all
Channel: IAX2/iaxuser-4
Context: test
Extension: 3
Priority: 1
Application: SetGlobalVar
AppData: STATUS=ack
Uniqueid: 1175179682.12
Event: Newexten
Privilege: call,all
Channel: IAX2/iaxuser-4
Context: test
Extension: 3
Priority: 2
Application: Playback
AppData: gaThanks
Uniqueid: 1175179682.12
Event: Newexten
Privilege: call,all
Channel: IAX2/iaxuser-4
Context: test
Extension: 3
Priority: 3
Application: Hangup
AppData:
Uniqueid: 1175179682.12
Event: Newexten
Privilege: call,all
Channel: IAX2/iaxuser-4
Context: test
Extension: h
Priority: 1
Application: DeadAGI        // second (correct) call
AppData: ack.php
Uniqueid: 1175179682.12
Event: Hangup
Privilege: call,all
Channel: IAX2/iaxuser-4
Uniqueid: 1175179682.12
Cause: 16
Cause-txt: Normal Clearing

Manager Actions:

[code]
Action: Login
Username: foo
Secret: bar

Action: Originate
Channel: local/15@test
Context: test
Extension: s
Priority: 1
Timeout: 30000

Action: Logoff[/code]

Extensions.conf

[test] 
exten => 15,1,Dial(IAX2/iaxuser@192.168.0.20,30)
exten => 15,2,SetGlobalVar(STATUS=${DIALSTATUS})

exten => s,1,SetGlobalVar(STATUS=noack) 
exten => s,2,Background(gaAck) 
exten => s,3,WaitExten(10) 

; press 2 to repeat 
exten => 2,1,GoTo(s,1) 

; press 3 to acknowledge 
exten => 3,1,SetGlobalVar(STATUS=ack) 
exten => 3,2,Playback(gaThanks) 
exten => 3,3,Hangup 

exten => t,1,SetGlobalVar(STATUS=timeout) 
exten => t,2,Hangup 

exten => i,1,Playback(invalid) ; "That's not valid, try again" 
exten => i,2,GoTo(s,1) 

exten => h,1,DeadAGI,ack.php

(192.168.0.20 is the ip of the machine that’s both originating and recieving the call. The Asterisx box is on 192.168.0.10)

can you add some filtering in your AGI so that it ignores the Local channel leg of the call ?

So it isn’t an error that it places the two calls?

I can easily add the filtering if that’s the best way to fix it.