将变量传递给出站调用 TwiML [英] Passing Variables to Outbound Call TwiML

查看:40
本文介绍了将变量传递给出站调用 TwiML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个页面,该页面接收以 JSON 格式存储的信息.例如:

I am creating a page that takes in information stored as JSON. For example:

"PatientContactHeader":{  
  "PatientID":14,
  "PhoneNumber":"+1558881414",
  "ContactType":"Phone Call",
  "DateTimeOfCall":"2015-06-25: 11:00:00AM",
  "TimeZone":"EST"
 } "PatientContactDetails":[  
  {  
     "MessageID":123,
     "RecordingURL":"http://examplerecording.com",
     "MessageTitle":"Greeting"
  }
 ]
}

初始页面将接收此 JSON 并使用它来创建出站调用.根据 Twilio 的 API,出站向某个 TwiML Url 发出请求.

The initial page will take in this JSON and use it to create an outbound call. The outbound, as per Twilio's API, makes a request to a certain TwiML Url.

 function initiateCall($fromNumber, $toNumber, $url) {

try {
    // Initiate a new outbound call
    $call = $client->account->calls->create(
        $fromNumber, // The number of the phone initiating the call
        $toNumber, // The number of the phone receiving call
        $url, // The URL Twilio will request when the call is answered
        array('IfMachine' =>'Continue')
    );
    echo 'Started call: ' . $call->sid;
} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage();
}

}

我想要的是能够访问 TwiML 指令中的一些 JSON 信息.更具体地说,如果被调用的人应该接收多条消息,我希望能够遍历 JSON 数据并访问每条消息进行播放.我的问题是我不知道如何将信息从发出调用请求的初始页面传递到包含 TwiML 的页面.解决这个问题的合乎逻辑的方法似乎是会话变量,但我已经阅读(并发现)这些在进行出站调用时不起作用.这个问题有什么解决办法吗?

What I want is to be able to access some of the JSON information within the TwiML instructions. More specifically, if the person being called is supposed to receive multiple messages, I want to be able to loop through the JSON data and access each message for playback. My problem is that I know of no way to pass the information from the initial page that makes the call request to the page that contains the TwiML. The logical way to solve this problem would appear to be session variables but I have read (and found) that those do not work when making outbound calls. Is there any solution to this problem?

推荐答案

如果您已经有一个存储了此信息的数据库,那么处理此问题的最快方法是传递一段数据,您可以使用该数据在数据库上进行查询(可能是 TwiML url 的查询字符串中的 PatientID 或 MessageID},如下所示:

If you already have a database with this information stored then the quickest way to handle this would be passing a piece of data that you could use to query on the database (perhaps PatientID or MessageID} in the query string of the TwiML url like this:

  $call = $client->account->calls->create(
        $fromNumber, // The number of the phone initiating the call
        $toNumber, // The number of the phone receiving call
        $url . "?PatientID=" . $patientID, // The URL Twilio will request when the call is answered
        array('IfMachine' =>'Continue')
    );

然后在为您的 TwiML 提供服务的文件中,您可以像这样访问该数据:

Then within your file that's serving your TwiML you could access that data like this:

$patientID = $_GET['PatientID'];
// query your database with $patientID and get the info you need

希望有帮助!

这篇关于将变量传递给出站调用 TwiML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