【问题标题】:Asterisk PBX - Infinite Loop when user disconnects while using 'Read' application from LUAAsterisk PBX - 当用户在使用 LUA 的“读取”应用程序时断开连接时的无限循环
【发布时间】:2019-06-16 03:57:24
【问题描述】:

我现在正在为星号配置交互式拨号计划,因为我已经知道一些 LUA,所以我认为走这条路会更容易。

我有一个这样的开始扩展:

["h"] = function(c,e)
    app.verbose("Hung Up")
  end;

["s"] = function(c, e)
    local d = 0
    while d == 0 do
      say:hello()
      app.read("read_result", nil, 1)

      d = channel["read_result"].value;

      if d == 1 then
        say:goodbye()
      elseif d == 2 then
        call:forward('front desk')
      end

      d = 0
    end

    say:goodbye()
end;

如你所见,我想在任何时候重复指令say:hello() 用户给出了无效的答案。但是,如果用户在 app.read 等待他们的回答,星号进入无限循环 因为d 将永远是nil

我会检查 d==nil 以检测断开连接,但 nil 也会显示 当用户在app.read 期间按下# 井号时,就会启动。

到目前为止,我已经开始使用 for 循环而不是 while 来限制 以这种方式进行最大迭代,但我宁愿找出如何检测断开连接 渠道。不过我找不到任何相关文档。

我也尝试设置一个h 扩展,但是当 用户挂断。

星号详细输出:

[...]
-- Executing [s@test-call:1] read("PJSIP/2300-00000004", "read_result,,1")                │        test.lua:3: in main chunk
-- Accepting a maximum of 1 digit.                                                       │        [C]: ?
-- User disconnected                                                                      │root@cirro asterisk lua test.lua
-- Executing [s@test-call:1] read("PJSIP/2300-00000004", "read_result,,1")                │Global B
-- Accepting a maximum of 1 digit.                                                       │LocalB-B->a
-- User disconnected                                                                      │LocalB-A
-- Executing [s@test-call:1] read("PJSIP/2300-00000004", "read_result,,1")                │LocalB-A
-- Accepting a maximum of 1 digit.                                                       │LocalB-A
-- User disconnected                                                                      │root@cirro asterisk cp ~/test.call /var/spool/asterisk/outgoing
-- Executing [s@test-call:1] read("PJSIP/2300-00000004", "read_result,,1")
[...]

感谢您提供的任何帮助。

【问题讨论】:

    标签: lua asterisk pbx


    【解决方案1】:

    首先,您可以在 app_read 文档(以及任何其他文档)中看到,它会为不正确的执行(当通道关闭时)返回不同的值。

    这个确切的应用程序还提供了确定结果的简化方法:

    core show application Read
    
      -= Info about application 'Read' =- 
    
    [Synopsis]
    Read a variable. 
    
    [Description]
    Reads a #-terminated string of digits a certain number of times from the user
    in to the given <variable>.
    This application sets the following channel variable upon completion:
    ${READSTATUS}: This is the status of the read operation.
        OK
        ERROR
        HANGUP
        INTERRUPTED
        SKIPPED
        TIMEOUT
    

    如果仍然不适合你,你可以直接向星号询问 CHANNEL(state)

    PS绝不应该编写拨号方案或任何其他无限循环的程序。数一数你的循环并在 10+ 时退出。这将为客户节省大量的资金。

    【讨论】:

    • 谢谢,这正是我所需要的——我实际上并没有意识到 AMI 有如此广泛的内置文档。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-05-18
    • 1970-01-01
    • 1970-01-01
    • 2020-08-21
    • 2018-05-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多