Questions about dialplan optimization

Hello everyone,

My asterisk dialplan is working fine, but I’m sure I can optimize it. I have a few questions about it :

1] I am using patterns to allow external calls :

exten => _+.,1,MixMonitor(rec_${STRFTIME(${EPOCH},GMT-1,%Y-%m-%d_%H:%M)}_${CHANNEL(endpoint)}_${EXTEN}.g722)
same = n,Dial(PJSIP/${EXTEN}@voipms)
same = n,Goto(n-${DIALSTATUS},1)
exten => _00.,1,MixMonitor(rec_${STRFTIME(${EPOCH},GMT-1,%Y-%m-%d_%H:%M)}_${CHANNEL(endpoint)}_${EXTEN}.g722)
same = n,Dial(PJSIP/${EXTEN}@voipms)
same = n,Goto(n-${DIALSTATUS},1)
; exten => _0Z.,1,MixMonitor(rec_${STRFTIME(${EPOCH},GMT-1,%Y-%m-%d_%H:%M)}_${CHANNEL(endpoint)}_${EXTEN}.g722)
; same = n,Dial(PJSIP/"+33"${EXTEN:1}@voipms)
; same = n,Goto(n-${DIALSTATUS},1)
include => DialStatus

The _+. and _00. patterns have both the same dialplan, is there a way to write a pattern including _+. and _00. ?

  1. If a call can not be established, Asterisk plays a message (the DialStatus extension) :
same = n,Goto(n-${DIALSTATUS},1)
[DialStatus] ; if a call can not be established

exten => n-CHANUNAVAIL,1,PlayBack(custom/bonjour)
same = n,wait(0.3)
same = n,PlayBack(custom/numeroinvalide)
same = n,wait(0.3)
same = n,PlayBack(custom/bonnejournee)
same = n,Hangup()

exten => n-CONGESTION,1,PlayBack(custom/bonjour)
same = n,wait(0.3)
same = n,PlayBack(custom/numeroinvalide)
same = n,wait(0.3)
same = n,PlayBack(custom/bonnejournee)
same = n,Hangup()

exten => n-BUSY,1,PlayBack(custom/bonjour)
same = n,wait(0.3)
same = n,PlayBack(custom/busy)
same = n,wait(0.3)
same = n,PlayBack(custom/renouvelerappelplustard)
same = n,wait(0.3)
same = n,PlayBack(custom/bonnejournee)
same = n,Hangup()

exten => n-NOANSWER,1,PlayBack(custom/bonjour)
same = n,wait(0.3)
same = n,PlayBack(custom/numeronerepondpas)
same = n,wait(0.3)
same = n,PlayBack(custom/renouvelerappelplustard)
same = n,wait(0.3)
same = n,PlayBack(custom/bonnejournee)
same = n,Hangup()

Is there a way to do it more simply ? Is this good practice?
Thanks for your help

  1. No

  2. How do you measure simplicity. The simplest would probably be to consolidate the the messages and pauses offline then use:

same => n,Playback(CallFailed-${DIALSTATUS})

but the use of extensions for the various cases is a common practice.

Even simpler would be to do nothing and let the call fall through to a hangup, and have the network indicate the reason.

Thanks for your reply. Will do this. I prefer playing a message for users, it’s more appreciated.

Is there a way to do something when the extension is not found ? playing a sound for example.

In some cases, the i extension is run when the target extension isn’t found.

Remember that playing a message is likely to require you to answer the call, which will result in toll calls being charged. for.

Tried to set :

exten => i,1,PlayBack(custom/bonjour)

but when i dial an invalid extension :

[2021-11-12 13:12:30] NOTICE[3008]: res_pjsip_session.c:3975 new_invite:  1067: Call (UDP:my_ip_address:63024) to extension '444' rejected because extension not found in context 'Illimite'.

That’s why I said some cases. I’m not sure exactly when i is used and when it is not.

I think the i extension is used for IVR

Asterisk doesn’t have IVRs. Do you mean WaitExten and Background. I think it is also use for GoTo.

Yes, so no way to set a default extension who’s executed when no extension is found.

You “set” such a thing by writing dialplan for it which matches as a last resort.

You could experiment with an initial wildcard match and then TryExec on GoTo.

So if I do :

exten => _.,1,PlayBack(custom/error)

at the end of the context it works

I like Joshua’s approach better - I overcomplicated things.

However, you shouldn’t use “_.” as it matches the special extensions, as well as all normal ones. _X. is usually good enough, although you could use a character class.

Putting it at the end of the context is probably easier to understand, but the actual order doesn’t matter. Within a context the most specific entry matches, regardless of its position.

Thanks for all your help, it works !