[Asterisk-Dev] Making a variable available to a dialplan

steve at daviesfam.org steve at daviesfam.org
Thu Oct 21 11:54:23 MST 2004




> > >>I need to create a variable in an app "global" so that I can refer to 
> > >>its value in a dial plan.  What functions should I look at to do this?  
> > >>Searching the archives didn't turn anything up.

I recently had a situation where it would have been great to be able to 
declare a channel variable "statically" within a context, such that 
the channel gets that variable before the first exten=> line in the 
context, or in an included context, gets executed.


So I could do something like this:

[exten-6001]
setvariable=>NUFONECID=18001231234
setvariable=>PSTNCID=021123${EXTEN}
setvariable=>CALLERCANTRANSFER=T
include=>dialplan-chargeable

[exten-6002]
setvariable=>NUFONECID=18001231235
setvariable=>PSTNCID=021123${EXTEN}
setvariable=>CALLERCANTRANSFER=T
include=>dialplan-chargeable

How is this useful?  For instance, when we dial another extension:

[dialplan-chargeable]
include => extens

[inbound-calls]
include => extens

[extens]
exten => _60XX,1,Dial(SIP/${EXTEN},30,${CALLERCANTRANSFER}t)

Now when an extension is dialled from another extension, then the T flag 
goes in the dial.  So the caller can transfer.  But when the extension is 
dialled from outside, CALLERCANTRANSFER is nothing and the caller can't 
transfer.

Obviously, the other two variables are to set the right CID when we send 
calls out our various routes.

Now I know the technique of starting your dial steps in the included 
context from 5 or whatever, leaving 4 steps that must be defined in the 
including context.  But, really, what a pain to keep all that in step and 
error-free.  

The logic would be that before an exten=> line is executed, to pass
through the context "inheritance chain" and set the variable(s) on the
channel if it hasn't already got the name.

What do people think?

Steve




More information about the asterisk-dev mailing list