【问题标题】:how to show multiple message at a time in amazon lex如何在亚马逊 lex 中一次显示多条消息
【发布时间】:2020-11-03 14:39:41
【问题描述】:

嗨,我正在研究 amazon lex 和

  1. 想知道如何在 amazon lex 中换行以在下一行显示文本。我用过 \n 但它不起作用。查看屏幕截图。

  1. 我可以同时向用户显示 2 条消息吗?我是 lex 的新手,所以请指导我。谢谢。

【问题讨论】:

    标签: amazon-lex


    【解决方案1】:
    • Amazon lex 不支持新行。
    • 您可以在前端处理,例如在响应中保留 @newLine,如果您使用的是 Web 界面,则反映为下一行。
    • 您需要在前端编写自定义代码以更新新行中的响应。
    • 在下面的代码中,我使用标识符 @newLine 将响应插入为两条不同的消息。
    • 在 Ajax 调用响应或 SDK 调用响应中编写以下代码。

    <!DOCTYPE html>
    <html>
       <head>
          <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
          <script>
             $(document).ready(function(){
    
             //Add the botResponse in the Amazon lex.
             let botResponse = "This is a first response @newLine This is second response @newLine This is third response."
               
               let pushToChat = botResponse.split("@newLine")
             
               $("#btn2").click(function(){
                 pushToChat.forEach(res =>{
                $("ol").append(`<li>${res}</li>`);
               })
               });
             });
          </script>
       </head>
       <body>
          <p>This is a paragraph.</p>
          <ol>
             <li>List item 1</li>
             <li>List item 2</li>
             <li>List item 3</li>
          </ol>
          <button id="btn2">Append list items</button>
       </body>
    </html>
    • 希望以上代码对您有所帮助。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多