c# - 无法将机器人链接到机器人框架模拟器

标签 c# azure botframework chatbot

这是我尝试将机器人加载到机器人框架模拟器时的当前屏幕:enter image description here

这是我在机器人设置中输入的内容:enter image description here

但由于某种原因,我的机器人框架模拟器仍然是空的。 我还尝试将端点 URL 设置为 http://localhost:3979/api/messages但没有运气。我正在尝试在 Visual Studio 本地运行它。

非常感谢您提供任何帮助!

最佳答案

L.已满,如果您遵循 instructions from the Azure portal to create a QnA bot from a template ,您需要稍微调整代码以使其在本地运行,然后在模拟器中运行。

使用模板创建机器人后(听起来您已经完成了),在ABS中,转到构建(在机器人管理下)> “下载 zip 文件”,您将在本地获得项目的副本。

如果您查看模板机器人代码,它可以在 Azure 中运行,因为总而言之,它是从 Azure 门户内的应用程序设置中访问您的 QnA 凭据,但在本地,您需要将凭据放置在 .配置文件。

最终我们现在要做的是将您的 QnA 凭据插入项目的 .config 文件中,因为当您下载 zip 时,它不会自动下载到代码中。

下面我只是使用 QnA 模板机器人,您可以在 Azure 门户中找到它(创建资源 > AI + 机器学习 > Web 应用程序机器人,机器人模板为“问题和答案”)

  1. Web.config中添加 AzureWebJobsStorage(如果使用)、QnAAuthKey、QnAKnowledgebaseId 和 QnAEndpointHostName 的键值对 您自己的凭据值可以在 Azure 门户的应用程序设置下找到

    <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. 在您的对话框中(截至 2018 年 7 月 5 日,QnA 模板具有名为 BasicQnAMakerDialog.cs 的默认对话框文件),而不是 Utils (模板中的默认值),我们将使用 ConfigurationManager.AppSettings["KeyName"] 来访问您刚刚放置在 Web.config 中的值: 您可以在下面看到我更改了 QnA 模板中的变量(已注释掉)以使用 ConfigurationManager.AppSettings 检索值。您可能还需要编辑 if 语句中的变量,具体取决于您自己的应用程序所需的逻辑。

在根对话框中

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

            }
  • 在由您的根调用的子对话框(例如 BasicQnAMakerDialog)中,请务必将任何调用 QnA key 的内容替换为 ConfigurationManager.AppSettings["KeyName"]
  • 例如在 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
                )))
            {
    
            }
        }
    

    关于c# - 无法将机器人链接到机器人框架模拟器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51186403/

    相关文章:

    c# - 设置 ASP.net 成员(member)资格和 MySQL 数据库的问题

    c# - Microsoft Graph API 更新其他用户的照片?

    c# - 如何在 ajax 请求后更改 URL?

    c# - ANTLR:我可以让 ',' 成为一个上下文中的一个标记,而另一个在所述上下文之外吗?

    azure - Azure 中的角色。查看发票的权限

    azure - Azure 聊天机器人中的 Logger 日志存储在哪里?

    c# - 将 Cortana channel 添加到 BOT 时凭据不起作用

    botframework - 创建新机器人时不断收到消息 "Bot profile pictures should be PNG and less than 30kB"

    c# - 在一组短字符串中查找非常常见的子字符串的算法

    c# - 从 Azure 数据湖下载文件