0

I integrated a LUIS and QNA Maker Microsoft bot and created a webchat bot. The bot works perfectly fine however when I type a question with single quote (') or apostrophe in it the bot responds Sorry, my bot code is having an issue. For example if I type: "I am a diplomat" it gives me the answer that I trained it on. However, if I type: "I'm a diplomat" the bot responds "Sorry, my bot code is having an issue." I put the utterances in my LUIS app with apostrophe and the score is pretty high testing it but when I ask the bot in online test environment it has issues with any question or statements that has apostrophe in it.

Has anyone ever faced this issue? I searched for almost a day, no luck. Thanks.

Breeze
  • 29
  • 2
  • Seems like its not hitting the LUIS api when you put a single quote('). It must be breaking before that. Can confirm that if you look at the LUIS endpoint hits(last column) against your application in the 'My Apps' page? If its not changing then it should be the code in the project that must be looked into. – Tony Thomas Dec 23 '18 at 03:41
  • @TonyMathew Thanks. I think the problem is from this code:string questionJSON = @"{'question': '" + question + "'}"; I think that's why it doesn't understand single quote in any questions. I put single quote at the end of the question and it gives me the same error. – Breeze Dec 23 '18 at 06:14

1 Answers1

1

As suggested by Tony Mathew and given your reply, you are not sending the sentence properly to LUIS.

Here:

string questionJSON = @"{'question': '" + question + "'}";

You should encode the question variable to avoid this single quote which is breaking the JSON content.

Nicolas R
  • 13,812
  • 2
  • 28
  • 57
  • Thanks @Nicolas R. Do you know any resources that could help me recontruct the JSON content? I am fairly new at coding in C#. Any suggestions are much appreciated. – Breeze Dec 24 '18 at 20:53
  • A simple ".Replace("'", "''") should be enough – Nicolas R Dec 24 '18 at 21:14
  • 1
    @TonyMathew ; I played with that line of code for hours, .Replace did not work as Nicolas suggested. I tried this and it works with single quote having no issues: string questionJSON = "{\"question\": \""+ question+"\"}"; – Breeze Dec 28 '18 at 15:50
  • In order to handle both single and double quotes in the text of the chatbot, I've altered the answer to string questionJSON = "{\"question\": \"" + question.Replace("\"","'") + "\"}"; – DFBerry Jan 30 '19 at 23:30