0
votes

I have below LUIS intent implementation -

    [LuisIntent("MyIntent")]
    public async Task MyIntent(IDialogContext context, IAwaitable<IMessageActivity> res, LuisResult result)
    {
        var message = await res;
        try
        {
            await context.PostAsync("I see that you have below options <br/> 1. Do first task <br/> 2. Do second task <br/> 3. Do third task ");
            PromptDialog.Text(context, taskdoer, "You can ask me like - <br/>Do task 2<br/>or simply enter 2");
        }
        catch (Exception e)
        {
            await context.PostAsync("Error is <br/> " + e.ToString());
            context.Wait(MessageReceived);
        }
    }

And the definition for taskdoer -

    private async Task taskdoer(IDialogContext context, IAwaitable<string> result)
    {
        string strTaskNumber = await result;
                if (strTaskNumber == "2")
                {
                    await context.PostAsync("So, you have entered  " + strTaskNumber);
                    await context.PostAsync("This is Task 2");
                    context.Wait(MessageReceived);
                }
                if (strTaskNumber == "3")
                {
                    await context.PostAsync("So, you have entered  " + strTaskNumber);
                    await context.PostAsync("This is Task 3");
                    context.Wait(MessageReceived);
                }
    }

What I would like to achieve is that, without using new method - taskdoer, how can I implement taskdoer logic within MyIntent method itself, but with user prompt for the input as in taskdoer? Is any way user can be prompted without using PromptDialog in Microsoft bot?

1

1 Answers

3
votes

You can't implement it in the way you are looking at. If you need input from the user, you will always have to act on the response in a new method.

You could try to use an anonymous method though you are still having a method and doing some tricks to have it in the same scope. It might not work!

PromptDialog.Text(context, async (IDialogContext ctx, IAwaitable<string> resume) =>
{
    // your magic here
}, "text");

Another alternative if you don't want to use a Prompt within an intent method is:

  1. Instead of using the Prompt, do a context.PostAsync to show the question to the user
  2. Use a context.Wait to wait for the user input. You could wait on a new method (that should have 2 params, IDialogContext and IAwaitable<IMessageActivity>) or you can just use the MessageReceived from LUIS, override it and add some logic there to know when the message shouldn't go LUIS and you should execute the taskdoer logic. I recommend you to have a separate method.

I'm curious about why you don't want to use a Prompt though.