drenda
drenda

Reputation: 6254

Asterisk 11.7 Matching on Caller ID

I've an asterisk pbx that manages some sip providers (a ISDN Patton) and some Voip providers. I'm trying to use matching of CID in my dialplan as described here. This is the relevant part of my dialplan, please note that this part of dialplan is included my extension.conf:

[patton];Calls from Patton
exten => 0219999999/_0031X.,1,Answer(0)  
exten => 0219999999/_0031X.,n,Hangout()

exten => 0219999999,1,Answer(0)   
exten => 0219999999,n,Goto(in_4,${EXTEN},1)

[in_4]
exten => 0219999999,1,Noop(Exten: ${EXTEN})
exten => 0219999999,n,Noop(CID: ${CALLERID(NUM)})

In short I want do something different when the CID of the caller cames from Netherlands. Watching what happens in Asterisk CLI I see:

 == Using SIP RTP CoS mark 5
-- Executing [0219999999@patton:1] Answer("SIP/patton-00000011", "0") in new stack
-- Executing [0219999999@patton:2] Goto("SIP/patton-00000011", "in_4,0219999999,1") in new stack
-- Goto (in_4,0219999999,1)
-- Executing [0219999999@in_4:1] NoOp("SIP/patton-00000011", "Exten: 0219999999") in new stack
-- Executing [0219999999@in_4:2] NoOp("SIP/patton-00000011", "Cid: 0031123456789") in new stack

So what I understand is that Asterisk don't apply the CID matching but I don't understand why, considering that if I print the CID it matches perfectly my expression.

Upvotes: 0

Views: 4761

Answers (2)

user3788685
user3788685

Reputation: 3113

Here is a section of my extensions.conf file that deals with inbound caller ID matching (from a PSTN line)

There might be another/better way to do this, but its been a working config for me since 1.4 and I'm now running 13.7 without any issues. (Individual numbers have been replaced with '#') - This is a simple dial plan.

This is used to catch anyone who send an 084 or 087 prefix, a couple of specific numbers and anything from 'international' or lazy system administrators 'UNAVAILABLE'

I've the same thing set up for SIP trunks as well so this should work across any channel type.

[from-pstn]
exten => s,1,Verbose(CLID From BT ${CALLERID(all)})
exten => s,2,GotoIf($[${CALLERID(num):0:3} = 087]?103:3)
exten => s,3,GotoIf($[${CALLERID(num):0:3} = 084]?103:4)
exten => s,4,GotoIf($[${CALLERID(num):0:11} = 07896######]?103:5)
exten => s,5,GotoIf($[${CALLERID(num):0:11} = 01494######]?103:6)
exten => s,6,GotoIf($["${CALLERID(name):0:13}" = "INTERNATIONAL"]?103:7)
exten => s,7,GotoIf($["${CALLERID(name):0:11}" = "UNAVAILABLE"]?103:8)
exten => s,8,GotoIf($[${CALLERID(num):0:10} = 020315####]?103:9)
exten => s,103,Answer
exten => s,104,Wait(1)
exten => s,105,Playtones(info)
exten => s,106,Wait(7)
exten => s,107,Hangup
exten => s,9,Goto(internal-ext,5800,1)

You would want something like;

[from-yourtrunk]
exten => s,1,Verbose(CLID From <yourtrunk> ${CALLERID(all)})
exten => s,2,GotoIf($[${CALLERID(num):0:4} = 0031]?103:3)
exten => s,103,<do something with the call that matches the CLI>
exten => s,3,Goto(<your-internal-ext>,<number>,1)

Something to keep in mind - if you handle inbound caller ID that could start 0031 but its not a call from .nl then you would need to apply some additional patten matching to the 2nd line to enforce a minimum number of digits (for example) otherwise that will match any call that comes in with a CLI of 0031...............................

If you need any more explanation, or I've got the wrong end of the stick just add a comment to this answer.

Upvotes: 2

arheops
arheops

Reputation: 15259

There can be non zero probability, that cid is go in other format(use Verbose or Noop command to show real cid)

Also in this case any dialplan can work if cid match

Asterisk not select "most matching" dialplan. Insead it select FIRST matching dialplan.

You can use different contexts and include directive to control matching. See examples in extensions.conf.sample

    -- Executing [19@test:1] Answer("SIP/test2-0000821a", "") in new stack
    -- Executing [19@test:2] Set("SIP/test2-0000821a", "CALLERID(num)=0031123456789") in new stack
    -- Executing [19@test:3] Goto("SIP/test2-0000821a", "patton,0219999999,1") in new stack
    -- Goto (patton,0219999999,1)
    -- Executing [0219999999@patton:1] Answer("SIP/test2-0000821a", "0") in new stack
[Feb 10 08:26:09] WARNING[15817][C-00008bfe]: pbx.c:4869 pbx_extension_helper: No application 'Hangout' for extension (patton, 0219999999, 2)
  == Spawn extension (patton, 0219999999, 2) exited non-zero on 'SIP/test2-0000821a'
[Feb 10 08:26:45] NOTICE[1499]: chan_sip.c:28210 handle_request_register: Registration from '"407" <sip:[email protected]:5060>' failed for '221.144.172.3:5083' - Wrong password
pro-sip*CLI> dialplan show pa
park-dial            park-hints           park-orphan-routing  park-return-routing  parkedcalls          parkedcallstimeout   
patton               
pro-sip*CLI> dialplan show patton 
[ Context 'patton' created by 'pbx_config' ]
  '0219999999' (CID match '_0031X.') =>  1. Answer(0)                                  [pbx_config]
                    2. Hangout()                                  [pbx_config]
  '0219999999' =>   1. Answer(0)                                  [pbx_config]
                    2. Goto(in_4,${EXTEN},1)                      

[pbx_config] pro-sip*CLI> core show applications like  Hang
    -= Matching Asterisk Applications =-
         ChangeMonitor: Change monitoring filename of a channel. 
                Hangup: Hang up the calling channel. 
      HangupCauseClear: Clears hangup cause information from the channel that is available through HANGUPCAUSE. 
            SoftHangup: Hangs up the requested channel. 
    -= 4 Applications Matching =- pro-sip*CLI>

Addon2(please note, debug is OFFTOPIC on SO)

    -- Executing [0219999999@patton:1] NoOp("SIP/test2-0000821c", "cid match") in new stack
    -- Executing [0219999999@patton:2] Answer("SIP/test2-0000821c", "0") in new stack
[Feb 10 08:32:18] WARNING[15826][C-00008c00]: pbx.c:4869 pbx_extension_helper: No application 'Hangout' for extension (patton, 0219999999, 3)
  == Spawn extension (patton, 0219999999, 3) exited non-zero on 'SIP/test2-0000821c'
pro-sip*CLI> dialplan show pa
park-dial            park-hints           park-orphan-routing  park-return-routing  parkedcalls          parkedcallstimeout   
patton               
pro-sip*CLI> dialplan show patton 
[ Context 'patton' created by 'pbx_config' ]
  '0219999999' (CID match '_0031X.') =>  1. Noop(cid match)                            [pbx_config]
                    2. Answer(0)                                  [pbx_config]
                    3. Hangout()                                  [pbx_config]
  '0219999999' =>   1. NOOP(CIDNOTMATCH)                          [pbx_config]
                    2. Answer(0)                                  [pbx_config]
                    3. Goto(in_4,${EXTEN},1)                      [pbx_config]

Upvotes: 0

Related Questions