[asterisk-users] pre-dial handler, how to access variables from calling channel?

Tony Mountifield tony at softins.co.uk
Fri Nov 15 08:27:30 CST 2019


In article <20191115150532.53eb10e2 at go.imp.ch>,
Benoit Panizzon <benoit.panizzon at imp.ch> wrote:
> Hi List
> 
> Implementing screening and routing I have stumbled over this issue:
> 
> [pbx-router]
> exten => s,1,NoOp(ROUTER FROM: ${CALLERID(Number)}  TO: ${DESTINATION})
>         same => n,Set(SOURCE=${CHANNEL(name)})
>         same => n,Set(PAI=${PJSIP_HEADER(read,P-Asserted-Identity)})
> ....
> 
> But I have not yet found any 'easy' way to pass the corrected ${PAI}
> Variable to the callee channel.

Try changing PAI to __PAI when setting:

same => n,Set(__PAI=${PJSIP_HEADER(read,P-Asserted-Identity)})

When setting a variable, if you prepend a single underscore, e.g. "_PAI",
the variable will be inherited by any channels created by the current
channel (child channels), but will not be inherited further (it is
effectively created as "PAI", which is then non-inheritable).

If you prepend two underscores, e.g. "__PAI", the variable will be inherited
by child channels, and will then be further inherited by grandchild channels
and so on (it is effectively created as "__PAI" each time).

You don't need to speficy the __ when reading the variable, just use ${PAI}
as before.

See https://wiki.asterisk.org/wiki/display/AST/Variable+Inheritance

Cheers
Tony
-- 
Tony Mountifield
Work: tony at softins.co.uk - http://www.softins.co.uk
Play: tony at mountifield.org - http://tony.mountifield.org



More information about the asterisk-users mailing list