将变量从上下文传递到另一个上下文

Passing Variables from context to another context

所以我需要使用来自调用方调用的上下文的变量到被叫方使用的上下文,所以我有这样的代码

[calledContext]

exten => s,1,goto(waits)
 same => n,goto(playmessage)
 same => n(waits),set(a=0)
 same => n(waits2),wait(5)
 same => n,GotoIf($[${a} = 0]?waits2:hang)
 same => n(playmessage),noop(${randomId})
 same => n(hang),hangup(); 

[callerContext]

exten => 012345,1,Noop()
 same => n,set(randomId=523)
 same => n,Dial(SIP/09201234567,20,G(calledContext^s^1)g)
 same => n,hangup()

这是我的问题,在 calledContext 上下文中,当我在 ${randomId} 上使用 noop() 时,没有任何显示,我如何将 randomId 的值从 callerContext 传递到 calledContext?

Asterisk 使用 CHANNEL 或 leg 的概念。

所以在你的调用中你有 2 个通道,每个通道都有自变量和控制结构

您可以通过 BRIDGEPEER 查看桥接频道的名称

http://www.voip-info.org/wiki/view/Asterisk+Detailed+Variable+List

你可以通过函数SHARED获取其他通道的变量。

http://www.voip-info.org/wiki/view/Asterisk+func+shared

要查看当前频道中设置的变量,您可以使用应用程序 DumpChan

SHARED 不是您想要的。

Dial中的G选项是其中一个有趣的选项,它将参与Dial操作的两个通道发送到不同的地方。两者都将被发送到您指定的 Context/Extension,鉴于上下文的名称,这可能不是您想要的。被叫方被发送到优先级+1;呼叫方优先级。

也就是说,我希望被叫方在 calledContext,s,2 开始执行,主叫方在 calledContext,s,1 开始执行。但这与你的问题无关。

可以使用 channel variable inheritance 将入站通道上设置的变量传递到它拨打的通道。即:

exten => 012345,1,Noop()
; Using a single underbar will set randomId on all channels this
; channel creates, but will not continue to propagate further
same => n,set(_randomId=523)
; Using two underbars will cause the variable to always propagate
same => n,set(__someOtherId=111)
same => n,Dial(SIP/09201234567,20,G(calledContext^s^1)g)
same => n,hangup()

使用 _ 或 __ 将导致在被叫方上设置变量。如果您希望变量继续传播到被叫方也可能呼叫的频道,则使用 __.