Twilio'AdwardUrl'未被传递给我的Parse Cloud Code

时间:2016-09-10 07:36:43

标签: javascript parse-platform cloud twilio twilio-php

我有一些php Twiml可以成功调用并记录它们,然后再触发一些Parse Cloud代码来检索RecordingUrl:

$response->dial($callee, array(action=>"https://myApp.parseapp.com/handleRecording", 'callerId'=>$callerId, record=>true));

我的Parse Cloud Code如下:

// Include Cloud Code module dependencies
var express = require('express'),
    twilio  = require('twilio');

var app = express();
twilio.initialize("ACr245kl2hj54245245324","252k5kjk5j4525234252525252b54v5"); 

app.post('/handleRecording', function(request, response){
         //var recUrl = request.body.RecordingUrl + ".wav";    // This is
         //var recUrl = request.params.RecordingUrl + ".wav";  // always nil
         console.log(request);
         console.log(response);
        });

问题在于没有响应Body,只有标题。状态代码为200,但它也表示未调用成功/错误。我在这里错过了什么?我希望其中一位着名的Twilio爱好者会来救援,因为我浪费了一天试图得到一个愚蠢的网址。输出如下:

结果:未调用成功/错误 { “域”:空, “_事件”:空, “_ maxListeners”:10, “方法”: “POST”, “URL”: “/ handleRecording”, “标题”:{ “缓存控制”:“MAX- age = 259200“,”content-length“:”567“,”content-type“:”application / x-www-form-urlencoded; charset = UTF-8“,”host“:”myApp.parseapp.com“ , “引荐”: “https://myAppsTwilioServer.herokuapp.com/twiml.php”, “用户代理”: “TwilioProxy / 1.1”, “版本”: “HTTP / 1.1”, “X-转发换”: “10.252.1.70”,”的x转发-原 “:” HTTPS “ ”X-twilio签名“: ”24958u49843985934579kjkjdf45 =“}, ”httpVersion“:[ ”HTTP / 1.1“, ”1.1“], ”连接“:{},” originalUrl “:”/ handleRecording “ ”_ parsedUrl“:{ ”协议“:NULL, ”斜线“:NULL, ”AUTH“:空, ”宿主“:NULL, ”端口“:NULL, ”主机名“:NULL,” 散列“:空,” 搜索 “:空,” 查询 “:空,” 路径 “:”/ handleRecording”, “路径”: “/ handleRecording”, “HREF”: “/ handleRecording”}, “查询”:{} , “资源”:{ “域”:空, “_事件”:空, “_ maxListeners”:10 “的StatusCode”:200, “headersSent”:假的, “sendDate”:真实的, “请求”:{}” viewCallbacks“:[],”_ hasConnectPatch“:true},”_ route_index“:0,”route“:{”pat ...(截断)

1 个答案:

答案 0 :(得分:1)

Twilio开发者传道者在这里。

Twilio sends data through a POST request时,它以编码的url参数形式执行。你需要从原始体中解析出来。

通常的方法是通过npm安装express body-parser模块,然后使用它来解析传入的请求主体,如下所示:

var express = require('express'),
    bodyParser = require('body-parser'),
    twilio  = require('twilio');

var app = express();
app.use(bodyParser.urlencoded({ extended: false }))
twilio.initialize("{{ AccountSid }}","{{ AuthToken }}"); 

app.post('/handleRecording', function(request, response){
         //var recUrl = request.body.RecordingUrl + ".wav";    // This is
         //var recUrl = request.params.RecordingUrl + ".wav";  // always nil
         console.log(request);
         console.log(response);
        });

让我知道这是否有帮助。