I’ve got ertw.com set up to accept SIP calls, so that if you dial sean@ this domain, it rings a phone here. But, how do you dial out?
It’s actually quite easy in theory, since you can Dial() any sort of address, but the trick is to integrate it with the dialplan.
A bit of research found this page which is good, but it assumes that everything gets forwarded to the SIP macro. Using part of his recipe:
exten => _[a-z].,1,Macro(uridial,${EXTEN}@${SIPDOMAIN})
exten => _[A-Z].,1,Macro(uridial,${EXTEN}@${SIPDOMAIN})
means that only those addresses that start with a letter will be dialed as SIP, which rules out numeric addresses (like 613@fwd.pulver.com for echo testing).
I like his idea, though, so I decided that I’d keep it, and prefix any numeric sip addresses with sip: so that the extension above would be caught. Then it was a matter of modifying his macro to look for sip: in front of a URI and strip it. The results are:
; Dials a SIP URI
[macro-uridial]
; First, assume it’s not a sip: type address
exten => s,1,Set(destination=${ARG1})
exten => s,n,NoOp(First 6 chars are ${ARG1:0:6})
; We see them as url encoded (ie : is really %3a)
; check to see if the first *six* chars match it then
exten => s,n,GotoIf($[“${ARG1:0:6}” != “sip%3a”]?nowdial|1)
; we fell through because there was a sip: at the beginning, so
; strip the digits and then dial
exten => s,n,Set(destination=${ARG1:6})
exten => s,n,GoTo(nowdial,1)
; At this point it’s a proper uri
exten => nowdial,1,NoOp(Calling remote SIP peer ${destination})
exten => nowdial,n,Dial(SIP/${destination},120,tr)
exten => nowdial,n,Congestion()
In the end it turned out to be an exercise in learning how Asterisk works more than anything else, ie the %3a translation, the implicit breaking up of the address into $EXTEN and $SIPDOMAIN, and also the format of GotoIf.