Pattern matching for Anonymous

I have created an IVR menu where I want to send callers to specific locations based on their calling number. I however can’t get it to work if the A-number is Anonymous.

exten => s,1,NoOp(Entering IVR)
exten => s,n,Goto(${CALLERID(num)},1)
exten => _Anonymous!,1,NoOp(Anonymous caller)
exten => _Anonymous!,n,Hangup()
exten => _+45!,1,NoOp(Danish number)
exten => _+45!,n,Hangup()
exten => i,1,NoOp(No match)
exten => i,n,Hangup()

It works fine when the A-number is ex. +4524252627 - then I hit the _+45! pattern
When A-number is Anonymous then no match is found, and I hit the i extension.

Am I doing something wrong or are alphabetical strings not supported?

On Tuesday 05 November 2024 at 13:50:19, Soelvberg via Asterisk Community
wrote:

I have created an IVR menu where I want to send callers to specific
locations based on their calling number. I however can’t get it to work if
the A-number is Anonymous.

Am I doing something wrong or are alphabetical strings not supported?

Alphabetic strings are definitely supported. Show us what ${EXTEN} contains at
this point in the dialplan.

Antony.


Schrödinger’s rule of data integrity: the condition of any backup is unknown
until a restore is attempted.

                                               Please reply to the list;
                                                     please *don't* CC me.

Why can’t you do an exact match?

If you really need wild card suffixes, you may need to give the letters as single character character classes, otherwise some will be treated as meta-characters: [A]]n][o]…

Hi Antony and David

I probably have found the solution.
What I had was this

[ZyIncoming]
exten => aaaa,1,NoOp(********** START ***********)
exten => aaaa,n,Goto(ivrtest,s,1)

[ivrtest]
exten => s,1,NoOp(****** In IVR*******)
exten => s,n,Goto(${CALLERID(num)},1)
exten => _Anonymous!,1,NoOp(Anonymous caller***)
exten => _Anonymous!,n,Hangup()
exten => _+45!,1,NoOp(*********** Danish number*******************)
exten => _+45!,n,Hangup()
exten => i,1,NoOp(********* NO MATCH ****************)
exten => i,n,Hangup()

And my the first lines of my INVITE was this

INVITE sip:aaaa@novus.zylinc.cloud:5090 SIP/2.0
From: “Loadtest” sip:Anonymous@10.0.0.4;tag=a4ee714d-3542-4526-9a9f-6927b0fff668

I just found that if I change the anonymous pattern to
exten => _[Anonymous]!,1,NoOp(works)
Then it works as expected.

One question still: if I also change the Danish extension to exten => _[+45]!,1,NoOp(Danish)
Then i get a match no matter what number I use - except for Anonymous

Tried calling in with number 54912345678, and for some reason it matched matched _[+45]!
Executing [54912345678@ivrtest:1] NoOp(“PJSIP/anonymous-00000039”, “*********** Danish number*******************”)

So what i need to know is when the extension should be enclosed in brackets.
Is it when it contains any letters that is not + or numeric?

On Tuesday 05 November 2024 at 14:36:27, Soelvberg via Asterisk Community
wrote:

I just found that if I change the anonymous pattern to
exten => _[Anonymous]!,1,NoOp(works)
Then it works as expected.

This looks absolutely terrible.

It’s a pattern match (starts with underscore) for any letter in the word
“Anonymous” (so, any of A m n o s y) and will end on the first match (ends with
exclamation).

Please read about Asterisk patterns before implementing this sort of thing for
real.

https://docs.asterisk.org/Configuration/Dialplan/Pattern-Matching/

Antony.


It is also possible that putting the birds in a laboratory setting
inadvertently renders them relatively incompetent.

  • Daniel C Dennett

                                                Please reply to the list;
                                                      please *don't* CC me.
    

I changed the script to this:

[ZyIncoming]
exten => aaaa,1,NoOp(********** START ***********)
exten => aaaa,n,Goto(ivrtest,s,1)

[ivrtest]
exten => s,1,NoOp(****** In IVR*******)
exten => s,n,Goto(${CALLERID(num)},1)
exten => _[A][n][o][n][y][m][o][u][s]!,1,NoOp(Anonymous caller***)
exten => _[A][n][o][n][y][m][o][u][s]!,n,Hangup()
exten => _[+][4][5]!,1,NoOp(*********** Danish number*******************)
exten => _[+][4][5]!,n,Hangup()
exten => i,1,NoOp(********* NO MATCH ****************)
exten => i,n,Hangup()

Then everything works as expected.
Thank you so much for your hints

On Tuesday 05 November 2024 at 14:56:10, Soelvberg via Asterisk Community
wrote:

exten => _[A][n][o][n][y][m][o][u][s]!,1,NoOp(Anonymous
caller
***)
exten => _[A][n][o][n][y][m][o][u][s]!,n,Hangup()
exten => _[+][4][5]!,1,NoOp(*********** Danish number*******************)
exten => _[+][4][5]!,n,Hangup()

PLEASE read Pattern Matching - Asterisk Documentation

Antony.


