2017-02-18 51 views
0

我想用自定义变量来初始化一个调用。Twilio创建呼叫 - 张贴参数?

由于twilio状态,the call is initiated by making a post request to the url provided

var client = require('twilio')(accountSid, authToken); 

client.calls.create({ 
    url: "http://demo.twilio.com/docs/voice.xml", 
    to: "+14155551212", 
    from: "+1544444444" 
}, function(err, call) { 
    process.stdout.write(call.sid); 
}); 

如果文件voice.xml具有可变{{firstName}}

如何发布body.firstName?什么是适当的方式来格式化在XML一侧?谢谢

回答

0

Twilio开发者传道这里。

如果您需要通过该URL传递信息,则可以将其作为URL参数。例如:

var client = require('twilio')(accountSid, authToken); 

client.calls.create({ 
    url: "http://example.com/voice.xml&firstName=Phil", 
    to: "+14155551212", 
    from: "+1544444444" 
}, function(err, call) { 
    process.stdout.write(call.sid); 
}); 

然后,当你处理这个incoming POST request from Twilio,你可以自己检索URL参数。如果您使用Express作为服务器,它看起来有点像这样:

var express = require('express'); 
var twilio = require('twilio'); 

var app = new express(); 

app.post('/voice.xml', function(request, response) { 
    var firstName = request.query.firstName; 
    var twiml = new twilio.TwimlResponse(); 
    twiml.say('Hello ' + firstName + '! How are you today?'; 
    response.set('Content-Type', 'text/xml'); 
    response.send(twiml.toString()); 
}); 

让我知道这是否有助于在所有。