簡體   English   中英

在通過twilio的出站呼叫中,如何給用戶選擇並做出相應的響應?

[英]How can I give user choices and respond to them accordingly, in an outbound call via twilio?

我試圖在他們的文檔中找到解決方案。 但是我發現最接近我的查詢的是這個; https://www.twilio.com/docs/guides/how-to-gather-user-input-via-keypad-in-php#collect-user-input-with-the-gather-twiml-verb ; 這是為了打進來的電話,而不是像我現在需要的去電。 任何幫助將不勝感激,謝謝大家!

這是一些讓您入門的東西。

撥打語音電話:
// page located at http://example.com/make_call.php —>

<?php
require __DIR__ . '/vendor/autoload.php';
use Twilio\Rest\Client;

// Your Account SID and Auth Token from twilio.com/console
$account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
$auth_token = 'your_auth_token';
// In production, these should be environment variables. E.g.:
// $auth_token = $_ENV["TWILIO_ACCOUNT_SID"]

// A Twilio number you own with SMS capabilities
$twilio_number = "+15017122661";

// Where to make a voice call (your cell phone?)
$to_number = "+15558675310";

$client = new Client($account_sid, $auth_token);
$client->account->calls->create(  
    $to_number,
    $twilio_number,
    array(
        "url" => "http://example.com/complex_gather.xml"
    )
);

https://www.twilio.com/docs/quickstart/php/programmable-voice?code-sample=code-make-a-voice-call&code-language=php&code-sdk-version=5.x


收集輸入:
// page located at http://example.com/complex_gather.xml (以內容類型XML響應)

<?xml version="1.0" encoding="UTF-8"?>

<Response>
    <Gather action="process_gather.php" method="POST">
        <Say>
            Please enter your account number,
            followed by the pound sign
        </Say>
    </Gather>
    <Say>We didn't receive any input. Goodbye!</Say>
</Response>

https://www.twilio.com/blog/2016/09/hitchhikers-guide-to-twilio-programmable-voice.html


流程數字:
// page located at http://example.com/process_gather.php

<?php

    if (empty($_POST["Digits"])) {
        // process digits

    } else {
        // do something

    }

?>

https://www.twilio.com/blog/2012/04/build-a-simple-phone-verification-with-twilio-php-mysql-and-jquery.html

我已經完成了這項任務; 我能夠撥打電話並從用戶的撥號器(DTMF)中獲得選擇; 但是我在保存這些用戶輸入時使用的文件上出現解析錯誤; 這是我正在使用Twilio \\ Twiml對象的twiml對象的結構

(
    [element:protected] => SimpleXMLElement Object
        (
            [Say] => Please enter 1 for yes, 9 for no as we try to verify your identity:
            [Gather] => Array
                (
                    [0] => SimpleXMLElement Object
                        (
                            [@attributes] => Array
                                (
                                    [numDigits] => 1
                                    [action] => https://accounts.onsitecrm.com/test_twillo/post_script.php?q=1&id=632
                                    [method] => POST
                                )

                            [Say] => Is your full name Ammad Farooqi
                        )

                    [1] => SimpleXMLElement Object
                        (
                            [@attributes] => Array
                                (
                                    [numDigits] => 1
                                    [action] => https://accounts.onsitecrm.com/test_twillo/post_script.php?q=2&id=632
                                    [method] => POST
                                )

                            [Say] => Are the last 4-digits of your Social Security Number 1234 
                        )

                    [2] => SimpleXMLElement Object
                        (
                            [@attributes] => Array
                                (
                                    [numDigits] => 1
                                    [action] => https://accounts.onsitecrm.com/test_twillo/post_script.php?q=3&id=632
                                   [method] => POST
                               )
                            [Say] => Is your Date of Birth 24th of June, 1996?
                       )
                )
        )
)

這是存儲用戶憑據的文件的結構;

$question = (int)$_GET['q'];
$leadid = (int)$_GET['id'];
$input = null;
$get = $_POST['Digits'];    //Digits Pressed

if (array_key_exists('Digits', $_POST)) {
    $x=$_POST['Digits'];
   if($x==1){
       $input = 'YES';
      //do nothing, all good
   }elseif($x==3){
       $input = 'Not Applicable';
       //do nothing
   }elseif($x==9){
       $input = 'NO';
       if($question>8){
           //call enrollment rep
       }
   }else{
       $input = "Not Recognized, Repeat The Question";
   }
}

$data = array();
$data['leadid'] = $leadid;
$data['question'] = $question;
$data['input'] = $input;
$data['get'] = $get;

$fh = fopen('/usr/share/nginx/html/usr_input.1.txt', 'a') or die("Can't open file.");
$results = print_r( $data, true);
fwrite($fh, $results);
fclose($fh);


$sql = "SELECT * FROM `tblcompcall` WHERE `leadid` = '$leadid'";
$resp = clsdatabase::runQuery($sql);
$num = mysqli_num_rows($resp);
if($num != 0){
    $sql = "UPDATE `tblcompcall` SET `q$question` = '$input' WHERE `leadid` = '$leadid'";
    $result  = clsdatabase::runQuery($sql);
}else{
    $sql = "INSERT INTO `tblcompcall` (`leadid`, `q$question`) VALUES ('$leadid', '$input')";
    $result  = clsdatabase::runQuery($sql);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM