Set CID question

About 150. I only have about 10 numbers I need to change CID name for.

Hmmm, this is not a practical approach then. I got you on the wrong track. Your first approach is the way to do it, what dialplan are you working with?

Excuse my greenness, but not sure what you mean. Running 'asterisk -x ‘dialplan show’ I think shows me the matrix, I chose the red pill. Are you asking about what my inbound routes look like?

I’m on mobile so can’t do anything much at the moment. You need a block of dialplan to preprocess the calls before the inbound route. I will give you an example over the weekend when time permits if someone doesn’t beat me to it.

Ok, cool. I appreciate the help. The only dial plan I deal with is on the Vega gateway. If there’s a particular file you need or command to run, let me know.

You need to create a context in extensions_custom.conf with an arbitrary name like this:

exten =>  _./1234567890,1,Set(CALLERID(name)=NewName1)    ; all inbound calls matching cid number 1234567890
exten =>  _./9876543210,1,Set(CALLERID(name)=NewName2)    ; all inbound calls matching cid number 9876543210
;  additional set lines as required
exten =>  _.,1,NoOp(Entering user defined context from-pstn-preprocess in extensions_custom.conf)          ; Catch all other cases
exten =>  _.,n,goto(from-pstn,${EXTEN},1))

Then edit your trunk(s) and set the context to from-pstn-preprocess. You can set as many priority 1 lines as you want for each different CID number.

Ah, it’s all becoming much clearer now :slight_smile:

Is my interpretation of this correct?

exten => _./1234567890,1,Set(CALLERID(name)=NewName1) ; all inbound calls matching cid number 1234567890

exten => number,priority,application([parameter[,parameter2…]])

“_” means this is a pattern
“.” one or more characters
“/” only match what is matched by preceding pattern “.” if Caller-ID Number matches “1234567890”

“1” Set priority to highest
“Set(CALLERID(name)=NewName1)” Set variable CALLERID(name) to NewName1

1 Like

The string that follows the => is called the extension in Asterisk. When talking about inbound calls the extension will be the DID optionally followed by the CID Number with the two separated by the /. So in the case above _./1234567890 means match calls with any DID AND with CID exactly matching 1234567890.

The value that follows the extension is the priority, which determines the order that the dialplan lines are executed. It always starts with priority 1. You can number the lines explicitly using 1,2,3 … etc. or after line 1 you can use the lower case n which means execute the lines in the order they are written.

What about the line:
; additional set lines as required
exten => _.,n,goto(from-pstn,${EXTEN},1))

Is that required to send the call back to “from-pstn” from the preprocessor or will it go there by default?


No. Once you get under the hood, nothing goes anywhere by default. You have to tell things where to go.

This only matches at the end of a pattern.

For completeness, you can also match the caller ID as a pattern, by putting an _ after the /.

Although priority has already been covered, I would add that, instead of repeating 1, for each alternative, you can use “s”, or even “n-1”, which makes it possible to repeat priorities even if you don’t know the preceding priority number.

I seem to be missing something…

After creating entries for all of the numbers I want to change and updating the trunk context under Trunk->pjsip Settings->context to “from-pstn-preprocess” I’m getting errors that say call to extension ‘1234’ rejected because extension not found in context ‘from-pstn-preprocess’, which ends with an abandoned call on the caller end.

extensions_custom.conf only contains:
exten => _./9876543210,1,Set(CALLERID(name)=NewName2) ; all inbound calls matching cid number 9876543210
exten => _.,n,Goto(from-pstn,${EXTEN},1)

I did remove trailing ‘)’ as I didn’t think it was necessary…adding it back gives same results. Whatever parses the config must be forgiving :slight_smile: Also just put your example in there for testing, I realize it’s not going to match what I want.

Not sure if this helps, but here’s some more info:

pbx*CLI> dialplan show from-trunk
[ Context 'from-trunk' created by 'pbx_config' ]
  Include =>        'from-pstn'                                   [pbx_config]

-= 0 extensions (0 priorities) in 1 context. =-
pbx*CLI> dialplan show from-pstn
[ Context 'from-pstn' created by 'pbx_config' ]
  Include =>        'from-pstn-custom'                            [pbx_config]
  Include =>        'ext-did'                                     [pbx_config]
  Include =>        'ext-did-post-custom'                         [pbx_config]
  Include =>        'from-did-direct'                             [pbx_config]
  Include =>        'ext-did-catchall'                            [pbx_config]

-= 0 extensions (0 priorities) in 1 context. =-

pbx*CLI> dialplan show from-pstn-preprocess
[ Context 'from-pstn-preprocess' created by 'pbx_config' ]

