Here is my situation. I have one SIP account (which allows as many concurrent calls as I can handle on my internet connection) going to an asterisk server. I have 12 local extensions called ext2001, ext2002, etc… Each incoming call I wish to have ringing on one and only one of those extensions. If the call is not answered, then it goes to voicemail. This is working well, as I have done this using the following code:
; Return a Busy immediately if the next line is left in
exten => 1000,1,Set(CallerIDString=${CALLERID(all)})
exten => 1000,n,Set(GROUP(${EXTEN})=incoming)
exten => 1000,n,noop( ${GROUP_COUNT(incoming@${EXTEN})} )
;If too many calls, then go to busy
;exten => 1000,n,Set(foo=${CURL(http://www.pblq.com/)})
exten => 1000,n,AGI(logcall.py)
exten => 1000,n,noop
exten => 1000,n,GotoIf($[${GROUP_COUNT(incoming@${EXTEN})} > 10 ]?333)
;
; Dial First Extension
exten => 1000,n,Set(C1State=${CHANNEL(state)})
exten => 1000,n,Dial(SIP/ext2001,20,R)
; If congestion or unavailable, then go to Next line, otherwise go to voicemail immediately
exten => 1000,n,GotoIf($["${DIALSTATUS}" = "CHANUNAVAIL"]?TryTwo)
exten => 1000,n,GotoIf($["${DIALSTATUS}" = "CONGESTION"]?TryTwo)
exten => 1000,n,GotoIf($["${DIALSTATUS}" = "BUSY"]?TryTwo)
; Go To Voice mail because it was not answered
exten => 1000,n,Goto(DoVoiceMail)
;
; Try Second Extension
exten => 1000,n(TryTwo),noop
exten => 1000,n,Set(C2State=${CHANNEL(state)})
exten => 1000,n,Dial(SIP/ext2002,20,R)
; If congestion or unavailable, then go to Next line, otherwise go to voicemail immediately
exten => 1000,n,GotoIf($["${DIALSTATUS}" = "CHANUNAVAIL"]?TryThree)
exten => 1000,n,GotoIf($["${DIALSTATUS}" = "CONGESTION"]?TryThree)
exten => 1000,n,GotoIf($["${DIALSTATUS}" = "BUSY"]?TryThree)
; Go To Voice mail because it was not answered
exten => 1000,n,Goto(DoVoiceMail)
;
;Try Third Extension
exten => 1000,n(TryThree),noop
exten => 1000,n,Set(C3State=${CHANNEL(state)})
exten => 1000,n,Dial(SIP/ext2003,15,R)
; If congestion or unavailable, then go to Next line, otherwise go to voicemail immediately
exten => 1000,n,GotoIf($["${DIALSTATUS}" = "CHANUNAVAIL"]?TryFour)
exten => 1000,n,GotoIf($["${DIALSTATUS}" = "CONGESTION"]?TryFour)
exten => 1000,n,GotoIf($["${DIALSTATUS}" = "BUSY"]?TryFour)
; Go To Voice mail because it was not answered
exten => 1000,n,Goto(DoVoiceMail)
;
;Try Fourth Extension
exten => 1000,n(TryFour),noop
exten => 1000,n,Set(C4State=${CHANNEL(state)})
exten => 1000,n,Dial(SIP/ext2004,15,R)
; If congestion or unavailable, then go to NextLine otherwise go to voicemail immediately
exten => 1000,n,GotoIf($["${DIALSTATUS}" = "CHANUNAVAIL"]?TryFive)
exten => 1000,n,GotoIf($["${DIALSTATUS}" = "CONGESTION"]?TryFive)
exten => 1000,n,GotoIf($["${DIALSTATUS}" = "BUSY"]?TryFive)
; Go To Voice mail because it was not answered
exten => 1000,n,Goto(DoVoiceMail)
;
;
exten => 1000,n(TryFive), Goto(DoVoiceMail)
; Fall Through to Voice Mail Anyways
exten => 1000,n(DoVoiceMail),Answer()
exten => 1000,n,Wait(1)
exten => 1000,n,Voicemail(1001,u)
exten => 1000,n,Hangup()
exten => 1000,333,Busy()
include => extensions
This works exactly as I want since each call rings for a short period of time on one SIP port, then goes to voice mail.
My question though is how can I get the caller ID information to be delivered to some other server (preferably via an HTTP call or something like that) when the call is actually ringing on a specific port. My issue is that the DIAL() command does not return unless the channel is busy or no answer. I need to have the caller ID information on the external system while the call is ringing, not after it gets picked up.
I thought about writing some sort of timeout system on the remote system so that the asterisk system sends the caller ID information to the remote before calling the DIAL() command, and then if the remote system gets nothing for a second or so, it actually uses that data. OTOH if the DIAL() command returns immediately with a “BUSY” or “UNAVAIL” then I send a sort of “forget about it” message to the remote system and it does not use the data given previously.
I tried calling the DIAL() command with a timeout of zero to see if the local extension was available, but that does not work.
So the real questions is how can I determine if an incoming call is ringing on a SIP port so I can send the callerID information to an external system for processing?
Any ideas please would be very helpful!!!
Thank you very much.
Reed