How to get a trunk name in AGI script?

I need to do some OutboundCID manipulation based trunk name and CallerID.

I’m used [macro-dialout-trunk-predial-hook] to put my code in. Caller ID is not a big problem as I used ${CALLERID(number)} to get it. But its a bit unclear how to get the Trunk Name being called. Any advises on this?

Artem

Which channel technology driver are you using (e.g. skinny, H.323, DAHDI/analogue)?

I’m using PJSIP as a driver.

The trunk name meaning from a FreePBX setup? Anyway what if you try to set a variable in the peer definition maybe that could work.

set_var under pjsip endpoint definition just didn’t work in asterisk 13 for some reason.

Actually I managed to get a trunk name by using following:

exten => s,n,Set(the_trunk_raw=${OUTNUM}${OUT_${DIAL_TRUNK}_SUFFIX})
exten => s,n,Set(the_trunk=${CUT(the_trunk_raw,@,2)})

However if I try to fit everything in one line it wouldn’t work and return empty line
exten => s,n,Set(the_trunk=${CUT(${OUTNUM}${OUT_${DIAL_TRUNK}_SUFFIX},@,2)})

The CUT function takes variable name as a first argument so I don’t think it will work the way you intend to use.
e.g.

exten => s,1,Set(foo=${CUT(bar,2)}) ; This is correct syntax
exten => s,1,Set(foo=${CUT(${bar},2)}) ; This is invalid syntax (unless bar contains the name of another variable)

Odd, I’ve got no problem using it, Even with using the pjsip wizard.

[myendpoint]
set_var=911trunkid=Trunk9