-= 0 extensions (0 priorities) in 1 context. =-
pbx*CLI> dialplan show [email protected]
[ Included context 'ext-did-0002' created by 'pbx_config' ]
  '_.' (CID match '2013552290') =>  1. Set(__DIRECTION=INBOUND)                   [extensions_additional.conf:2178]
                    2. Set(CHANNEL(tonezone)=us)                  [extensions_additional.conf:2179]
                    3. Set(__FROM_DID=${EXTEN})                   [extensions_additional.conf:2180]
                    4. Goto(s,1)                                  [extensions_additional.conf:2181]
                    5. Set(__CRM_DIRECTION=INBOUND)               [extensions_additional.conf:2182]
                    6. Set(__CRM_SOURCE=${CALLERID(num)})         [extensions_additional.conf:2183]
                    7. Set(__CRM_LINKEDID=${CHANNEL(LINKEDID)})   [extensions_additional.conf:2184]
                    8. AGI(agi://,true)   [extensions_additional.conf:2185]
                    9. ExecIf($["${CRM_DIRECTION}"="INBOUND"]?Set(CHANNEL(hangup_handler_push)=crm-hangup,s,1)) [extensions_additional.conf:2186]

[ Included context 'ext-findmefollow' created by 'pbx_config' ]
  '1234' =>         1. GotoIf($[${DB_EXISTS(AMPUSER/${EXTEN}/followme/ddial)} != 1 | "${DB(AMPUSER/${EXTEN}/followme/ddial)}" = "EXTENSION"]?ext-local,${EXTEN},1:followme-check,${EXTEN},1) [extensions_additional.conf:2435]

[ Included context 'ext-local' created by 'pbx_config' ]
  '1234' =>         hint: PJSIP/1234&PJSIP/901234&Custom:DND1234,CustomPresence:1234 [extensions_additional.conf:3743]
                    1. Set(__RINGTIMER=${IF($["${DB(AMPUSER/1234/ringtimer)}" > "0"]?${DB(AMPUSER/1234/ringtimer)}:${RINGTIMER_DEFAULT})}) [extensions_additional.conf:3737]
                    2. ExecIf($["${REGEX("from-queue" ${CHANNEL})}"="1" && "${CONTEXT}"="from-internal-xfer"]?Set(__CWIGNORE=)) [extensions_additional.conf:3738]
                    3. Macro(exten-vm,1234,1234,0,0,0)            [extensions_additional.conf:3739]
     [dest]         4. Set(__PICKUPMARK=)                         [extensions_additional.conf:3740]
                    5. Macro(vm,1234,${DIALSTATUS},${IVR_RETVM})  [extensions_additional.conf:3741]
                    6. Goto(vmret,1)                              [extensions_additional.conf:3742]

[ Included context 'ext-did-catchall' created by 'pbx_config' ]
  '_.' =>           1. Set(__FROM_DID=${EXTEN})                   [extensions_additional.conf:4737]
                    2. Noop(Received an unknown call with DID set to ${EXTEN}) [extensions_additional.conf:4738]
                    3. Goto(s,a2)                                 [extensions_additional.conf:4739]

-= 4 extensions (20 priorities) in 4 contexts. =-

pbx*CLI> dialplan show [email protected]
[ Context 'from-pstn-preprocess' created by 'pbx_config' ]
  '_.' (CID match '9876543210') =>  1. Set(CALLERID(name)=NewName2)               [extensions_custom.conf:2]
  '_.' =>           2. Goto(from-pstn,${EXTEN},1)                 [extensions_custom.conf:3]

-= 2 extensions (2 priorities) in 1 context. =-

Edited the dialplan with an important fix. There was no way to handle calls for all the other CID cases.

You have no priority 1 match for caller IDs other than 9876543210. Any call with a different caller ID will be rejected, in the way you are seeing. The most specific match is used, so, to be safe, you should use the same pattern on the line with the caller ID.

If you want to have a catch all, you should add a priority 1 with no caller ID qualification. However, you should note that _. matches some special values, so it is safer to use “_X.”, assuming that called numbers always start with a digit. Other patterns can be used in other cases.

1 Like

That seemed to fix it. Thanks! What is the NoOp line changing? I could tell by the logs when it was broke that ${EXTEN} was being set…so how did the NoOp make it work?

It was as @david55 said, there was no line to catch calls other than the specific CID cases. The Noop line doesn’t do anything other than provide a priority 1 for those.

This is technically correct, but long experience with writing contexts for this purpose has given me a level of comfort with just using _. It’s my lazy shorthand instead of writing separate lines for DIDs/CIDs with a leading + character, as well as for cases where one or both are missing. The most likely unexpected extension to catch with this dialplan is h, and happily there is a condition catching that in from-pstn in FreePBX, to terminate the channel.

What would you recommend for priorities on the callerID lines, the no-op line, and the goto line. I’m reading the docs but just not getting it.

I would guess that the order of parsing I want is my callerID lines, then the noop, and then the goto. Also, on the matching bit, looks like _X. is what should be on the callerID lines, but for the NoOp should it be _. or something more along the lines of “not _X.”?

I recommend you use the dialplan as written. Add additional Set lines for each CID you need using the same template, just change the CID number.

Thanks so much everyone, got it going!

One last question and I’ll shut up for a while :slight_smile:

While troubleshooting I found that if I didn’t send any callerid info that somewhere along the way it gets set to “Anonymous”, where does that get set and is it configurable?