Dialplan: commands for all extensions

Hi All!

Suppose that I have some dialplan. It has a strings which specifying the actions for various extensions.

exten => 100,1,...
exten => 101,1,...
exten => 102,1,...

But I still need to include a line in it, which will be executed for all еxtensions. And only then, the lines for the corresponding extension.

exten => ALL,1,Macro(cid-fix)
same  => n,NoOp(Call from '${CALLERID(all)}' to '${EXTEN}')
exten => 100,1,...
exten => 101,1,...

How to do it correctly?


All extensions includes h, i, s, t, e, etc., and you generally don’t want that.

Use a pattern, e.g. _X. that matches all your valid extensions, then coninue the extension specific code from the next priority, e.g. 100, and 101, in your example, would start at priority 3.

Maybe I misunderstood your answer, but I could not get what I wanted to do.

I created a test context. Now it contains only common command to all extensions.

exten => _X.,1,NoOp(Call from '${CALLERID(all)}' to '${EXTEN}')

In sip.conf I describe this context, an outgoing for the test SIP-terminal.
And I call on еxtension 700.

-- Executing [700@my-test:1] NoOp("SIP/sip-t26p_1-0000018d", "Call from '"Ogogon !!!" <600>' to '700'") in new stack
-- Auto fallthrough, channel 'SIP/sip-t26p_1-0000018d' status is 'UNKNOWN'

So far so good. Common to all extensions commands work.
But this is not enough for me. Now I want to add commands that are specific to each extension.

exten => _X.,1,NoOp(Call from '${CALLERID(all)}' to '${EXTEN}')
exten => 700,1,NoOp(Exten 700)
same  => n,HangUp()

Once again, I call on extension 700.

   -- Executing [700@my-test:1] NoOp("SIP/sip-t26p_1-0000018c", "Exten 700") in new stack
   -- Executing [700@my-test:2] Hangup("SIP/sip-t26p_1-0000018c", "") in new stack
  == Spawn extension (my-test, 700, 2) exited non-zero on 'SIP/sip-t26p_1-0000018c'

Now, the general commands are not executed. Asterisk saw an explicit number, and lost interest in the templates.

Please tell me how to change my test context that executed and common commands and commands for a specific context?

e.g. 100, and 101, in your example, would start at priority 3.

So 700 should start at 2, in your revised examle.

How about something like this…

exten => _X.,(Fix the caller ID here first)

same => n,Goto(my-dialplan)

exten => 100,1,…
same => n,Something else for 100
same => n,Another thing for 100
exten => 101,1,…
same => n,Something else for 101
same => n,Another thing for 101
exten => 102,1,…
same => n,Something else for 102
same => n,Another thing for 102

Just a small correction here @mkozusnik.
It should be Goto(my-dialplan,${EXTEN}),1)

The Goto() application can be called with either one, two, or three parameters. If you call the Goto() application with a single parameter, Asterisk will jump to the specified priority (or its label) within the current extension. If you specify two parameters, Asterisk will read the first as an extension within the current context to jump to, and the second parameter as the priority (or label) within that extension. If you pass three parameters to the application, Asterisk will assume they are the context, extension, and priority (respectively) to jump to.

Thanks for correcting that. I wrote it quickly and overlooked the others extension and priority. :slight_smile: