Exemplo n.º 1
0
        public async Task DialogContinue(DialogContext dc)
        {
            if (dc == null)
            {
                throw new ArgumentNullException(nameof(dc));
            }
            //Recognize token
            var tokenResult = await _prompt.Recognize(dc.Context).ConfigureAwait(false);

            //Check for timeout
            var state       = dc.ActiveDialog.State as OAuthPromptOptions;
            var isMessage   = dc.Context.Activity.Type == ActivityTypes.Message;
            var hasTimedOut = isMessage && (DateTime.Compare(DateTime.Now, state.Expires) > 0);

            if (hasTimedOut)
            {
                // if the token fetch request timesout, complete the prompt with no result.
                await dc.End(null).ConfigureAwait(false);
            }
            else if (tokenResult != null)
            {
                // if the token fetch was successful and it hasn't timed out (as verified in the above if)
                await dc.End(tokenResult).ConfigureAwait(false);
            }
            else if (isMessage && !string.IsNullOrEmpty(state.RetryPromptString))
            {
                // if this is a retry, then retry getting user credentials by resending the activity.
                await dc.Context.SendActivity(state.RetryPromptString, state.RetrySpeak).ConfigureAwait(false);
            }
        }
Exemplo n.º 2
0
        public async Task DialogContinue(DialogContext dc)
        {
            if (dc == null)
            {
                throw new ArgumentNullException(nameof(dc));
            }

            // Don't do anything for non-message activities
            if (dc.Context.Activity.Type != ActivityTypes.Message)
            {
                return;
            }

            // Recognize value
            var instance   = dc.ActiveDialog;
            var recognized = await OnRecognize(dc, (PromptOptions)instance.State);

            // TODO: resolve the inconsistency of approach between the Node SDK and what we have here
            if (!recognized.Succeeded())
            {
                // TODO: setting this to null is intended to mimicking the behavior of the Node SDK PromptValidator
                recognized = null;
            }

            if (recognized != null)
            {
                // Return recognized value
                await dc.End(recognized);
            }
            else if (!dc.Context.Responded)
            {
                // Send retry prompt
                await OnPrompt(dc, (PromptOptions)instance.State, true);
            }
        }
Exemplo n.º 3
0
        public async Task DialogContinue(DialogContext dc)
        {
            if (dc == null)
            {
                throw new ArgumentNullException(nameof(dc));
            }

            // Recognize value
            var instance   = dc.Instance;
            var recognized = await OnRecognize(dc, (PromptOptions)instance.State);

            // TODO: resolve the inconsistency of approach between the Node SDK and what we have here
            if (!recognized.Succeeded())
            {
                // TODO: setting this to null is intended to mimicking the behavior of the Node SDK PromptValidator
                recognized = null;
            }

            if (recognized != null)
            {
                await dc.End(recognized);
            }
            else if (!dc.Context.Responded)
            {
                await OnPrompt(dc, (PromptOptions)instance.State, true);
            }
        }
Exemplo n.º 4
0
        private async Task RunStep(DialogContext dc, IDictionary <string, object> result = null)
        {
            if (dc == null)
            {
                throw new ArgumentNullException(nameof(dc));
            }

            var step = dc.ActiveDialog.Step;

            if (step >= 0 && step < _steps.Length)
            {
                SkipStepFunction next = (r) => {
                    // Skip to next step
                    dc.ActiveDialog.Step++;
                    return(RunStep(dc, r));
                };

                // Execute step
                await _steps[step](dc, result, next);
            }
            else
            {
                // End of waterfall so just return to parent
                await dc.End(result);
            }
        }
Exemplo n.º 5
0
        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);
                }
            }
        }
Exemplo n.º 6
0
        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.
            }
        }
Exemplo n.º 7
0
        public async Task DialogContinue(DialogContext dc)
        {
            if (dc == null)
            {
                throw new ArgumentNullException(nameof(dc));
            }

            // Continue controls dialog stack.
            var cdc = Dialogs.CreateContext(dc.Context, dc.Instance.State);
            await cdc.Continue();

            // End if the controls dialog ends.
            if (!cdc.DialogResult.Active)
            {
                await dc.End(cdc.DialogResult.Result);
            }
        }
Exemplo n.º 8
0
        public async Task DialogBegin(DialogContext dc, object dialogArgs = null)
        {
            if (dc == null)
            {
                throw new ArgumentNullException(nameof(dc));
            }

            // Start the controls entry point dialog.
            var cdc = Dialogs.CreateContext(dc.Context, dc.Instance.State);
            await cdc.Begin(DialogId, dialogArgs);

            // End if the controls dialog ends.
            if (!cdc.DialogResult.Active)
            {
                await dc.End(cdc.DialogResult.Result);
            }
        }
Exemplo n.º 9
0
        public async Task DialogContinue(DialogContext dc)
        {
            if (dc == null)
            {
                throw new ArgumentNullException(nameof(dc));
            }

            // Continue controls dialog stack.
            IDictionary <string, object> result = null;
            var cdc = new DialogContext(this.Dialogs, dc.Context, dc.ActiveDialog.State, (r) => { result = r; });
            await cdc.Continue();

            // End if the controls dialog ends.
            if (cdc.ActiveDialog == null)
            {
                await dc.End(result);
            }
        }
Exemplo n.º 10
0
        public async Task DialogBegin(DialogContext dc, IDictionary <string, object> dialogArgs = null)
        {
            if (dc == null)
            {
                throw new ArgumentNullException(nameof(dc));
            }

            // Start the controls entry point dialog.
            IDictionary <string, object> result = null;
            var cdc = new DialogContext(this.Dialogs, dc.Context, dc.ActiveDialog.State, (r) => { result = r; });
            await cdc.Begin(DialogId, dialogArgs);

            // End if the controls dialog ends.
            if (cdc.ActiveDialog == null)
            {
                await dc.End(result);
            }
        }