无法使用"换行符"生成XML响应(对于TwiML响应)

时间:2016-03-21 10:57:20

标签: xml meteor newline twilio twiml

周一快乐,

我正在使用TwiML使用Meteor和Twilio(发送短信)构建一个非常简单的应用。

然而,我感到困惑:我不知道如何使用换行符发送回复(html <br>的种类)。 在我的简单功能下面:

function xyz(message) {
    response.setHeader('Content-Type', 'application/xml');
    response.statusCode = 200;
    var toSend = "<Response><Message>" + message + "</Message></Response>";
    response.end(toSend);}

toSend因此:

<Response>
   <Message>The quick brown fox jumps over the lazy dog. Portez ce vieux whisky au juge blond qui fume</Message>
</Response>

虽然我想(例如):

<Response>
   <Message>The quick brown fox jumps over the lazy dog.

    Portez ce vieux whisky au juge blond qui fume
   </Message>
</Response>

我无法使用\n[CDATA]来使用<br>

我尝试使用XMLbuilder(https://atmospherejs.com/meteor/xmlbuilder)。 但是我没有成功地使它发挥作用..

1 个答案:

答案 0 :(得分:1)

Twilio开发者传道者在这里。

我刚刚使用Express应用程序进行了一项小测试,请查看以下函数:

router.post("/twilio/messages", function(req, res, next) {
  res.set('Content-Type', 'application/xml');
  var message = "Hello\n\nPhil";
  res.send("<Response><Message>"+message+"</Message></Response>");
});

这会向我的手机返回一条消息,如下所示:

  

您好

     

菲尔

我不确定ES2015 Meteor支持多少,但您也可以使用JavaScript中的多行字符串实现换行符(请注意反引号而不是引号)。

var message = `Hello

Phil`;

让我知道这是否有帮助。