使用 JavaScript 时向 Bot Framework 添加断线

Adding Break Lines to Bot Framework while using JavaScript

我使用 Microsoft bot Framework 并将其部署到 Web Chat,我的 bot 以正确的格式打印消息,并带有断行“\n\n”,然后我使用以下教程 https://github.com/microsoft/BotFramework-WebChat/blob/master/README.md 将JavaScript 与我的bot集成以删除附件图标(如下图所示)

使用 JavaScript 并删除附件图标后,我发现换行符 (\n) 已停止工作,

有谁知道发生了什么事吗?

以前的格式(不使用JavaScript):

line1

line2

当前格式(使用JavaScript):

line1
line2

在“wwwroot”中添加了以下代码以删除附件图标:

<!DOCTYPE html>
<html lang="en-US">
<head>
    <script crossorigin="anonymous" src="https://cdn.botframework.com/botframework-webchat/latest/webchat.js"></script>
</head>
<body>
    <div id="webchat" role="main"></div>
    <script>
    (async function () {
            window.WebChat.renderWebChat(
                {
                    directLine: window.WebChat.createDirectLine({ token: "MY-TOKEN" }),
                    styleOptions: {
                        markdownRespectCRLF: true,
                        // hide upload button
                        hideUploadButton: true
                    }
                },
                document.getElementById('webchat')
            );

            document.querySelector('#webchat > *').focus();
        })().catch(err => console.error(err));
    </script>
</body>
</html>

我要发送的 C# 代码 Activity:

string reply = "Line 1 \n\n Line 2";
await turnContext.SendActivityAsync(MessageFactory.Text(reply), cancellationToken);

试试这个:

IMessageActivity message = Activity.CreateMessageActivity();
message.Type = ActivityTypes.Message;
message.Text = "your \n text";
message.Locale = "en-Us";
message.TextFormat = TextFormatTypes.Plain;
await turnContext.SendActivityAsync(message);

当您在 Bot Framework 通道中插入空行时遇到问题,您可以尝试发送这样的消息以查看通道如何解释各种空白字符串:"1\n\n&nbsp;\n\n2\n\n\u00A0\n\n3\n\n\xA0\n\n4 \n5<br><br>6\n\n \n\n7 \r\n \r\n8<br/><br/>9\n&nbsp;\n10 \n11"

试试这个:

\n\n&nbsp;\n\n