How to pass parameters to an extension?


Is it possible to pass parameters to a dialplan extension? I know that variables can be set via AMI and other interfaces and can then be used in dialplan but I was wondering if it was possible while simply calling the extension. For example:

Calling 123-456-789 would pass 456 and 789 (as arg1 and arg2) to the dialplan code of extension 123. Something like that…

What is the easiest way to pass data to the dialplan code of an extension?

That concept doesn’t exist, you can’t pass arguments to dialplan code of an extension. You can only set variables.

If so, I am still wondering what would be the best way to dynamically set channel variables to be used by the dialled extension code. Say, I dial extension 123 and I would like to dynamically set two variables each time the dialplan code for 123 is executed and use their values in the code. Should I use AMI or other interface for this? That would require connecting to that interface though – therefore a separate connection with that interface. What I am looking and hoping for is a way to pass input to my dialplan code right when the extension is dialled and preferably using the same dial operation.

Besides, I don’t see how I could set channel variables via AMI (or other) prior to a call? Should the call itself then be initiated via AMI?

What are my options here?

I don’t think we can answer this until you tell us what your real goal is.

Generally whatever invokes the extension (Asterisk users Dilal for devices, not extensions, should set the variables.

My real goal is passing input to dialplan code dynamically, which could be anything. For example, I may need to pass an extension number to the dialled extension, etc. Input could be anything that´s only decided or determined at runtime.

How do I set channel variables from my client while/before dialing an extension, so the set values are used when the dialled extension code (referencing those variables) is actually executed?

That’s not your real goal.


Currently my goal is to learn the dialplan scripting language. My question is for educational purposes only. Since the concept of passing parameters to an extension doesn’t exist in Asterisk and setting variables seems to be the only way to pass input to dialplan code as far as I understood, what is the best way to achieve this. A practical example would be the following:

I need to call an extension A which at some point should call extension X, where X is variable and can only be determined dynamically at runtime when A is called. So the calling device should find a way to define X prior to calling A and it should be a channel variable.

I am new to dialplan scripting and I am wondering if this is possible. Otherwise, how would you make extension A trigger extension X if X is determined at runtime?

Your problem is probably that you don’t understand what an extension is in Asterisk.

You would probably call extension AX, pattern match on just the A, parse out the X and goto it.

However your requirement is still too abstract to give a good concrete solution, as it is difficult to work out what extension A really represents.

1 Like

Note you can pass parameters to a subroutine, but you will generally need an extension to call the subroutine.

An extension is just the name of a piece of code in the dialplan AFAIK. Yes, I have read about pattern matching and I think your tip could be a good solution! This is exactly what I asked about in my OP when I said I would like to be able to pass 123-456-789 which would call extension 123 with 456 and 789 as arg1 and arg2 respectively. In fact, if I could match on just 123, then parse out the rest, then bingo!

Thanks a lot!

Yes I know that. What I am interested in finding out was how to pass input from outside, ideally while making the call. Your partial pattern matching hint should be the answer to my question. Thanks again.