Caller ID match and route

Hello Team
Still a newbie I have Asterisk 11.20.0 using CLI
Am looking for a solution in extension.conf that can match incoming CALLER IDs numbers from USA ONLY starting with 1XXXXXXXXX to be routed and dialed to a voice gateway.

This is a sample of sip conversation
INVITE sip:254XXXXXXXXX@192.168.x.x SIP/2.0
Via: SIP/2.0/UDP 192.168.x.x;branch=z9hG4bKc0a8000b000002e556f1254300003bbe0000018c;rport
From: “1XXXXXXXXXX” sip:192.168.x.x;tag=2256e3b0cba
To: sip:254XXXXXXXXX@192.168.x.x
Contact: sip:192.168.x.x
Call-ID: AC9E1E006F9A44369CBE829D88BA2AC60xc0a8000b

Thanks in advance

exten => somepattern/_1XXXXXXXXX,1,DIAL(tech/trunk/NUMBER)

1 Like

Thanks Navaismo,
Am getting this error
[Mar 22 18:42:55] NOTICE[2826][C-00000001]: chan_sip.c:25844 handle_request_invite: Call from ‘’ (192.168.0.11:5060) to extension ‘254732453445’ rejected because extension not found in context ‘outgoing’.
Scheduling destruction of SIP dialog ‘70D41F91FE9E4C98B5A44DB25D3609B40xc0a8000b’ in 32000 ms (Method: INVITE)

This is my extensions.conf file
[general]
static=yes
writeprotect=no
clearglobalvars=no

[globals]
; Global variables goes here

[outgoing]
exten => 30,1,Wait(15)
exten => 30,n,Answer()
exten => 30,n,Background(/var/lib/asterisk/sounds/ivr_promt_user)
exten => 30,n,WaitExten(15,m)
exten => 30,n,Background(/var/lib/asterisk/sounds/ivr_promt_user)
exten => 30,n,WaitExten(15,m)
exten => 30,n,Background(/var/lib/asterisk/sounds/ivr_promt_user)
exten => 30,n,WaitExten(15,m)
exten => 30,n,Background(/var/lib/asterisk/sounds/ivr_promt_user)
exten => 30,n,WaitExten(15,m)
exten => 30,n,Background(/var/lib/asterisk/sounds/ivr_promt_user)
exten => 30,n,WaitExten(15,m)
exten => 1,1,DIAL(“SIP/1XXXXXXXXX@ringtones”)
exten => 1,2,Hangup()
exten => 2,1,DIAL(“SIP/1XXXXXXXXX@ringtones”)
exten => 2,2,Hangup()
exten => 3,1,DIAL(“SIP/1XXXXXXXXX@ringtones”)
exten => 3,2,Hangup()

exten => _254xxxxxxxxx/_1XXXXXXXXXX,1,Dial(SIP/${EXTEN}@sipprovider)
;exten => somepattern/_1XXXXXXXXX,1,DIAL(tech/trunk/NUMBER)

Thanks

You missed the undescore check this–> http://www.voip-info.org/wiki/view/Asterisk+config+extensions.conf
Search for ex-girlfriend

Also you can do it with a GotoIF and evaluating the CID

1 Like

Not working
exten => _254xxxxxxxxx/_1XXXXXXXXXX,1,Dial(SIP/${EXTEN}@sipprovider)
I now have the underscore
Still getting Error… Call from ‘’ (192.168.0.11:5060) to extension ‘254732453445’ rejected because extension not found in context ‘outgoing’

Again:

And really read the link carefully

Either the incoming INVITE is malformed, or the forum has corrupted the above. The From line should either have:

From: 1XXXXXXXXXX@somedomain ; tag.....

or

From: "some irrelevant text" <1XXXXXXXXXXX@somedomain>; tag.....

A name without an address is simply invalid.

For David551
INVITE sip:254732453445@192.168.0.2 SIP/2.0
Via: SIP/2.0/UDP 192.168.0.5:5060;branch=z9hG4bK48a0a0e7;rport
Max-Forwards: 70
From: “1123332222” sip:asterisk@192.168.0.5;tag=as4f3d847c
To: sip:254732453445@192.168.0.2
Contact: sip:asterisk@192.168.0.5:5060
Call-ID: 1f9883bf3cbdae2009f425ea52889fbd@192.168.0.5:5060
CSeq: 102 INVITE
User-Agent: Prefix
Date: Tue, 22 Mar 2016 23:53:06 GMT
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces
Content-Type: application/sdp
Content-Length: 291

For navaismo
I have counter checked it reads
exten => _254xxxxxxxxx/_1XXXXXXXXXX,1,Dial(SIP/${EXTEN}@SipProvider)
If the underscore is not showing just before 254 and 1 on the line then there must be something wrong

underscore not showing David is Right the forum has corrupted the original data that includes the underscore

From, To and Contact headers are all invalid. Did you use the </> button?

Thanks David551 let me re phrase it, we would like to allow Caller IDs from USA numbers starting with 1XXXXXXXXXX
This is what now have in the extension.conf
exten => _X.,1,GotoIf($[${CALLERID(all)} = 1]?reject:allow)
exten => _X.,n,(allow),Dial(SIP/${EXTEN}@sipprovider)
exten => _X.,n,Hungup
exten => _X.,n,(reject),Hungup
getting error
[Mar 23 14:07:25] WARNING[3848][C-00000005]: ast_expr2.fl:470 ast_yyerror: ast_yyerror(): syntax error: syntax error, unexpected ‘>’, expecting ‘-’ or ‘!’ or ‘(’ or ‘’; Input:
“12345678900” <> = 1

That indicates that your From headers are more compliant than the ones that appear on the forum, and they do contain angle bracketted address information.

${CALLERID(all)}, guessing as to what has gone wrong in your forum posting, is something like:

"12345678900" <12345678900@example.com>

which is not a valid expression because you can only have one comparison operator.

In any case, comparing even just the ${CALLERID(num)} to 1 won’t give a match for 11 digit numbers.