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

Asterisk 将变量从上下文传递到另一个上下文,asterisk,Asterisk,因此,我需要使用一个来自调用方调用的上下文的变量来调用被调用方使用的上下文,所以我有这样一个代码 [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(play

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

[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?

星号使用通道或分支的概念

所以在你的通话中有两个通道,每个通道都有独立的变量和控制结构

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

您可以使用共享函数获取其他通道的变量


要查看当前频道中设置的变量,您可以使用应用程序转储。此处不需要共享

中的G选项是将拨号操作中涉及的两个通道发送到不同位置的有趣选项之一。两者都将被发送到您指定的上下文/扩展,给定上下文的名称,它可能不是您想要的。被叫方被发送到优先级+1;主叫方优先权

也就是说,我希望被叫方开始在calledContext,s,2执行,而调用方开始在calledContext,s,1执行。但这是你的问题的附属问题

入站频道上设置的变量可以传递给它使用的拨号频道。即:

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()

使用u或u将导致在被叫方上设置变量。如果您想让变量继续传播到被叫方可能也会呼叫的频道,那么请使用.

我尝试了共享,但成功了,但拨了多个号码,每个号码都有不同的randomId,并且它们都是同时拨出的,因此randomId每次都会被覆盖,传递的randomId值是最后一个分配给itI的值,它已经给您提示了。所有其他的都是你的编程。对不起,我不想替你做编程。