Bot Framework模拟器(v4)无法正常工作-POST 202 [英] Bot Framework Emulator (v4) not working - POST 202

查看:63
本文介绍了Bot Framework模拟器(v4)无法正常工作-POST 202的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近使用Microsoft Azure的Cognitive Services和Bot Framework作为主要工具QnA Maker创建了一个聊天机器人.在开发甚至发布了bot几周后,我决定继续下一步并进行一些更改和优化,以使bot在本地运行.我设法将Azure代码的源代码从.Azure门户下载为.zip文件,用作IDE Visual Studio 2017,并用作测试工具Bot Framework Emulator(V4).

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

经过一段时间(以及很多问题,在 Azure Bot Framework仿真器错误-System.ArgumentNullException:值不能为空),我最终使代码在本地运行.但是,我仍然无法使用Bot Framework Emulator与之正确通信.似乎已连接,但是每次发送消息时,我都没有答案,只有一个POST 202 directline.postActivity,如下图所示:

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:

结果,我无法在Bot Framework Emulator中测试我的机器人.非常感谢你!

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!

推荐答案

要解决此问题,您可以在 MessagesController 中设置断点,并检查是否可以命中该断点,然后调试代码以检查您发送的消息是否可以到达 QnAMakerDialog .

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.

从Azure门户以.zip文件的形式下载源代码,用作IDE Visual Studio 2017,并用作我的测试工具Bot Framework Emulator(V4).

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

我使用Azure门户上的问答(C#)模板创建了一个bot服务,并下载了源代码,然后修改了代码并使用对我有效的Bot Framework Emulator在本地主机上对其进行了运行和测试.您可以将我的代码与您的代码进行比较,或者在您的QnA Maker知识库中测试我的代码,以检查它是否对您有用.

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:

这篇关于Bot Framework模拟器(v4)无法正常工作-POST 202的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