Kendo Chat , Text format problem

0 Answers 17 Views
Chat
Deniz
Top achievements
Rank 1
Deniz asked on 21 Mar 2024, 02:24 PM
Hello Everyone, 
I use Kendo Chat. the user writes a text (promt). this prompt goes to my endpoint and returns a response. i print this response back to the chat, but there is a problem. for example, the incoming text : 
"
This is a sample article. Sample text.
Sample text on the second line.
Sample text in the third line.
Sample text in the fourth line.
"
This is what the output looks like when I print it: 
"
This is a sample article. Sample text, sample text on the second line, sample text on the third line, sample text on the fourth line.
"

I'm tired of searching for a solution. I can't find it.
My code snippet: 



  $.ajax({
            url: SendPrompt.fmt(encodedMessage, encodedUserName), 
            async: true,
            contentType: 'application/json',
            type: "POST",
            dataType: "json",
            processData: false,          
            headers: { Authorization: tokenData() },
            beforeSend: setHeader,
            success: function (data) { 
                    var answer = data.Answer.replace(/(?:\r\n|\r|\n)/g, '\n\n');                   
                chat.renderMessage({
                    type: "MyText",
                    text: answer 
                }, {
                    id: kendo.guid(),
                    name: gptName
                });
            }, error: function (jqXHR, textStatus, errorThrown) {
                console.log("Status:", textStatus);
            },
            complete: function () {
                messageTemplate.animate({ opacity: 0 }, 500, function () {
                    $(this).css({ display: 'none' });
                });
                chat.wrapper.find(".k-input").prop('disabled', false);
                chat.wrapper.find(".k-button-send").prop('disabled', false);
            }
        });

Please help me..
Neli
Telerik team
commented on 26 Mar 2024, 07:47 AM

Hi Deniz,

Could you please try to log the value of the answer variable right before using it in the renderMessage method and check its value? I have tested the appearance when the string contains \n or \n\n and as you will see in the Dojo linked here the new lines are correctly added.

Looking forward to your reply.

Regards,

Neli

Deniz
Top achievements
Rank 1
commented on 26 Mar 2024, 06:37 PM

Hello Neli, first of all thank you for your reply. But I don't completely understand what you mean, do you have a chance to show it as code? By the way, on the trial page of the kendo chat template in the web page, you can use \n to move to a new line. But it does not happen in my project. where exactly should I make changes? This is very important for me. thank you.
Neli
Telerik team
commented on 29 Mar 2024, 12:39 PM

Hi Deniz,

In the Dojo example I have sent in my previous reply, the messages are displayed with new lines when the text value is added as demonstrated below:

 chat.renderMessage({
        type: "text",
        text: "This is a sample article. \n\n Sample text. \n Second line. \n\n Third line. \n\n Forth line."
    }, chat.getUser());

Could you please double check if the characters for the new lines are correctly added to the string used as a text in the application on your side?

Regards,

Neli

No answers yet. Maybe you can help?

Tags
Chat
Asked by
Deniz
Top achievements
Rank 1
Share this question
or