2017-02-13 68 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中检索这些响应。

相关问题