[asterisk-users] Dial out based on SIP invite
kjcsb
kjcsb at orcon.net.nz
Thu Aug 17 03:24:23 MST 2006
Assume that I receive an Invite from a SIP device that Asterisk has
registered with. How do I get Asterisk to dial out using the Invite details
as if the Invite had been received from a UA registered with Asterisk? i.e.
UA -> SIP Proxy -> Asterisk -> PSTN gateway.
For example
INVITE sip:95556789 at 60.234.xxx.xxx SIP/2.0
Record-Route: <sip:147.202.nn.nnn;ftag=bf7eced18eb7271b;lr=on>
Via: SIP/2.0/UDP 147.202.nn.nnn;branch=z9hG4bKe49c.21b320a3.0
Via: SIP/2.0/UDP 60.234.nnn.nnn;branch=z9hG4bK76bf3dec8d45b972
From: "User" <sip:1122334455 at proxy.domain.com>;tag=bf7eced18eb7271b
To: <sip:5556789 at domain.com>
etc
If the Invite was received from a SIP device registered with Asterisk (in
the [from-internal] context) then the call would be routed to
[outrt-003-test] and dial out correctly.
I want to do the same thing with the Invite received from the SIP proxy. Can
anyone advise how I can achieve this (in Asterisk 1.2.9)? Cut-down versions
of conf files are below.
sip.conf
register=1122334455:password at domain.com/66554433
[1122334455]
type=peer
host=proxy.domain.com
fromuser=1122334455
context=from-internal
extensions.conf
[from-internal]
include => from-internal-additional
exten => s,1,Macro(hangupcall)
exten => h,1,Macro(hangupcall)
exten => 66554433, 1, ?????????
[from-internal-additional]
include => outbound-allroutes
[outbound-allroutes]
include => outrt-003-test
exten => foo,1,Noop(bar)
[outrt-003-test]
exten => _90[2-79]XXXXXX.,1,Macro(dialout-trunk,1,${EXTEN:1},,)
exten => _90[2-79]XXXXXX.,n,Macro(dialout-trunk,5,${EXTEN:1},,)
exten => _90[2-79]XXXXXX.,n,Macro(dialout-trunk,3,${EXTEN:1},,)
exten => _90[2-79]XXXXXX.,n,Macro(dialout-trunk,2,${EXTEN:1},,)
exten => _90[2-79]XXXXXX.,n,Macro(outisbusy,)
[macro-dialout-trunk]
exten => s,1,GotoIf($["${ARG3}" = ""]?3:2) ; arg3 is pattern password
exten => s,2,Authenticate(${ARG3})
exten => s,3,Macro(user-callerid)
exten => s,4,Macro(record-enable,${CALLERID(number)},OUT)
exten => s,5,Macro(outbound-callerid,${ARG1})
exten => s,6,Set(GROUP()=OUT_${ARG1})
exten => s,7,GotoIf($[ ${GROUP_COUNT()} > ${OUTMAXCHANS_${ARG1}} ]?108)
; if we've used up the max channels, continue at (n+101)
exten => s,8,Set(DIAL_NUMBER=${ARG2})
exten => s,9,Set(DIAL_TRUNK=${ARG1})
exten => s,10,AGI(fixlocalprefix) ; this sets DIAL_NUMBER to the proper dial
string for this trunk
exten => s,11,Set(OUTNUM=${OUTPREFIX_${ARG1}}${DIAL_NUMBER}) ; OUTNUM is
the final dial number
exten => s,12,Set(custom=${CUT(OUT_${ARG1},:,1)}) ; Custom trunks are
prefixed with "AMP:"
exten => s,13,GotoIf($["${custom}" = "AMP"]?16)
exten => s,14,Dial(${OUT_${ARG1}}/${OUTNUM},120,${TRUNK_OPTIONS}) ; Regular
Trunk Dial
exten => s,15,Goto(s-${DIALSTATUS},1)
; This is a custom trunk. Substitute $OUTNUM$ with the actual number and
rebuild the dialstring
; example trunks: "AMP:CAPI/XXXXXXXX:b$OUTNUM$,30,r",
"AMP:OH323/$OUTNUM$@XX.XX.XX.XX:XXXX"
exten => s,16,Set(pre_num=${CUT(OUT_${ARG1},$,1)})
exten => s,17,Set(the_num=${CUT(OUT_${ARG1},$,2)}) ; this is where we
expect to find string OUTNUM
exten => s,18,Set(post_num=${CUT(OUT_${ARG1},$,3)})
exten => s,19,GotoIf($["${the_num}" = "OUTNUM"]?20:21) ; if we didn't find
"OUTNUM", then skip to Dial
exten => s,20,Set(the_num=${OUTNUM}) ; replace "OUTNUM" with the actual
number to dial
exten => s,21,Dial(${pre_num:4}${the_num}${post_num},120,${TRUNK_OPTIONS})
exten => s,22,Goto(s-${DIALSTATUS},1)
exten => s,108,Noop(max channels used up)
exten => s-BUSY,1,NoOp(Trunk is reporting BUSY)
exten => s-BUSY,2,Busy()
exten => s-BUSY,3,Wait(60)
exten => s-BUSY,4,NoOp()
exten => _s-.,1,NoOp(Dial failed due to ${DIALSTATUS})
Please note that Asterisk also receives Invites from the same proxy (same IP
and port) that need to be treated differently i.e. as if they were external
incoming calls. If this were not the case then the following sip.conf
achieves the desired result (I've tested this successfully). The call gets
into the from-internal context and the outbound call to the PSTN is made:
sip.conf
register=1122334455:password at domain.com
[1122334455]
type=peer
context=from-internal
However when I create another SIP peer, even though the Invite from the
Proxy has different From details, and I specify fromuser and host in
sip.conf under [1122334455], the call is treated as an external call.
Any advice appreciated.
Cameron
More information about the asterisk-users
mailing list