Reputation: 439
This is my current screen when I have tried to load my bot into the bot Framework Emulator:
And this is what I have entered within the setting for my bot:
But for some reason my bot framework emulator remains empty. I have also tried setting the Endpoint URL to http://localhost:3979/api/messages but no luck. I am trying to run this locally off of visual studio.
Any help with this is much appreciated!
Upvotes: 0
Views: 677
Reputation: 2613
One of the possible solution you can do is:
Right click your project in Solution Explorer in Visual Studio.
Click Properties.
Go to Debug Tab. Scroll down a little bit you will see Web Server Settings.. Check the URL and set it to new port. For example if it is: http://localhost:3798 change it to http://localhost:3979 or vice-versa. Changing the port number might solve your issue. Press Ctrl + S to save it.
Build the solution and re-run the project without Debugging (Ctrl +F5).
Open your Bot Framework Emulator and enter the URL that you mentioned in step 3 above.
Note: This doesn't mean it will 100% work, but this is one of the solution that I come across. I had the same problem and I solved it same way.
Hope this helps.
Upvotes: 0
Reputation: 1204
L. Full, if you followed the instructions from the Azure portal to create a QnA bot from a template, you will need to tweak the code a bit to have it work locally, and in turn work in the emulator.
After you have created your bot using the template (which it sounds like you have done), in ABS, going to Build (under Bot Management)> "Download zip file", you get a copy of your project locally.
If you look at the template Bot code, it works in Azure, because in summary, it is accessing your QnA credentials from within your Application Settings inside the Azure portal, but locally you will need to put the credentials somewhere like your .config file.
Ultimately what we'll have to do now is plug in your QnA credentials into your .config file of your project, as this is not automatically downloaded into the code when you download the zip.
Below I'm just using the QnA Template bot that you can find in the Azure portal (Create Resource > AI + Machine Learning > Web App Bot with Bot template of "Question and Answer")
In Web.config add key-value pairs for AzureWebJobsStorage (if using), QnAAuthKey, QnAKnowledgebaseId, and QnAEndpointHostName Your own credential values can be found under Application Settings of the Azure portal
<appSettings>
<!-- update these with your Microsoft App Id and your Microsoft App Password-->
<add key="MicrosoftAppId" value="" />
<add key="MicrosoftAppPassword" value="" />
<add key="AzureWebJobsStorage" value="DefaultEndpointsProtocol=https...."/>
<add key="QnAAuthKey" value="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" />
<add key="QnAKnowledgebaseId" value="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" />
<add key="QnAEndpointHostName" value="https://YOURQNA.azurewebsites.net/qnamaker" />
<add key="QnASubscriptionKey" value="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" />
</appSettings>
In your Dialog (QnA template as of 7/5/18 has default dialog file named BasicQnAMakerDialog.cs), instead of Utils (default in template), we'll use ConfigurationManager.AppSettings["KeyName"] to access the values you just placed in your Web.config: Below you can see I've changed the variables (commented out) in QnA template to retrieve values using ConfigurationManager.AppSettings. You may also have to edit the variables in your if-statement as well, depending on the logic your own app needs.
In Root Dialog
private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> result)
{
var message = await result as Activity;
// OLD
//var qnaAuthKey = GetSetting("QnAAuthKey");
//var qnaKBId = Utils.GetAppSetting("QnAKnowledgebaseId");
//var endpointHostName = Utils.GetAppSetting("QnAEndpointHostName");
// NEW
var qnaAuthKey = ConfigurationManager.AppSettings["QnAAuthKey"];
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.");
}
}
For example in BasicQnAMakerDialog:
[Serializable]
public class BasicQnAMakerDialog : QnAMakerDialog
{
static readonly string qnaAuthKey = ConfigurationManager.AppSettings["QnAAuthKey"];
static readonly string qnaKBId = ConfigurationManager.AppSettings["QnAKnowledgebaseId"];
static readonly string endpointHostName = ConfigurationManager.AppSettings["QnAEndpointHostName"];
public BasicQnAMakerDialog() : base(new QnAMakerService(
new QnAMakerAttribute
(
qnaAuthKey,
qnaKBId,
"No good match in FAQ.",
0.5,
1,
endpointHostName
)))
{
}
}
Upvotes: 3