Skip to content

Commit

Permalink
Suggestion for on-responded on prompts
Browse files Browse the repository at this point in the history
On issue #3947, relying on the responded flag todecide whether to show the prompt interferes with logic that could be happening either

a. Concurrently
b. On some middleware
c. As part of how we reached the prompt

I believe the *intention* is to prevent sending a prompt twice to the user, using a symbol may be enough for that, without relying on global status
  • Loading branch information
alexrecuenco committed Nov 16, 2021
1 parent a5ae17e commit fb62983
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion libraries/botbuilder-dialogs/src/prompts/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,15 @@ export abstract class Prompt<T> extends Dialog {
state.options = opt;
state.state = {};

dc.context.turnState.set(this.hasPrompted, true)
// Send initial prompt
await this.onPrompt(dc.context, state.state, state.options, false);

return Dialog.EndOfTurn;
}

protected hasPrompted = Symbol('hasPrompted')

/**
* Called when a prompt dialog is the active dialog and the user replied with a new activity.
* @param dc The [DialogContext](xref:botbuilder-dialogs.DialogContext) for the current turn of conversation.
Expand Down Expand Up @@ -257,7 +260,8 @@ export abstract class Prompt<T> extends Dialog {
if (isValid) {
return await dc.endDialog(recognized.value);
} else {
if (!dc.context.responded) {
if (!dc.context.turnState.get(this.hasPrompted)) {
dc.context.turnState.set(this.hasPrompted, true)
await this.onPrompt(dc.context, state.state, state.options, true);
}

Expand Down

0 comments on commit fb62983

Please sign in to comment.