Cannot link bot to bot framework emulator

瘦欲@ 提交于 2019-12-11 15:02:45

问题


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!


回答1:


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")

  1. 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>
    
  2. 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.");
                }

            }
  1. In the children Dialogs that get called by your root (BasicQnAMakerDialog for example), be sure to also replace anything that calls for a QnA key with ConfigurationManager.AppSettings["KeyName"].

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
            )))
        {

        }
    }


来源:https://stackoverflow.com/questions/51186403/cannot-link-bot-to-bot-framework-emulator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!