【问题标题】:Twilio PHP SDK, make outbound call, receive DTMF input from user and redirect callTwilio PHP SDK,进行出站呼叫,接收来自用户的DTMF输入并重定向呼叫
【发布时间】:2018-03-14 13:50:08
【问题描述】:

我正在尝试使用 Twilio PHP SDK 从 Twilio 进行出站呼叫。但我无法弄清楚如何从该调用中获取 DTMF 输入,然后根据该输入执行一些操作,例如如果按 1,将被叫号码连接到另一个号码。

这是我的外呼代码:

$call = $client->calls->create(
        $phone, "+1xxxx",
        array(
            "url" => "http://demo.twilio.com/docs/voice.xml",
            "method" => "GET",
            "statusCallbackMethod" => "POST",
            "statusCallback" => "http://xxxx.com/twilio/call_xxx",
            "statusCallbackEvent" => array(
                "answered"
            )
        )
    );

以及处理 webhook 请求的代码:

    //Use the Twilio PHP SDK to build an XML response
    $response = new Twiml();

    //If the user entered digits, process their request
    if(array_key_exists('Digits', $_POST)) {
        switch ($_POST['Digits']) {
            case 1:
                $dial = $response->dial();
                $dial->number($phone);
                break;
            default:
                $response->say('Goodbye.');
        }
    } else {

        //If no input was sent, use the <Gather> verb to collect user input
        $gather = $response->gather(array('numDigits' => 1));

        // use the <Say> verb to request input from the user
        $gather->say("This is xxx. $name just requested a voucher. Press 1 to connect with them now.");

        // If the user doesn't enter input, loop
        $response->redirect('/twilio/call_xxxx');
    }

    //Render the response as XML in reply to the webhook request
    header('Content-Type: text/xml');
    echo $response;

我在哪里犯错了?

【问题讨论】:

    标签: php twilio twilio-api twilio-php twilio-click-to-call


    【解决方案1】:

    你在这里犯了一个错误,根据你的代码:

    "url" => "http://demo.twilio.com/docs/voice.xml",
    "method" => "GET",
    

    应该是:


    "url" => "http://xxxx.com/twilio/call_xxx",
    "method" => "POST",
    

    获取调用流的 TwiML 并传递您正在寻找的 Digits

    至于statusCallback,如果需要,您必须使用不同的代码创建另一个端点(与跟踪呼叫状态有关)。

    我建议,先让它在没有 statusCallback 的情况下工作(你可以暂时删除 statusCallback... 行)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-15
      相关资源
      最近更新 更多