PJSIP_HEADER with channel variable not working?

Sorry for all the forums topics, working hard on all the dialplan things, learning everyday.

(Asterisk 18 Function_PJSIP_HEADER - Asterisk Project - Asterisk Project Wiki)

Adding an extra sip header for the callee with a hardcoded value works.

[ctbVariableOutboundCallStartSuccess]
exten => 1,1,Verbose(Variable outbound call start success)
same => n,Set(ctbMonitor=${SHELL(echo '${ctbJsonResult}' | jq '.data.callRecording' | tr -d '\n"')})
same => n,Verbose(Callrecording: ${ctbMonitor})
same => n,ExecIf($[${ctbMonitor}=1]?MixMonitor(${ctbCodexLocation}${ctbSessionId}.wav))
same => n,Set(CALLERID(num)=+${ctbOutboundDialedNumber})
;same => n,Dial(PJSIP/+${ctbEmployeeOutboundNumber}@${ctbSipProviderEndpoint}&PJSIP/${ctbWebPhoneEndpoint},${ctbDialTimeOut},g)
same => n,Verbose(Visitor user id ${ctbVisitorUserId})
same => n,Dial(PJSIP/${ctbWebPhoneEndpoint},${ctbDialTimeOut},b(ctbVariableOutboundCallStartHeaders^addheader^1))
same => n,Verbose(Call result: ${DIALSTATUS});
same => n,Log(NOTICE, Call result: ${DIALSTATUS})

[ctbVariableOutboundCallStartHeaders]
exten => addheader,1,Set(PJSIP_HEADER(add,CtbVisitorUserId)=12)

Changing

exten => addheader,1,Set(PJSIP_HEADER(add,CtbVisitorUserId)=12)

into

exten => addheader,1,Set(PJSIP_HEADER(add,CtbVisitorUserId)=${ctbVisitorUserId})

Does not work and leaves the value empty.

Note that ${ctbVisitorUserId} out put is 126, so the channel variable is set

How can you set a channel variable value as header value?

The channel variable doesn’t exist on the called channel, unless you use variable inheritance. Your verbose line is outputting it from the calling channel. You can either inherit the variable, or pass it as an argument to the Gosub in the Dial ‘b’ option.

1 Like

The use of a single _ did the trick following Variable Inheritance - Asterisk Project - Asterisk Project Wiki

exten => 1,1,Verbose(Variable outbound call start success)
same => n,Set(ctbMonitor=${SHELL(echo '${ctbJsonResult}' | jq '.data.callRecording' | tr -d '\n"')})
same => n,Verbose(Callrecording: ${ctbMonitor})
same => n,ExecIf($[${ctbMonitor}=1]?MixMonitor(${ctbCodexLocation}${ctbSessionId}.wav))
same => n,Set(CALLERID(num)=+${ctbOutboundDialedNumber})
;same => n,Dial(PJSIP/+${ctbEmployeeOutboundNumber}@${ctbSipProviderEndpoint}&PJSIP/${ctbWebPhoneEndpoint},${ctbDialTimeOut},g)
same => n,Set(_ctbVisitorUserId=${ctbVisitorUserId})
same => n,Dial(PJSIP/${ctbWebPhoneEndpoint},${ctbDialTimeOut},b(ctbVariableOutboundCallStartHeaders^addheader^1))
same => n,Verbose(Call result: ${DIALSTATUS});
same => n,Log(NOTICE, Call result: ${DIALSTATUS})

[ctbVariableOutboundCallStartHeaders]
exten => addheader,1,Set(PJSIP_HEADER(add,CtbVisitorUserId)=${ctbVisitorUserId})

Solution: same => n,Set(_ctbVisitorUserId=${ctbVisitorUserId})

Thanks

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.