php - Twilio 客户端 DTMF 不工作

标签 php javascript twilio

我正在开发 Twilio 客户端应用程序,但我很难发送 DTMF 音调。这是我到目前为止的代码:

<script type="text/javascript">
$.each(['0','1','2','3','4','5','6','7','8','9','star','pound'], function(index, value) { 
    $('#button' + value).click(function(){ 
        if(connection) {
            if (value=='star')
                connection.sendDigits('*')
            else if (value=='pound')
                connection.sendDigits('#')
            else
                connection.sendDigits(value)
            return false;
        } 
     });
  });
</script>


<div id="dialpad">
    <table>
    <tr>
    <td><input type="button" value="1" id="button1"></td>
    <td><input type="button" value="2" id="button2"></td>
    <td><input type="button" value="3" id="button3"></td>
    </tr>
    <tr>
    <td><input type="button" value="4" id="button4"></td>
    <td><input type="button" value="5" id="button5"></td>
    <td><input type="button" value="6" id="button6"></td>
    </tr>
    <tr>
    <td><input type="button" value="7" id="button7"></td>
    <td><input type="button" value="8" id="button8"></td>
    <td><input type="button" value="9" id="button9"></td>
    </tr>
    <tr>
    <td><input type="button" value="*" id="buttonstar"></td>
    <td><input type="button" value="0" id="button0"></td>
    <td><input type="button" value="#" id="buttonpound"></td>
    </tr>
    </table>
</div>

当我调用我的测试号码并按下拨号盘上的按钮时,它没有发送值。非常感谢您对此提供任何帮助?

最佳答案

在您的脚本 block 中,您需要有可用的连接对象。所以在你的功能之上,你需要像这样的东西:

var connection = null;
Twilio.Device.setup('your token');
params = { "number" : "5559871234", "outbound" : "true" };
connection = Twilio.Device.connect(params);

本质上,这个函数只需要“看到”连接变量。如果您的 javascript 文件位于不同的位置并且您无法合并它们,您可以将连接对象设置为全局(不理想)至少看看您是否可以让它工作。

connection = null;

(前面没有“var”)

关于php - Twilio 客户端 DTMF 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11285740/

相关文章:

javascript - node.js - 想在同一个路由器 POST 中发送两个资源

php - 在 Eloquent Laravel 中为 Between 编写原始查询

php - Prestashop 1.7 block page_content

php - sql插入具有层次结构的一堆记录

javascript - 如何为 Bokeh 回调过滤器的一部分编写 Javascript 代码,以便我可以按数字和类别进行过滤?

Twilio session 录制状态回调 URL 未触发

sms - Twilio SMS 验证目标电话号码和验证 ID

php - 使用 php 和 clamav 扫描文件夹中的病毒?

javascript - 如何在 jquery 中停止以前的 dom 元素动画

javascript - 我必须从 Controller 访问表 tr 以突出显示行