Linked Questions

Popular Questions

Dialog is not continuing from where it waited for user input

Asked by At

This code is using botframework 4

I have rootdialog which is calling an another dialog called choicedialog .From the choicedialog i am returning the DialogturnResult(waiting) from BeginDialogAsync method.After that the bot wait for the input from the user. when the user enter something it should call the ContinueAsync Method in the ChoiceDialog.But the bot is calling the Rootdailog ContinueAsync . what is the reason for this ?How can i solve this?

in the Controller onTurnAync Method

async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken)
    {
        if (turnContext.Activity.Type == ActivityTypes.Message)
        {

                var dc = await Dialogs.CreateContextAsync(turnContext, cancellationToken);
                var dialogResult = await dc.ContinueDialogAsync();

                if (!dc.Context.Responded)
                {
                    // examine results from active dialog
                    switch (dialogResult.Status)
                    {
                        case DialogTurnStatus.Empty:
                            await dc.BeginDialogAsync(nameof(RootDialog));
                            break;

                        case DialogTurnStatus.Waiting:
                            // The active dialog is waiting for a response from the user, so do nothing.
                            break;

                        case DialogTurnStatus.Complete:
                            await dc.EndDialogAsync();
                            break;

                        default:
                            await dc.CancelAllDialogsAsync();
                            break;
                    }
                }
        }
    }

rootDialog

public override async Task<DialogTurnResult> BeginDialogAsync(DialogContext context, object options = null, CancellationToken cancellationToken = default(CancellationToken))
    {
        var activity = context.Context.Activity;
        context.SendTyping(activity);
            var response = DataFromService();
            if (response == null || response.StatusCode != 1)
            {
                await context.PostAsync(Messages.StandardErrorMessage);

            }

            if (response.Data != null)
            {

                return await dialog.BeginDialogAsync(context);

            }
            else
            {
                return new DialogTurnResult(DialogTurnStatus.Waiting);
            }

    }

ChoiceDialog

public override async Task<DialogTurnResult> BeginDialogAsync(DialogContext context, object options = null, CancellationToken cancellationToken = default(CancellationToken))
    {
        choiceStep.SaveEntityDataInContext(context: context);

        IList<IMessageActivity> messages = GenerateMessageActivity(context);

        if (messages.IsCollectionValid())
        {
            foreach (var message in messages)
            {
                await context.PostActivityToUser(message);
            }
        }
        var dialogResult = new DialogTurnResult(DialogTurnStatus.Waiting);
        return dialogResult;
    }

Related Questions