Reputation: 1438
I recently created a chatbot using Microsoft Azure's Cognitive Services and Bot Framework, using as the main tool QnA Maker. After some weeks developing and even publishing the bot, I decided to go to the next steps and make some changes and optimizations that requires the bot running locally. I managed to download the source code from Azure's portal as a .zip file, using as IDE Visual Studio 2017 and using as my test tool Bot Framework Emulator (V4).
After some time (and a lot of issues, solved in Azure Bot Framework Emulator Error - System.ArgumentNullException: Value cannot be null), I finally made the code run locally. Still, I am being unable to properly communicate with it using Bot Framework Emulator. It seems to be connected, but everytime I send a message, I get no answer but a POST 202 directline.postActivity
, as the image below shows:
As a consequence, I am unable to test my bot in the Bot Framework Emulator... Could anyone help me to find out what is going on? Thank you very much!
Upvotes: 0
Views: 714
Reputation: 27793
To troubleshoot the issue, you could set the breakpoint in MessagesController and check if it can be hit, and debug your code to check if the message you sent can reach your QnAMakerDialog.
download the source code from Azure's portal as a .zip file, using as IDE Visual Studio 2017 and using as my test tool Bot Framework Emulator (V4).
I create a bot service using Question and Answer (C#) template on Azure portal and download the source code, then modify the code and run&test it on local host with Bot Framework Emulator, which works for me. You can compare my code with yours, or test my code with your QnA Maker knowledge base to check if it can work for you.
[Serializable]
public class RootDialog : IDialog<object>
{
public async Task StartAsync(IDialogContext context)
{
/* Wait until the first message is received from the conversation and call MessageReceviedAsync
* to process that message. */
context.Wait(this.MessageReceivedAsync);
}
private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> result)
{
/* When MessageReceivedAsync is called, it's passed an IAwaitable<IMessageActivity>. To get the message,
* await the result. */
var message = await result;
var qnaAuthKey = GetSetting("QnAAuthKey");
//var qnaKBId = Utils.GetAppSetting("QnAKnowledgebaseId");
var qnaKBId = ConfigurationManager.AppSettings["QnAKnowledgebaseId"];
var endpointHostName = ConfigurationManager.AppSettings["QnAEndpointHostName"];
// QnA Subscription Key and KnowledgeBase Id null verification
if (!string.IsNullOrEmpty(qnaAuthKey) && !string.IsNullOrEmpty(qnaKBId))
{
// Forward to the appropriate Dialog based on whether the endpoint hostname is present
if (string.IsNullOrEmpty(endpointHostName))
await context.Forward(new BasicQnAMakerPreviewDialog(), AfterAnswerAsync, message, CancellationToken.None);
else
await context.Forward(new BasicQnAMakerDialog(), AfterAnswerAsync, message, CancellationToken.None);
}
else
{
await context.PostAsync("Please set QnAKnowledgebaseId, QnAAuthKey and QnAEndpointHostName (if applicable) in App Settings. Learn how to get them at https://aka.ms/qnaabssetup.");
}
}
private async Task AfterAnswerAsync(IDialogContext context, IAwaitable<IMessageActivity> result)
{
// wait for the next user message
context.Wait(MessageReceivedAsync);
}
public static string GetSetting(string key)
{
//var value = Utils.GetAppSetting(key);
var value = ConfigurationManager.AppSettings[key];
if (String.IsNullOrEmpty(value) && key == "QnAAuthKey")
{
//value = Utils.GetAppSetting("QnASubscriptionKey"); // QnASubscriptionKey for backward compatibility with QnAMaker (Preview)
value = ConfigurationManager.AppSettings["QnASubscriptionKey"];
}
return value;
}
}
// Dialog for QnAMaker Preview service
[Serializable]
public class BasicQnAMakerPreviewDialog : QnAMakerDialog
{
// Go to https://qnamaker.ai and feed data, train & publish your QnA Knowledgebase.
// Parameters to QnAMakerService are:
// Required: subscriptionKey, knowledgebaseId,
// Optional: defaultMessage, scoreThreshold[Range 0.0 – 1.0]
public BasicQnAMakerPreviewDialog() : base(new QnAMakerService(new QnAMakerAttribute(RootDialog.GetSetting("QnAAuthKey"), ConfigurationManager.AppSettings["QnAKnowledgebaseId"], "No good match in FAQ.", 0.5)))
{ }
}
// Dialog for QnAMaker GA service
[Serializable]
public class BasicQnAMakerDialog : QnAMakerDialog
{
// Go to https://qnamaker.ai and feed data, train & publish your QnA Knowledgebase.
// Parameters to QnAMakerService are:
// Required: qnaAuthKey, knowledgebaseId, endpointHostName
// Optional: defaultMessage, scoreThreshold[Range 0.0 – 1.0]
public BasicQnAMakerDialog() : base(new QnAMakerService(new QnAMakerAttribute(RootDialog.GetSetting("QnAAuthKey"), ConfigurationManager.AppSettings["QnAKnowledgebaseId"], "No good match in FAQ.", 0.5, 1, ConfigurationManager.AppSettings["QnAEndpointHostName"])))
{ }
}
Test Result:
Upvotes: 1
Reputation: 632
When you're debugging locally, try commenting out the Azure Table Storage set up part of your code if you haven't already. This should solve your problem.
Or else, if you don't want to comment out your stuff, you can try this:
// Basically you need to check the environment
if(process.env.BotEnv === 'prod') {
bot.set('storage', tableStorage);
}
Upvotes: 0