如何在node.js中创建有效的TwilioML响应对象(How to create a valid TwilioML response object in node.js)

编程入门 行业动态 更新时间:2024-10-22 21:32:28
如何在node.js中创建有效的TwilioML响应对象(How to create a valid TwilioML response object in node.js)

我有一个twilio webhook,我试图按照twiloML构建响应,我在twilio日志中得到错误响应

12200提供的XML不符合Twilio标记XML架构。 请参阅具体错误并更正问题。

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()) }); }); ...

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

12200 The provided XML does not conform to the Twilio Markup XML schema. Please refer to the specific error and correct the problem.

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()) }); }); ...

最满意答案

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() }); });

更多推荐

本文发布于:2023-08-03 13:52:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1391984.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:对象   如何在   js   node   object

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!