A committee is a group of people who keep minutes and waste hours.

  • Milton Berle

                                                Please reply to the list;
                                                      please *don't* CC me.
    

Hi Pooh

I have read pattermatching and has used it for many years - but I recently found that my implementation didn’t work when the customer is configuring a specific call flow for calls from “Anonymous”.
Right now I am going with this:

exten => _[A][n][o][n][y][m][o][u][s]!,n,Noop(Anonymous)
exten => _+45!,1,NoOp(Danish number)

I know that the Anonymous line could be handled by not entering it as a pattern (no underscore and no exclamation mark) - but we actually do have a provider that is sending “Anonymous caller”, instead of just “Anonymous” so a pattern is needed to handle those cases.
Please note that I am not setting up the patterns manually. I am doing it programmatically and need a general rule on how to format the the values entered by the customer.

If I have missed something in the Asterisk documentation, would you then please enlighten me on how I could set up a pattern for all calls starting with “Anonymous” in another way?

On Thursday 14 November 2024 at 11:51:58, Soelvberg via Asterisk Community
wrote:

we actually do have a provider that is sending “Anonymous caller”, instead
of just “Anonymous” so a pattern is needed to handle those cases.

I would deal with this at the point where you identify the Caller ID which is
being sent, not in the pattern match for an extension in your dialplan.

So, somethng like:

same => n,GotoIf ( [ “${CALLERID(num):0:9}” = “Anonymous” ] ? anoncall )
same => n,Do whatever you want with non-anonymous calls

Then you label the extension for handling this case:

same => n(anoncall),Do whatever you need to with anonymous calls

Does that help?

Antony.


Numerous psychological studies over the years have demonstrated that the
majority of people genuinely believe they are not like the majority of people.

                                               Please reply to the list;
                                                     please *don't* CC me.

Apologies for the missing $

same => n,GotoIf ( [ “${CALLERID(num):0:9}” = “Anonymous” ] ? anoncall )

same => n,GotoIf ( $[ “${CALLERID(num):0:9}” = “Anonymous” ] ? anoncall )

Antony.

You are matching callee, not caller here. To pattern match the caller, you need a pattern or literal callee match a / and then a pattern or literal caller match.

Space is not valid in SIP user names. Are they sending this in caller name? Asterisk only matches ids, not names.

I do

same => n,GotoIf ( $[ “${CALLERID(num):-8}” = “nonymous” ] ? anoncall )

to avoid an Aa swap

On Thursday 14 November 2024 at 12:53:45, tootai via Asterisk Community wrote:

I do

same => n,GotoIf ( $[ “${CALLERID(num):-8}” = “nonymous” ] ? anoncall )

to avoid an Aa swap

Agreed, however this would not cope with “Anonymous caller”, which the OP said
some ITSP is sending.

Antony.


“Linux is going to be part of the future. It’s going to be like Unix was.”

  • Peter Moore, Asia-Pacific general manager, Microsoft

                                                Please reply to the list;
                                                      please *don't* CC me.
    

same => n,GotoIf ( $[ “${CALLERID(num):1:8}” = “nonymous” ] ? anoncall )

would then do the trick


Daniel

The space makes me think that this should be name, not num.

On Thursday 14 November 2024 at 13:31:49, david551 via Asterisk Community
wrote:

The space makes me think that this should be name, not num.

Entirely reasonable, but:

a) not all (many?) ITSPs actually send name as well as num

b) I’ve seen spaces even in telephone numbers before now

c) The OP started this thread with a posting 2024-11-05 which included:
exten => s,n,Goto(${CALLERID(num)},1)

Antony.


Never automate fully anything that does not have a manual override capability.
Never design anything that cannot work under degraded conditions in emergency.

                                               Please reply to the list;
                                                     please *don't* CC me.

I only included a very small sample so my question was clearer.
But Asterisk can easily match on whatever you want, if you code for it.
ex. Goto(${Some variable},1) would go to the extension that best matches the variable

On Thursday 14 November 2024 at 14:06:55, Soelvberg via Asterisk Community
wrote:

I only included a very small sample so my question was clearer.
But Asterisk can easily match on whatever you want, if you code for it.
ex. Goto(${Some variable},1) would go to the extension that best matches
the variable

You do, however, need a good understanding of what Asterisk thinks of as
“best”.

I don’t regard the above solution as good for future maintenance, when someone
is reading the dialplan in 6 months’ time (or more) and trying to work out why
the call ended up where it did. That person may even be you.

Antony.


“There is no reason for any individual to have a computer in their home.”

  • Ken Olsen, President of Digital Equipment Corporation (DEC, later consumed
    by Compaq, later merged with HP)

                                                Please reply to the list;
                                                      please *don't* CC me.
    

In this case they were not being matched on a number, but the displayname in a PAI header.
Might seem weird to you, but I needed it to determine whether we were allowed to show the number to the handling agent.
It was merely an example to illustrate my problem.

Regarding your warning about automation: when you handle 100+ customers you don’t have time sit and hold their hand while they are setting up the callflow that they want, so automation and CI/CD quickly becomes a “must have”