2017-02-18 50 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()); 
}); 

讓我知道這是否有助於在所有。