Bot框架模拟器(v4)无法正常工作 - POST 202

时间:2018-05-16 15:40:34

标签: c# azure botframework

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

经过一段时间(以及很多问题,在Azure Bot Framework Emulator Error - System.ArgumentNullException: Value cannot be null中解决了),我终于让代码在本地运行了。尽管如此,我还是无法使用Bot Framework Emulator与它进行正确的通信。它似乎已连接,但每次我发送消息时,我都没有答案,只有POST 202 directline.postActivity,如下图所示:

Bot framework not working

因此,我无法在Bot框架模拟器中测试我的机器人......任何人都可以帮我找出发生了什么?非常感谢你!

2 个答案:

答案 0 :(得分:1)

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

enter image description here

  

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

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

[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"])))
    { }

}

测试结果:

enter image description here

答案 1 :(得分:0)

当您本地调试时,如果您还没有注释 Azure表存储设置部分代码,请尝试注释。这应该可以解决你的问题。

否则,如果你不想评论你的东西,你可以试试这个:

// Basically you need to check the environment if(process.env.BotEnv === 'prod') { bot.set('storage', tableStorage); }