Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

azure - Published C# Bot runs into internal server error after some time

Good day everyone,

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

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

In Azure "Always On" is set to true.

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.

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

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

then:

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

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

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.

Thanks in advance!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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

Update 3/21/2018:

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...