public async Task DialogBegin(DialogContext dc, IDictionary <string, object> dialogArgs = null) { if (dc == null) { throw new ArgumentNullException(nameof(dc)); } PromptOptions promptOptions = null; if (dialogArgs != null) { if (dialogArgs is PromptOptions) { promptOptions = dialogArgs as PromptOptions; } else { throw new ArgumentException(nameof(dialogArgs)); } } //persist options and state var timeout = _settings.Timeout.HasValue ? _settings.Timeout.Value : DefaultPromptTimeout; var instance = dc.ActiveDialog; instance.State = new OAuthPromptOptions(promptOptions); var tokenResult = await _prompt.GetUserToken(dc.Context).ConfigureAwait(false); if (tokenResult != null && tokenResult.TokenResponse != null) { // end the prompt, since a token is available. await dc.End(tokenResult).ConfigureAwait(false); } else if (!string.IsNullOrEmpty(promptOptions?.PromptString)) { //send supplied prompt and then OAuthCard await dc.Context.SendActivity(promptOptions.PromptString, promptOptions.Speak).ConfigureAwait(false); await _prompt.Prompt(dc.Context); } else { // if the bot developer has supplied an activity to show the user for signin, use that. if (promptOptions == null) { await _prompt.Prompt(dc.Context).ConfigureAwait(false); } else { await _prompt.Prompt(dc.Context, promptOptions.PromptActivity); } } }
public async Task DialogBegin(DialogContext dc, object dialogArgs = null) { if (dc == null) { throw new ArgumentNullException(nameof(dc)); } PromptOptions promptOptions = null; if (dialogArgs != null) { if (dialogArgs is PromptOptions) { promptOptions = dialogArgs as PromptOptions; } else { throw new ArgumentException(nameof(dialogArgs)); } } //persist options and state var timeout = _settings.Timeout.HasValue ? _settings.Timeout.Value : DefaultPromptTimeout; var instance = dc.ActiveDialog; instance.State = new OAuthPromptOptions(promptOptions); var tokenResult = await _prompt.GetUserToken(dc.Context).ConfigureAwait(false); if (tokenResult != null && tokenResult.Value != null) { // end the prompt, since a token is available. await dc.End(tokenResult).ConfigureAwait(false); } else if (!string.IsNullOrEmpty(promptOptions.PromptString)) { // if no token is avaialable, display an oauth/signin card for the user to enter credentials. await _prompt.Prompt(dc.Context, promptOptions.PromptString, promptOptions.Speak).ConfigureAwait(false); } else if (promptOptions.PromptActivity != null) { // if the bot developer has supplied an activity to show the user for signin, use that. await _prompt.Prompt(dc.Context, promptOptions.PromptActivity).ConfigureAwait(false); } else { // no suitable promptactivity or message provided. Hence ignoring this prompt. } }