我正在尝试将特定的传入标头转发到呼叫的另一条线路,但不知道如何将传入线路中的标头值传递给预拨号处理程序
[addheaders]
exten => addheader,1,Verbose("Setting header")
exten => addheader,1,Verbose(${somevar}) ; The 'somevar' variable doesn't exist anymore
exten => addheader,n,Set(PJSIP_HEADER(add,X-MyHeader)=test)
exten => addheader,n,Set(PJSIP_HEADER(add,X-MyHeader2)=${somevar})
exten => addheader,n,Return()
[incoming]
exten => _+4600.,1,Ringing
exten => _+4600.,n,Set(somevar=${PJSIP_HEADER(read,TheHeaderIWantToForward)})
exten => _+4600.,n,Verbose(${somevar}) ; Prints the correct value
exten => _+4600.,n,Dial(PJSIP/${EXTEN:1},,b(addheaders^addheader^1))
exten => _+4600.,n,Hangup
我已成功将 X-MyHeader 添加到出站呼叫线路(因为星号文档演示如何操作),但我如何实际将值传递给其他上下文?我无法读取“[addheaders]”中的变量,只能读取“[incoming]”中的标头
答案1
您可以使用_VARIABLE:https://wiki.asterisk.org/wiki/display/AST/Variable+Inheritance
[handler]
exten => addheader,1,NoOp(Value is ${somevar})
same => n,Set(PJSIP_HEADER(add,X-myheader=${somevar})
same => n,Return()
[internal]
exten => 6010,1,NoOp(Test)
same => n,Set(_somevar=${PJSIP_HEADER(read,X-myheader)})
same => n,NoOp(Value is ${somevar})
same => n,Dial(PJSIP/6010,,b(handler^addheader^1))
same => n,Hangup()
答案2
不知道这是否是执行此操作的“正确”方法,但我通过在 addheaders 上下文中接受通配符扩展来解决了它:
[addheaders]
exten => _.,1,Set(PJSIP_HEADER(add,X-header-to-be-forwarded)=${EXTEN})
exten => _.,n,Return()
[incoming]
exten => _+4600.,1,Ringing
exten => _+4600.,2,Set(customheader=${PJSIP_HEADER(read,X-header-to-be-forwarded)})
exten => _+4600.,3,GotoIf($["${customheader}"=""]?7:) ; Skip adding the header if it is empty
exten => _+4600.,4,Dial(PJSIP/${EXTEN:1},,b(addheaders^${customheader}^1))
exten => _+4600.,5,GoTo(9))
exten => _+4600.,6,Dial(PJSIP/${EXTEN:1})
exten => _+4600.,7,Hangup
这有一些限制,例如“。”或“,”不能使用,但它解决了我们的问题。
答案3
您还可以将参数传递给 Dial 应用程序 b 选项:
b([[context^]exten^]priority[(arg1[^...][^argN])]): Before initiating an
outgoing call, Gosub to the specified location using the newly created
channel. The Gosub will be executed for each destination channel.
像这样:
exten => _+4600.,n,Dial(PJSIP/${EXTEN:1},,b(addheaders^addheader^1(${somevar})))
然后使用它:
exten => addheader,n,Set(PJSIP_HEADER(add,X-MyHeader)=${ARG1})