发布的 C# Bot 在一段时间后遇到内部服务器错误 [英] Published C# Bot runs into internal server error after some time

查看:24
本文介绍了发布的 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)上,如果没有人尝试与机器人通信,它只会运行大约一小时到一小时十五分钟.在这段时间之后,机器人将遇到内部服务器错误.当你问机器人什么时,你可以延长这个时间窗口(我不知道多久,为什么我也不知道,抱歉).

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 中,Always On"设置为 true.

In Azure "Always On" is set to true.

此时我真的很沮丧,因为我找不到问题,而且我很确定我的代码一定有问题,因为我没有正确理解框架.我仍然是 Azure、C# 和 Bot Framework 的初学者.此外,我已经阅读了此处和 github 上有关内部服务器错误"的所有内容.还尝试了调试,即使在 VS 中有额外的调试选项.我们尚未尝试过 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 做所有事情,它调用/转发到其他 IDialog:

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

我知道Value"是用于 CardActions,但我不知道我还能如何将实体传递给子对话框.

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

这基本上是我项目中的每个对话框.我还有一个 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/4322https://github.com/Microsoft/BotBuilder/issues/4321

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

2018 年 3 月 21 日更新:

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 在一段时间后遇到内部服务器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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