Search code examples
botframework

Extra new line in Botframework V4 prompt


I write an Bot with Microsoft Botframework. In the newest version I got a problem with an extra new line on text prompts.

I want to display text like this:

Wenn Sie Ihre Eingabe so präzise wie möglich formulieren, kann ich Sie am besten verstehen und eine passende Antwort finden.

Diese Eingabe ist nicht sehr präzise:
"Kompetenzen Sollzinsänderung"

Schreiben Sie stattdessen doch lieber:
"Welche Kompetenzen benötige ich für die Änderung eines individuell vereinbarten Sollzinses?" 

I load this text from an resource file and send it via context.PromptAsync to the client. The client renderd it like this:

Wenn Sie Ihre Eingabe so präzise wie möglich formulieren, kann ich Sie am besten verstehen und eine passende Antwort finden.

Diese Eingabe ist nicht sehr präzise:
  
"Kompetenzen Sollzinsänderung"

Schreiben Sie stattdessen doch lieber:

"Welche Kompetenzen benötige ich für die Änderung eines individuell vereinbarten Sollzinses?"

I know that a markdown interpreter is used to render the text. Does someone know how to format the resource string, to get the first output?

Edit: My resource Text is as shown in the first code section.

The Code to get the resource text is as follows: BaseDialog.cs

public class BaseDialog : ComponentDialog{
    private readonly IStringLocalizer<BaseDialog> _stringLocalizer;
    public BaseDialog(string dialogId, IStringLocalizer<BAseDialog> stringLocalizer) : base(dialogId)
    {
        _stringLocalizer = stringLocalizer ?? throw new ArgumentNullException(nameof(stringLocalizer));

        AddDialog(new TextPrompt(PROMPTDIALOGID));
    }

    protected override async Task<DialogTurnResult> OnBeginDialogAsync(DialogContext innerDc, object options, CancellationToken cancellationToken = default)
    {
        var activity = GetActivity().AsMessageActivity();

        return await innerDc.PromptAsync(PROMPTDIALOGID, new PromptOptions
        {
            Prompt = (Activity)activity
        }, cancellationToken);
    }

    public virtual IActivity GetActivity()
    {
        return MessageFactory.Text(Localizer["Default_Response"]);
    }
}

HelpDialog.cs

public class HelpDialog : BaseDialog
{
    public HelpHandlingDialog(IStringLocalizer<BaseDialog> localizer)
        : base(nameof(HelpDialog), localizer)
    {
    }

    public override IActivity GetActivity()
    {
       return MessageFactory.Text(Localizer["Help_Response"]);
    }
}

We are using the Directline and test with BotFramework Emulator and for the users we are using the ReactWebchat. The described behaviour is present in both clients.


Solution

  • So one of my co-workers did the task and got a solution to the problem.

    These is the code to eliminate the extra new lines:

    BaseDialog.resx Wenn Sie Ihre Eingabe so präzise wie möglich formulieren, kann ich Sie am besten verstehen und eine passende Antwort finden.

    Diese Eingabe ist nicht sehr präzise: \\n "Kompetenzen Sollzinsänderung"
    
    Schreiben Sie stattdessen doch lieber:\\n “Welche Kompetenzen benötige ich für die Änderung eines individuell vereinbarten Sollzinses?”
    

    HelpDialog.cs

    public class HelpgDialog : BaseDialog
    {
        public HelpDialog(IStringLocalizer<BaseDialog> localizer)
            : base(nameof(HelpDialog), localizer)
        {
        }
    
        public override IActivity GetActivity()
        {
            return MessageFactory.Text(Localizer["Help_Response"].Value.Replace("\\n","\n"));
        }
    }