Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ForeachElement Does not Re-prompt #6313

Closed
karrimrabibiomni opened this issue Apr 29, 2022 · 3 comments · Fixed by #6325
Closed

ForeachElement Does not Re-prompt #6313

karrimrabibiomni opened this issue Apr 29, 2022 · 3 comments · Fixed by #6325
Assignees
Labels
Bot Services Required for internal Azure reporting. Do not delete. Do not change color. bug Indicates an unexpected problem or an unintended behavior. customer-replied-to Indicates that the team has replied to the issue reported by the customer. Do not delete. customer-reported Issue is created by anyone that is not a collaborator in the repository. needs-triage The issue has just been created and it has not been reviewed by the team.

Comments

@karrimrabibiomni
Copy link

Version

4.16.0

Describe the bug

We are running an InputDialog inside an Adaptive For each, another dialog is then run proactively when that proactive dialog has finished then input dialog resumes and Re-prompts the user where they were left before.

Since upgrading to 4.16.0 we noticed that ForEach is Obsolete using the new ForEachElement the above behaviour no longer exists and the InputDialog is not re-prompted.

Expected behaviour

The same re-prompting behaviour to be in the ForEachElement that was in the older ForEach.

Screenshots

Conversation with the old ForEach :
image

Here is 4.16.0 ForEachElement without re-prompt:
image

@karrimrabibiomni karrimrabibiomni added bug Indicates an unexpected problem or an unintended behavior. needs-triage The issue has just been created and it has not been reviewed by the team. labels Apr 29, 2022
@stevkan stevkan added customer-reported Issue is created by anyone that is not a collaborator in the repository. Bot Services Required for internal Azure reporting. Do not delete. Do not change color. labels Apr 29, 2022
@breakingram
Copy link
Contributor

Hey @karrimrabibiomni -- Thanks for reaching out.

For clarity, could you please share the steps to reproduce this issue? I will attempt to reproduce from my end.
Also, are you able to share your dialog code?

@karrimrabibiomni
Copy link
Author

Here is a simple bot that recreates the issue:
BotForeachRepromptBug.zip

@EricDahlvang
Copy link
Member

EricDahlvang commented May 9, 2022

Hi @karrimrabibiomni

Thank you for the repro project! This PR adds reprompt support to ForEachElement, with a unit test of the repro you've provided: #6325

edit:
The below implementation can be used if a workaround is required until this bug is patched:

private class ForEachElementEx : ForEachElement
        {
            /// <inheritdoc/>
            public override async Task<bool> OnDialogEventAsync(DialogContext dc, DialogEvent e, CancellationToken cancellationToken)
            {
                var handled = await base.OnDialogEventAsync(dc, e, cancellationToken).ConfigureAwait(false);
                if (!handled && e?.Name == DialogEvents.RepromptDialog)
                {
                    var childState = GetActionScopeState(dc);
                    var childDc = CreateChildContext(dc, childState);
                    await childDc.RepromptDialogAsync(cancellationToken).ConfigureAwait(false);
                    handled = true;
                }
                return handled;
            }
            private DialogContext CreateChildContext(DialogContext dc, DialogState childDialogState)
            {
                var childDc = new DialogContext(new DialogSet().Add(new ActionScope(this.Actions)), dc.Parent ?? dc, childDialogState);
                childDc.Parent = dc.Parent;
                if (dc.Services != null)
                {
                    foreach (var service in dc.Services)
                    {
                        childDc.Services[service.Key] = service.Value;
                    }
                }
                return childDc;
            }
            private DialogState GetActionScopeState(DialogContext dc)
            {
                const string ActionScopeState = "this.actionScopeState";
                DialogState state = null;
                var activeDialogState = dc.ActiveDialog?.State as Dictionary<string, object>;
                if (activeDialogState != null && activeDialogState.TryGetValue(ActionScopeState, out var currentState))
                {
                    state = currentState as DialogState;
                }
                if (state == null)
                {
                    state = new DialogState();
                    if (activeDialogState != null)
                    {
                        activeDialogState[ActionScopeState] = state;
                    }
                }
                return state;
            }
        }

@EricDahlvang EricDahlvang added the customer-replied-to Indicates that the team has replied to the issue reported by the customer. Do not delete. label May 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bot Services Required for internal Azure reporting. Do not delete. Do not change color. bug Indicates an unexpected problem or an unintended behavior. customer-replied-to Indicates that the team has replied to the issue reported by the customer. Do not delete. customer-reported Issue is created by anyone that is not a collaborator in the repository. needs-triage The issue has just been created and it has not been reviewed by the team.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants