如何在node.js中创建有效的TwilioML响应对象(How to create a valid TwilioML response object in node.js)
我有一个twilio webhook,我试图按照twiloML构建响应,我在twilio日志中得到错误响应
const twilio = require('twilio'); function defaultTwilioSuccess(){ var response = new twilio.twiml.MessagingResponse(); response.message('its alive'); return response.toString(); } exports.handler = function(event, context, callback){ ... .then(function() { return callback(null, { "statusCode": 200, "headers": {'Content-Type': 'text/xml'}, "body": JSON.stringify(defaultTwilioSuccess()) }); }); ...12200提供的XML不符合Twilio标记XML架构。 请参阅具体错误并更正问题。
I have a twilio webhook and I'm trying to structure the response with accordance with twiloML, I get an error response in twilio logs of
const twilio = require('twilio'); function defaultTwilioSuccess(){ var response = new twilio.twiml.MessagingResponse(); response.message('its alive'); return response.toString(); } exports.handler = function(event, context, callback){ ... .then(function() { return callback(null, { "statusCode": 200, "headers": {'Content-Type': 'text/xml'}, "body": JSON.stringify(defaultTwilioSuccess()) }); }); ...12200 The provided XML does not conform to the Twilio Markup XML schema. Please refer to the specific error and correct the problem.
最满意答案
JSON.stringify在这种情况下不需要,因为它的响应是XML格式
return callback(null, { "statusCode": 200, "headers": {'Content-Type': 'text/xml'}, "body": defaultTwilioSuccess() }); });the JSON.stringify , is not needed in this case since its the respone is an XML format
return callback(null, { "statusCode": 200, "headers": {'Content-Type': 'text/xml'}, "body": defaultTwilioSuccess() }); });更多推荐
发布评论