QnA Maker bot on Teams - apostrophe problem
Hi, I've made a QnA Maker knowledge base and one answer has an apostrophe that in Teams returns a different encoding in the response, for example, the answer to one question in Teams to my bot was:
My name is bombot. I'm a bill of materials bot for the training team. I provide links to resources.
A general tip for watching that your utilization of apostrophes is right is to change the phrase around so that the part before the apostrophe turns into the last word. If it still has a similar meaning, the meaning, was right.
Are you seeing this in the Teams web client, desktop, or ? In the emulator, I can replicate the problem if I display in monotype (e.g. type `'` gets '), but in emulator only...
Hi, The QnA Maker returns string as HTML encoded format. Unfortunately some clients like Teams do not decode before rendering. We have raised this issue with them.
As a work around for now you can decode before you send the message yourself:
/// <summary>
/// Simple Dialog, that invokes the QnAMaker if the incoming message is a question
/// </summary>
[Serializable]
public class FAQDialog : IDialog<object>
{
public async Task StartAsync(IDialogContext context)
{
context.Wait(MessageReceivedAsync);
}
public async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> argument)
{
var message = await argument;
await context.PostAsync(WebUtility.HtmlDecode(CallQnAMaker(message.Text)));
context.Wait(MessageReceivedAsync);
}
public string CallQnAMaker(string query)
{
string responseString = string.Empty;
var knowledgebaseId = <your KB ID>; // Use knowledge base id created.
var qnamakerSubscriptionKey = <your subscription key>; //Use subscription key assigned to you.
//Build the URI
Uri qnamakerUriBase = new Uri("https://westus.api.cognitive.microsoft.com/qnamaker/v1.0");
var builder = new UriBuilder($"{qnamakerUriBase}/knowledgebases/{knowledgebaseId}/generateAnswer");
//Add the question as part of the body
var postBody = $"{{\"question\": \"{query}\"}}";
//Send the POST request
using (WebClient client = new WebClient())
{
client.Encoding = System.Text.Encoding.UTF8;
//Add the subscription key header
client.Headers.Add("Ocp-Apim-Subscription-Key", qnamakerSubscriptionKey);
client.Headers.Add("Content-Type", "application/json");
responseString = client.UploadString(builder.Uri, postBody);
}
QnAMakerResult response;
try
{
response = JsonConvert.DeserializeObject<QnAMakerResult>(responseString);
}
catch
{
throw new Exception("Unable to deserialize QnA Maker response string.");
}
}
//Callback, after the QnAMaker Dialog returns a result.
public async Task AfterQnA(IDialogContext context, IAwaitable<object> argument)
{
context.Wait(MessageReceivedAsync);
}
}
class QnAMakerResult
{
/// <summary>
/// The top answer found in the QnA Service.
/// </summary>
[JsonProperty(PropertyName = "answer")]
public string Answer { get; set; }
/// <summary>
/// The score in range [0, 100] corresponding to the top answer found in the QnA Service.
/// </summary>
[JsonProperty(PropertyName = "score")]
public double Score { get; set; }
}
@michhar, I'm assuming @pchoudhari's answer helped you out mitigating the issue, so I'm closing this as resolved. Please feel free to reopen it if this is not the case. Thanks!
Hi all, I'm facing the same problem when I use QnA active learning with Node Js. As you can see in the photo the problem arise when the bot should print "special" characters like "è" "cos'è" and so on...
Any suggestion about solving the problem? I was reading about using npm package named decode-html but I really don't know how to apply it and where cause I debugged the code finding html pages or similar with poor results.
Thanks

I also faced this issue, then I created the message with below formats in MS bot Code(app.js).
var customMessage = new builder.Message(session)
.text("I didn't quite get that. For us ......")
.textFormat("plain")
.textLocale("en-us");
session.send(customMessage);
Refer Official URL for V3: https://docs.microsoft.com/en-us/azure/bot-service/nodejs/bot-builder-nodejs-message-create?view=azure-bot-service-3.0