How to detect by which numbers are starting the caller ID


I am looking for help to know how to gotoif the caller ID coming from outside starts by a specific series of numbers. As I am looking to use aliases to transfer to a specific IVR instead of buying a SIP trunk to use aliases as it would cost a lot.

The scheme:
I got one VOIP line: 0123232323
I got 3 aliases:
Work alias: 0123232325
Home alias: 0123232326
Public alias: 0123232327

For now, I wanted each alias to be detected and transferred to them IVR. There is two problems that I would make that work.
1st: confusion, to make that work I actually make a rule when you call the alias it calls the voip line number and shows its alias number not the number of the caller. I can choose to show both.
2nd: don’t know how to show caller id when ringing to a phone because for the moment it shows only the alias number when ringing to a phone. That’s normal because I choose to show the alias number when it calls the voip line in order to detect them in Asterisk.

It’s a little bit confusing sorry for that. I am making the things complicated but I really do not want to buy a SIP trunk if I can make the things work as they are.

This is what I am already using and that works:

exten => s,1,GotoIf($["${CALLERID(num)}" = "XXXXXXX34"]?dial1) // detecting if that's the work phone number alias then transfer dial1 priority
exten => s,n,GotoIf($["${CALLERID(num)}" != "XXXXXXX34"]?home1) // if the number is calling is different than my work number transfer to my home ivr
exten => s,n(home1),Goto(home,8002,1)
exten => s,n(dial1),GotoIfTime(10:00-11:59|mon-fri|*|*?open,s,1)
exten => s,n,GotoIfTime(14:00-18:00|mon-fri|*|*?open,s,1)
exten => s,n,Goto(closed,s,1)

That scheme actually works well. I really think it is not the better way to make it working. I am a beginner in all that things.

As now, I added a new alias to that scheme. The problem is that actually there is only one number I am detecting and if it is not it transfers to my home ivr. But now, I want it to detect if that is my work alias, the house alias or the public alias which is making more difficult.

Is there anyone that know how we can proceed that scheme to the extensions. I tried a lot of things to detect the both entire aliases and transfer to priority each one but it does not work.

I stay fully available for any further questions,

Let me start with showing something I did involving CallerID:

exten => s,1,GoToIf($["${DB_EXISTS(newnake/${CALLERID(num)})}" = "1"]?2:3)
same => 2,Set(CALLERID(name)=${DB(newnake/${CALLERID(num)})})
same => 3,Dial(PJSIP/6422)

My situation was I had old analog phone systems running on ATAs and a lot of friends and family with new numbers that weren’t getting updated information. So what I did was program all those numbers in to a database with the correct info; then rewrote the CALLERID field before dialing the extension.

You don’t need two GoToIf statements. It either matches, or it doesn’t.

exten => s,1,GotoIf($["${CALLERID(num)}" = "XXXXXXX34"]?dial1:home1)

Does the same thing as both of your lines.

Try issuing a Set(CALLERID(num) before you dial.

1 Like

Thank you so much for your really detailed answer.
I took note of all your explications. But, one thing remains confused. For the Gotoif, if that only one line makes the work for my actual configuration. How to add a detection of an additionnal number, as here you entered callerid is = to my work alias for example then, if it’s my public alias how to distinguish both and redirect them to dial2 priority, is it possible to add all these priorities? and make all that stuff working together?
For the caller id, thanks, if I make this, how to tell asterisk to choose only the caller number and not choose the alias number if I show both of them in the header of the sip frame?

I copied from your example…if the operation is backwards…then you must have described as such. But the basic idea is that the GoToIf will handle both true and false actions. Think of it like this:

GoToIf(some statement)?true:false)

What dial2 priority? You don’t talk about that in your post.
If you want to detect additional numbers…then you need to either add more GoToIfs or switch to something that checks the number against a database.

1 Like

As already pointed out, you don’t need both positive and negative tests. Also, you can go directly to the full context, extension and priority, from the GotoIF.

Moreover, you do not need explicit conditionals for this, as you can match on callerID and extension combinations:

exten=> s/XXXXXXX34,1,GoTo...... ; office
exten=> s/YYYYYYYYY,s,......  ; home
exten=> s,s,...... ; default processing

Hello David, I apologize for my late answer and many thanks for your response.

I succeeded made it working with your method. I did not know putting s/ could be use to detect the caller ID and making whatever you want afterwards.
The only thing still remaining now is how to set the caller id to show the caller’s one and not the alias number.
As for the moment, I set up to show the alias number in order to transfer each alias to its appropriate context. I can set up to show both numbers (caller id + allias id) but I also don’t know if my method will still work in these conditions.

here is the actual working dialplan with the last modifications made.

exten => s/04XXXXXX84,1,GotoIfTime(10:00-11:59|mon-fri|*|*?open,s,(dial1))
exten => s/04XXXXXX60,s,Goto(home,8003,2)
exten => s/04XXXXXX41,s,Goto(home,8002,1)
exten => s,n(dial1),GotoIfTime(14:00-18:00|mon-fri|*|*?open,s,1)
exten => s,n,Goto(closed,s,1)

Have you any suggestions I could follow?
Kind regards,

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.