Set CID question

(Lonely Admin) #1

Trying to figure out how to do this…and even if this (Set CID) is the right module.

For a known calling number (CID) I need to add/replace the CID Name and send to whatever the original DID being called was. I have no idea what destination to choose. Am I doing this wrong?

I ran across this thread that uses clidchange in /etc/asterisk/extensions_custom.conf, but I haven’t completely digested everything going on there.

So, for a list of known numbers calling any DID I need to change the CID name, keep the CID number, and go on to the original destination DID IR.


(Lorne Gaetz) #2

Are you able to have an inbound route (or routes) to catch all these calls? If so, you can use the Set CID module.

(Lonely Admin) #3

I already have inbound routes set for these which are pretty much “from anywhere to this DID go to this extension”. What’s tripping me up is the destination for the set CID. I don’t know how to introduce logic into the inbound route to flow through to the originally intended DID.

How I think it should work:
Any call from specified number change the CID Name then look at DID and match existing DID definition in inbound route.

Still learning here :slight_smile:

(Lorne Gaetz) #4

Got it. For a 100% GUI solution

Inbound route to Set CID module
Make desired change to Caller ID Name and then send call to Dynamic Route
Dynamic route branches call based on “Asterisk Variable” ${FROM_DID). Set a destination for each DID value.

(Lonely Admin) #5

So close I can taste it…
So I have this:
DID:ANY CID:1112223333 DEST:Set Caller ID Test

Set CID (Test):
CallerID Name: NameToChangeTo CallerID Number:${CALLERID(num)} Destination:Dynamic Routes(test)

Dynamic Routes (Test): [Here’s where I lose it]
${FROM_DID} has the DID of where this call would normally be matched in the inbound route. With a DID of “any” and CID priority route enabled it goes though the “any” match first instead of the matching DID route. I have Source Type set to Asterisk Variable and the variable set to ${FROM_DID}. Now I don’t know what to put for Default Destination and/or Dynamic Route Entries and match/destination.

I basically want to tell it to go back to the Inbound Routes with the changed caller id. I don’t see a “go back to where you came from” option :slight_smile:

I can tell by tailing the log file that the CID is getting updated. But without anything defined in the destination the call just gets dropped.

(Lorne Gaetz) #6

No going back, only forward. You must set your destinations again in dynroutes for each did. How many DIDs are we talking about?

(Lonely Admin) #7

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

(Lorne Gaetz) #8

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?

(Lonely Admin) #9

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?

(Lorne Gaetz) #10

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.

(Lonely Admin) #11

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.

(Lorne Gaetz) #12

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.

(Lonely Admin) #13

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

(Lorne Gaetz) #14

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.

(Lonely Admin) #15

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?

(Jared Busch) #16


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

(David55) #17

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.

(Lonely Admin) #18

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 1234@from-pstn
[ 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 1234@from-pstn-preprocess
[ 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. =-

(Lorne Gaetz) #19

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

(David55) #20

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.