2017-02-13 67 views
0

所以我下面的教程創建twilio的XML文檔等爲response, (https://www.twilio.com/blog/2013/03/introducing-the-twilio-module-for-node-js.html生成動態Twiml響應和保存的NodeJS服務器上

而不是發送它作爲迴應,我想在我的服務器上生成稍後訪問的文件。

像 - 本地主機/文件/ USERNAME/filename.xml中

這是我當前的代碼,該文件將作爲響應。


var resp = new twilio.TwimlResponse(); 

    resp.say({voice:'woman'}, 'Thanks for calling!'); 

    //Render the TwiML document using "toString" 
    res.writeHead(200, { 
     'Content-Type':'text/xml' 
    }); 

    res.end(resp.toString()); 

回答

0

Twilio開發者傳道這裏。

正如番茄指出的那樣,您可以使用來自Node的fs庫中的內部版本。你可以這樣做:

var resp = new twilio.TwimlResponse(); 

resp.say({voice:'woman'}, 'Thanks for calling!'); 

//Render the TwiML document using "toString" 
res.writeHead(200, { 
    'Content-Type':'text/xml' 
}); 

// Save the XML to disk, then return the response to Twilio. 
fs.writeFile('twilio-response.xml', resp.toString(), function(err) { 
    res.end(resp.toString()); 
}); 

您可能想爲每個響應生成一個唯一的文件名,以防止它們被覆蓋。

爲了防止這種情況發生,Twilio會保存您發回的TwiML響應,並且您可以在call log中檢索這些響應。

相關問題