How to get DID from SIP header


To get DID from SIP header just add in /etc/asterisk/extensions_custom.conf new context:

;Get did from SIP Header
[custom-get-did-from-sip]
exten => _.,1,Noop(Fixing DID using information from SIP TO header)
exten => _.,n,Set(pseudodid=${SIP_HEADER(To)})
exten => _.,n,Set(pseudodid=${CUT(pseudodid,@,1)})
exten => _.,n,Set(pseudodid=${CUT(pseudodid,:,2)})
exten => _.,n,Goto(from-trunk,${pseudodid},1)

After that just add in sip trunk peer details your new context

context=custom-get-did-from-sip

And reload asterisk. fwconsole reload or amportal reload