如何在node-js中添加换行符?

时间:2019-06-17 13:10:37

标签: node.js aws-lambda aws-lex

我正在尝试在lambda函数内的节点js中的两个字符串之间添加换行符。

我尝试使用'\ n','\ r \ n',还尝试导入os,然后使用os.EOL语句,但是这些都不起作用。

------------------------Using '\n'-------------------------------

var msg = `The order(s) for the customer ${CustomerNumber} and its status are ${data}`
msg+='\n'
msg+= ' To know the order details of another customer enter the customer 


-------------------------- Using '\r\n' -------------------------------
var msg = `The order(s) for the customer ${CustomerNumber} and its status are ${data}`
msg+='\n'
msg+= ' To know the order details of another customer enter the customer number'

-------------------------- Using 'os.EOL' -------------------------------
var os = require("os");
var msg = `The order(s) for the customer ${CustomerNumber} and its status are ${data}`+os.EOL+' To know the order details of another customer enter the customer number'


-------------- Sending msg string to the AWS lex bot----------------------
callback(elicitSlot(sessionAttributes, deliveryStatus, slots, "CustomerNumber", {

                        'contentType': 'PlainText',
                        'content': msg

                    } ));

function elicitSlot(sessionAttributes, intentName, slots, slotToElicit, message) {
    return {
        sessionAttributes,
        dialogAction: {
            type: 'ElicitSlot',
            intentName,
            slots,
            slotToElicit,
            message,
        },
    };
}

所有这些都具有节点效应,我得到的输出没有换行符并且是连续的字符串

我期望的输出是:“客户abcd的订单及其状态为1234、5678、9876” 要了解其他客户的订单详细信息,请输入客户编号'

我得到的输出是:“客户abcd的订单及其状态为1234、5678、9876”要知道其他客户的订单详细信息,请输入客户编号'

我认为这是因为我将内容类型指定为“纯文本”,有人可以建议我解决方案吗?

1 个答案:

答案 0 :(得分:0)

看起来有点旧,但是我在tutorial中找到了答案。要在邮件中使用html,您需要对邮件使用反引号。例如:

event.response.emailMessage = `<h1>Welcome to the App!</h1> <p>Your user name is ` + event.request.usernameParameter + `</p> <p>Your temporary password: ` + event.request.codeParameter + `</p> <p>If you need assistance, please contact the help desk at (555) 555-5555 or email <a href="mailto:help@example.org">help@example.org.</a></p>`;

希望这可以帮助其他人。