Creating a loop in c # botframework

I am designing a bot that queries the database, however I hit the wall.

[LuisIntent("ProjectInfo")]
        public async Task projectInfo(IDialogContext context, LuisResult result)
        {
            PromptDialog.Text(context,AfterPromptMethod,"Please enter your project name", attempts: 100);
        }
        async Task AfterPromptMethod(IDialogContext context, IAwaitable<string> userInput)
        {
            var InputText = await userInput;
            string projectName = InputText.ToString();
            if (projectName!= null)
            {
                TestInfo MI = new TestInfo();
                if (MI.FindProject(projectName) == 0)
                {
                    await context.PostAsync($"Project Found. What do you want to know ?");
                }
                else
                {
//PromptDialog.Text(context,AfterPromptMethod,"Pleaase check your product name and try again", attempts: 100);
                    await context.PostAsync($"Project Not Found. Check your project name and try again.");

                }
            }
            context.Wait(MessageReceived);
        }

      

This is where I would like to put the loop, projectInfo is called ok, but when it reaches the if statement where the project is not found, it does nothing. I tried to insert "context.Wait (projectInfo)" but it didn't help. I also tried using the promt dialog, if so, then it goes back if it doesn't go to the main menu. However, I have not been able to plunge into this approach.

If anyone has any suggestions or better ways to do this, they would be appreciated.

+3


source to share


2 answers


If you want to go back to the projectInfo method just call it :)

I have updated your code



[LuisIntent("ProjectInfo")]
public async Task projectInfo(IDialogContext context, LuisResult result)
{
    PromptDialog.Text(context,AfterPromptMethod,"Please enter your project name", attempts: 100);
}

async Task AfterPromptMethod(IDialogContext context, IAwaitable<string> userInput)
{
    var InputText = await userInput;
    string projectName = InputText.ToString();
    if (projectName!= null)
    {
        TestInfo MI = new TestInfo();
        if (MI.FindProject(projectName) == 0)
        {
            await context.PostAsync($"Project Found. What do you want to know ?");
            context.Wait(MessageReceived);
        }
        else
        {
            await context.PostAsync($"Project Not Found. Check your project name and try again.");
            await this.projectInfo(context, null);
        }
    }
}

      

+4


source


Problem context.Wait(..)

. When the button PromptDialog

is clicked , a dialog box is created in which the dialog will be displayed. But executing the code in that method doesn't just exit it. This continues until the end of the method, and the next thing it hits is this context.wait(MessageRecieved)

. This line tries to indicate that the next message should be processed in the MessageRecieved method. So you have 2 places to wait for the next message and it can't be.



To solve your problem, please add return;

directly after your request. This will make sure context.wait (..) hasn't been clicked.

0


source







All Articles