Support both username and number for an extension

I have a user whose extension is 1000, but I’d also like the dialplan to route using his username of “michael” … Is there a way I can do both in a single rule, instead of splitting like the below? Is this the right way to do this?

        exten => 1000,1,NoOp(Dial Extension)
         same => n,Dial(${PJSIP_DIAL_CONTACTS(michael)},10)
         same => n,VoiceMail(${EXTEN}@internal-vm,u)
         same => n,Hangup()

        exten => michael,1,NoOp(Dial Extension)
         same => n,Dial(${PJSIP_DIAL_CONTACTS(michael)},10)
         same => n,VoiceMail(${EXTEN}@internal-vm,u)
         same => n,Hangup()

You could make extension 1000 GoTo extension Michael, but there is no real way of interleaving.

Yep

exten => michael,1,GoTo(1000)

His device name is miachael, not 1000!

Thanks, that works! What about some kind of string match for (1000 or Michael) in the first line. Does asterisk support that, or a regular expression?

Is it bad practice to use a username as a device name?

Asterisk doesn’t have full regular expression matching in dialplan patterns.

It is possible to have different patterns match on each priority, so you could have:

exten =>1000,1,Noop()
exten =>michael,s,Noop()
exten =>1000,n,DIal(…)
exten => michael,s,Dial(…)
exten => _.,n,Voicemail()
same => n,Hangup()

The hangup is not strictly necessary.

Having names is slightly more secure, although the official advice is something less guessable. However most people make the device name the same as the primary extension number, so that they can use ${EXTEN}, with a wildcard for the extension field.

You can’t have an OR operator in a pattern, except for character classes in a single character position, and you cannot have anything that matches more than a single character, except at the end of the pattern.

The patterns are compiled at dialplan reload time, and the internal data structure allow fast parallel lookups, but with each branch leading to a different place.