如何修复此代码以允许它编译?

问题描述 投票:0回答:2

我正在尝试为hubot编写脚本,似乎我有一个未封闭的字符串。内容将以html格式显示,表情符号如下:smile:等。它不是在Cofeescript中编译。我是javascript的新手,任何帮助将不胜感激。

我得到的错误是

 ERROR Unable to load /var/discourse/avebot/scripts/test: /var/discourse/avebot/scripts/test.js:5
    msg.reply("Hello! I’m Avebot, and I will be your guide throughout your training. :smile: <br>
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

SyntaxError: Invalid or unexpected token
  at new Script (vm.js:51:7)

并且脚本是:

robot.hear(/hi bot/, function(msg) {

    msg.reply("Hello! I’m a bot, and I will be your guide your training. :smile: <br>

<br>After finishing this training, you will be able to do x y z. :tada:<br>
Are you ready? If so, let me know you are ready by replying 'yes I’m ready!'");

    //Start a dialog with the user that sent this message.
    var dialog = switchBoard.startDialog(msg);

    //Provide choices for the next step, wait for the user.
    dialog.addChoice(/yes/, function(msg2){  msg2.reply('Okay');}

    dialog.addChoice( /no/, function(msg2){    msg2.reply("Okay, I'll wait"); }

    //The dialog will expire after 30 secods.
});
hubot
2个回答
0
投票

你需要通过在撇号之前放一个反斜杠来逃避'中的I'm Avebot(所以它是I\'m Avebot)。

有关JS转义序列的更多信息,请查看this站点。


0
投票

为了在Javascript中定义多行字符串,您可以在新行之前使用反斜杠\

msg.reply("Hello! I’m a bot, and I will be your guide your training. :smile: <br>\
<br>After finishing this training, you will be able to do x y z. :tada:<br>\
Are you ready? If so, let me know you are ready by replying 'yes I’m ready!'");
© www.soinside.com 2019 - 2024. All rights reserved.