本文介绍了一段时间后,发布的C#Bot遇到内部服务器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在为我的公司创建一个聊天机器人,我从github上的示例和框架文档开始.

I'm creating a chatbot for my company and I started with the samples on github and the framework docs.

我们决定将其托管在Azure上,并向其中添加LUIS和表存储. Bot在Botframework Emulator中可以在本地正常运行,但是在Azure(WebChat,Telegram)上,如果没有人尝试与Bot通信,它将只能运行大约一个小时到一个小时和十五分钟.在这段时间之后,机器人将仅遇到内部服务器错误.当您向机器人询问某些内容时,您可以延长此时间范围(抱歉,我不知道多久以及为什么我也不知道多久).

We decided to host it on Azure and added LUIS and Table Storage to it. The Bot runs fine locally in Botframework Emulator, but on Azure (WebChat, Telegram) it will only run for approximatly an hour to an hour and fifteen minutes, if no one tries to communicate with the bot. After this period of time, the bot will just run into an internal server error. When you ask the bot something, you can stretch this time window (For how long I don't know and why I don't know either, sorry).

在Azure中,"始终在线"设置为true.

In Azure "Always On" is set to true.

在这一点上,我真的很沮丧,因为我找不到问题,而且我很确定我的代码肯定有问题,因为我没有正确地理解框架.我仍然是Azure,C#和Bot Framework的初学者.另外,我已经在这里和github上阅读了有关内部服务器错误"的所有内容.还尝试了调试,甚至在VS中使用了额外的Debbug选项.我们还尚未尝试过Application Insights.

I'm really frustrated at this point, because I cannot find the problem and I'm pretty sure there must be something wrong with my code, because I don't properly understand the framework. I'm still a beginner with Azure, C# and Bot Framework.Also I have already read everything on "internal server error's" on here and github. Also tried Debugging, even with extra Debbug options in VS. We have not tried Application Insights yet.

此刻,我正在使用LUIS Dialog进行所有操作,该LUIS Dialog调用/转发到其他IDialogs:

At the moment I'm doing everything with the LUIS Dialog which calls / Forwards to other IDialogs:

    [LuisIntent(Intent_Existens)]
    public async Task ExistensOf(IDialogContext context, IAwaitable<IMessageActivity> message, LuisResult result)
    {
        var existens = new ExistensDialog();
        var messageToForward = await message;

        if (result.Entities.Count == 1)
        {
            messageToForward.Value = result.Entities[0].Entity;
            await context.Forward(existens, AfterDialog, messageToForward);
        }
        else
        {
            context.Wait(this.MessageReceived);
        }
    }

我知道值"用于CardAction,但是我不知道如何将Entities传递给子对话框.

I know that "Value" is for CardActions, but I don't know how else I could pass Entities to the child dialog.

    [Serializable]
    public class ExistensDialog : IDialog<object>
    {
        public async Task StartAsync(IDialogContext context)
        {
            context.Wait(MessageReceivedAsync);
        }

        private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> result)
        {
            var message = await result;

            if (message.Text.Contains("specificWord"))
            {
                await context.Forward(new ExistensHU(), AfterDialog, message);
            }
            else
            {
                await context.Forward(new ExistensBin(), AfterDialog, message);
            }
        }

        private async Task AfterDialog(IDialogContext context, IAwaitable<object> result)
        {
            context.Done<object>(null);
        }
    }

然后:

    [Serializable]
    internal class ExistensHU : IDialog<object>
    {
        private Renamer renamer = new Renamer(); // Just for renaming
        private ExternalConnection ec = new ExternalConnection(); //Just a HTTP connection to a WebApp to get data from it

        public async Task StartAsync(IDialogContext context)
        {
            context.Wait(MessageReceivedAsync);
        }

        private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> result)
        {
            const string apiCallURL = "some/API/"; // ExternalConnection...

            var message = await result;

            string nameHU = renamer.RemoveBlanks(message.Value.ToString());

            StringBuilder answerBuilder = new StringBuilder();

            var name = ec.CreateSingleAPIParameter("name", nameHU);
            Dictionary<string, string> wms = await ec.APIResultAsDictionary(apiCallURL, name);

            foreach (var item in wms)
            {
                if (item.Key.Equals("none") && item.Value.Equals("none"))
                {
                    answerBuilder.AppendLine($"Wrong Answer"); 
                }
                else
                {
                    answerBuilder.AppendLine($"Correct Answer");
                }
            }
            await context.PostAsync(answerBuilder.ToString());
            context.Done<object>(null);
        }
    }

基本上,这就是我项目中的每个Dialog.我还有一个看起来像这样的IDialog:

That's basically every Dialog in my project.Also I have an IDialog which looks like this:

    [Serializable]
    public class VerificationDialog : IDialog<object>
    {
        [NonSerializedAttribute]
        private readonly LuisResult _luisResult;

        public VerificationDialog(LuisResult luisResult)
        {
            _luisResult = luisResult;
        }

        public async Task StartAsync(IDialogContext context)
        {
            var message = _luisResult.Query;

            if (!message.StartsWith("Wie viele"))
            {
               context.Call(new ByVerificationDialog(_luisResult), AfterDialog);
            }
            else
            {
               context.Call(new CountBinsByVerification(_luisResult), AfterDialog);
            }
        }

        private async Task AfterDialog(IDialogContext context, IAwaitable<object> result)
        {
            context.Done<object>(null);
        }
    }

我不知道是否可以从BasicLuisDialog中传递这样的luisResult.这可能是问题之一,也可能是问题之一.

I don't know if I'm allowed to pass the luisResult like this from BasicLuisDialog. This could be the issue or one of the issues.

基本上就是这样,我仍然习惯于框架.我不希望有一个绝对的答案.只是提示/技巧和建议,以使一切变得更好.

Basically that's it and I'm still getting used to the framework. I'm not expecting an absolute answer. Just hints/tips and advice how to make everything better.

提前谢谢!

推荐答案

如果使用的是.NET SDK版本3.14.0.7.目前,我们正在此版本中跟踪一个错误.有许多报告,我们正在积极调查中.请尝试降级到3.13.1.在我们可以发布新版本之前,这应该可以为您解决该问题.

If you are using the .NET SDK version 3.14.0.7. There is currently a bug we are tracking in this version. There has been a number of reports and we are actively investigating. Please try downgrading to 3.13.1. This should fix the issue for you until we can release a new version.

作为参考,我们正在跟踪以下GitHub问题的问题: https://github.com/Microsoft/BotBuilder/issues/4322 https://github.com/Microsoft/BotBuilder/issues/4321

for reference we are tracking the issue on these GitHub issues:https://github.com/Microsoft/BotBuilder/issues/4322https://github.com/Microsoft/BotBuilder/issues/4321

更新3/21/2018:

Update 3/21/2018:

我们推出了新版本的SDK,其中包含针对此问题的修复程序 https://www.nuget.org/packages/Microsoft.Bot.Builder/3.14.1.1

We have pushed a new version of the SDK which includes a fix for this issue https://www.nuget.org/packages/Microsoft.Bot.Builder/3.14.1.1

这篇关于一段时间后,发布的C#Bot遇到内部服务器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 10:04