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:
Please help me..
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..
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
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
Hi Reza,
Please find below a link to a thread in the forum where sending HTMl in the Chat message is described in details:
- https://www.telerik.com/forums/kendo-chat-control-for-jquery#5746339
I hope this helps.
Regards,
Neli