public async override Task <DialogTurnResult> BeginDialogAsync(DialogContext dc, object options = null, CancellationToken cancellationToken = default)
        {
            var dcState = dc.GetState();

            var(result, error) = Expression.Parse(Condition).TryEvaluate(dcState);
            if ((bool)result == false)
            {
                var desc = await new TemplateEngineLanguageGenerator()
                           .Generate(dc.Context, this.Description, dcState)
                           .ConfigureAwait(false);
                throw new Exception(desc);
            }

            return(await dc.EndDialogAsync().ConfigureAwait(false));
        }
        private string GetCulture(DialogContext dc)
        {
            if (!string.IsNullOrEmpty(dc.Context.Activity.Locale))
            {
                return dc.Context.Activity.Locale;
            }

            if (this.DefaultLocale != null)
            {
                var dcState = dc.GetState();
                return this.DefaultLocale.GetValue(dcState);
            }

            return English;
        }
        private string GetCulture(DialogContext dc)
        {
            var dcState = dc.GetState();

            if (!string.IsNullOrWhiteSpace(dc.Context.Activity.Locale))
            {
                return(dc.Context.Activity.Locale);
            }

            if (this.DefaultLocale != null)
            {
                return(this.DefaultLocale.GetValue(dcState));
            }

            return(English);
        }
        public override Task <DialogTurnResult> BeginDialogAsync(DialogContext dc, object options = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (options is CancellationToken)
            {
                throw new ArgumentException($"{nameof(options)} cannot be a cancellation token");
            }

            var dcState = dc.GetState();

            if (this.Disabled != null && this.Disabled.GetValue(dcState) == true)
            {
                return(dc.EndDialogAsync(cancellationToken: cancellationToken));
            }

            return(Task.FromResult(Dialog.EndOfTurn));
        }
        protected Dialog ResolveDialog(DialogContext dc)
        {
            if (this.Dialog?.Value != null)
            {
                return(this.Dialog.Value);
            }

            var dcState = dc.GetState();

            // NOTE: we call TryEvaluate instead of TryGetValue because we want the result of the expression as a string so we can
            // look up the string using external FindDialog().
            var se       = new StringExpression($"={this.Dialog.ExpressionText}");
            var dialogId = se.GetValue(dcState);

            return(dc.FindDialog(dialogId ?? throw new Exception($"{this.Dialog.ToString()} not found.")));
        }
Beispiel #6
0
            public override Task <DialogTurnResult> ContinueDialogAsync(DialogContext dc, CancellationToken cancellationToken = default)
            {
                switch (dc.Context.Activity.Text)
                {
                case "throw":
                    throw new Exception("throwing");

                case "end":
                    return(dc.EndDialogAsync());
                }

                var data = dc.GetState().GetValue <string>("conversation.test", () => "unknown");

                dc.Context.SendActivityAsync(data);
                return(Task.FromResult(new DialogTurnResult(DialogTurnStatus.Waiting)));
            }
Beispiel #7
0
        public override async Task <DialogTurnResult> BeginDialogAsync(DialogContext dc, object options = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (options is CancellationToken)
            {
                throw new ArgumentException($"{nameof(options)} cannot be a cancellation token");
            }

            var dcState = dc.GetState();

            if (this.Disabled != null && this.Disabled.GetValue(dcState) == true)
            {
                return(await dc.EndDialogAsync(cancellationToken : cancellationToken).ConfigureAwait(false));
            }

            return(await this.codeHandler(dc, options).ConfigureAwait(false));
        }
Beispiel #8
0
        public override async Task <DialogTurnResult> ContinueDialogAsync(DialogContext dc, CancellationToken cancellationToken = default(CancellationToken))
        {
            var activity = dc.Context.Activity;

            if (activity.Type != ActivityTypes.Message)
            {
                return(Dialog.EndOfTurn);
            }

            var interrupted = dc.GetState().GetValue <bool>(TurnPath.INTERRUPTED, () => false);
            var turnCount   = dc.GetState().GetValue <int>(TURN_COUNT_PROPERTY, () => 0);

            // Perform base recognition
            var state = await this.RecognizeInput(dc, interrupted? 0 : turnCount);

            if (state == InputState.Valid)
            {
                var input = dc.GetState().GetValue <object>(VALUE_PROPERTY);

                // set output property
                if (!string.IsNullOrEmpty(this.Property))
                {
                    dc.GetState().SetValue(this.Property, input);
                }

                return(await dc.EndDialogAsync(input).ConfigureAwait(false));
            }
            else if (this.MaxTurnCount == null || turnCount < this.MaxTurnCount)
            {
                // increase the turnCount as last step
                dc.GetState().SetValue(TURN_COUNT_PROPERTY, turnCount + 1);
                return(await this.PromptUser(dc, state).ConfigureAwait(false));
            }
            else
            {
                if (this.DefaultValue != null)
                {
                    var(value, error) = new ExpressionEngine().Parse(this.DefaultValue).TryEvaluate(dc.GetState());
                    if (this.DefaultValueResponse != null)
                    {
                        var response = await this.DefaultValueResponse.BindToData(dc.Context, dc.GetState()).ConfigureAwait(false);

                        await dc.Context.SendActivityAsync(response).ConfigureAwait(false);
                    }

                    // set output property
                    dc.GetState().SetValue(this.Property, value);

                    return(await dc.EndDialogAsync(value).ConfigureAwait(false));
                }
            }

            return(await dc.EndDialogAsync().ConfigureAwait(false));
        }
        protected async override Task <QnADialogResponseOptions> GetQnAResponseOptionsAsync(DialogContext dc)
        {
            var dcState  = dc.GetState();
            var noAnswer = (this.NoAnswer != null) ? await this.NoAnswer.BindToData(dc.Context, dcState).ConfigureAwait(false) : null;

            var cardNoMatchResponse = (this.CardNoMatchResponse != null) ? await this.CardNoMatchResponse.BindToData(dc.Context, dcState).ConfigureAwait(false) : null;

            var responseOptions = new QnADialogResponseOptions
            {
                ActiveLearningCardTitle = this.ActiveLearningCardTitle.GetValue(dcState),
                CardNoMatchText         = this.CardNoMatchText.GetValue(dcState),
                NoAnswer            = noAnswer,
                CardNoMatchResponse = cardNoMatchResponse,
            };

            return(responseOptions);
        }
        protected override object OnInitializeOptions(DialogContext dc, object options)
        {
            var op = options as ChoiceInputOptions;

            if (op == null || op.Choices == null || op.Choices.Count == 0)
            {
                if (op == null)
                {
                    op = new ChoiceInputOptions();
                }

                var choices = this.Choices.GetValue(dc.GetState());
                op.Choices = choices;
            }

            return(base.OnInitializeOptions(dc, op));
        }
Beispiel #11
0
            public override async Task <DialogTurnResult> BeginDialogAsync(DialogContext dc, object options = null, CancellationToken cancellationToken = default)
            {
                dc.GetState().SetValue($"dialog.options", options);
                dc.GetState().SetValue($"$bbb", "bbb");
                await dc.Context.SendActivityAsync(dc.GetState().GetValue <string>("$bbb"));

                await dc.Context.SendActivityAsync(dc.GetState().GetValue <string>("dialog.options.test"));

                await dc.Context.SendActivityAsync(dc.GetState().GetValue <string>("%MaxValue"));

                return(await dc.EndDialogAsync(dc.GetState().GetValue <string>("$bbb")));
            }
Beispiel #12
0
            public override async Task <DialogTurnResult> BeginDialogAsync(DialogContext dc, object options = null, CancellationToken cancellationToken = default)
            {
                dc.GetState().SetValue("dialog.xyz", "dialog");
                await dc.Context.SendActivityAsync(dc.GetState().GetValue <string>("dialog.xyz"));

                await dc.Context.SendActivityAsync(dc.GetState().GetValue <string>("$xyz"));

                dc.GetState().SetValue("$aaa", "dialog2");
                await dc.Context.SendActivityAsync(dc.GetState().GetValue <string>("dialog.aaa"));

                await dc.Context.SendActivityAsync(dc.GetState().GetValue <string>("$aaa"));

                await dc.Context.SendActivityAsync(dc.GetState().GetValue <string>("%MaxValue"));

                return(await dc.BeginDialogAsync("d2", options : new { test = "123" }));
            }
        protected override async Task <IActivity> OnRenderPrompt(DialogContext dc, InputState state)
        {
            var dcState = dc.GetState();
            var locale  = GetCulture(dc);
            var prompt  = await base.OnRenderPrompt(dc, state);

            var channelId     = dc.Context.Activity.ChannelId;
            var choicePrompt  = new ChoicePrompt(this.Id);
            var choiceOptions = this.ChoiceOptions?.GetValue(dcState) ?? ChoiceInput.DefaultChoiceOptions[locale];

            var(choices, error) = this.Choices.TryGetValue(dcState);
            if (error != null)
            {
                throw new Exception(error);
            }

            return(this.AppendChoices(prompt.AsMessageActivity(), channelId, choices, this.Style.GetValue(dcState), choiceOptions));
        }
        public override async Task <DialogTurnResult> ResumeDialogAsync(DialogContext dc, DialogReason reason, object result = null, CancellationToken cancellationToken = default)
        {
            if (result is ActionScopeResult actionScopeResult)
            {
                return(await OnActionScopeResultAsync(dc, actionScopeResult, cancellationToken).ConfigureAwait(false));
            }

            // When we are resumed, we increment our offset into the actions and being the next action
            var nextOffset = dc.GetState().GetIntValue(OFFSETKEY, 0) + 1;

            if (nextOffset < this.Actions.Count)
            {
                return(await this.BeginActionAsync(dc, nextOffset, cancellationToken : cancellationToken).ConfigureAwait(false));
            }

            // else we fire the end of actions
            return(await this.OnEndOfActionsAsync(dc, result, cancellationToken : cancellationToken).ConfigureAwait(false));
        }
Beispiel #15
0
        public override async Task <DialogTurnResult> BeginDialogAsync(DialogContext dc, object options = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (options is CancellationToken)
            {
                throw new ArgumentException($"{nameof(options)} cannot be a cancellation token");
            }

            // Ensure planning context
            if (dc is SequenceContext planning)
            {
                dc.GetState().RemoveValue(Property);
                return(await dc.EndDialogAsync());
            }
            else
            {
                throw new Exception("`ClearProperty` should only be used in the context of an adaptive dialog.");
            }
        }
Beispiel #16
0
        private async Task ReplaceJTokenRecursively(DialogContext dc, JToken token)
        {
            var dcState = dc.GetState();

            switch (token.Type)
            {
            case JTokenType.Object:
                foreach (var child in token.Children <JProperty>())
                {
                    await ReplaceJTokenRecursively(dc, child);
                }

                break;

            case JTokenType.Array:
                // NOTE: ToList() is required because JToken.Replace will break the enumeration.
                foreach (var child in token.Children().ToList())
                {
                    await ReplaceJTokenRecursively(dc, child);
                }

                break;

            case JTokenType.Property:
                await ReplaceJTokenRecursively(dc, ((JProperty)token).Value);

                break;

            default:
                if (token.Type == JTokenType.String)
                {
                    var text = token.ToString();

                    // if it is a "{bindingpath}" then run through expression engine and treat as a value
                    var(result, error) = new ValueExpression(text).TryGetValue(dcState);
                    if (error == null)
                    {
                        token.Replace(JToken.FromObject(result));
                    }
                }

                break;
            }
        }
Beispiel #17
0
        public override async Task <DialogTurnResult> BeginDialogAsync(DialogContext dc, object options = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (options is CancellationToken)
            {
                throw new ArgumentException($"{nameof(options)} cannot be a cancellation token");
            }

            // Ensure planning context
            if (dc is SequenceContext planning)
            {
                var(value, error) = condition.TryEvaluate(dc.GetState());
                var conditionResult = error == null && value != null && (bool)value;

                var actions = new List <Dialog>();
                if (conditionResult == true)
                {
                    actions = this.Actions;
                }
                else
                {
                    actions = this.ElseActions;
                }

                var planActions = actions.Select(s => new ActionState()
                {
                    DialogStack = new List <DialogInstance>(),
                    DialogId    = s.Id,
                    Options     = options
                });

                // Queue up actions that should run after current step
                planning.QueueChanges(new ActionChangeList()
                {
                    ChangeType = ActionChangeType.InsertActions,
                    Actions    = planActions.ToList()
                });

                return(await planning.EndDialogAsync(cancellationToken : cancellationToken).ConfigureAwait(false));
            }
            else
            {
                throw new Exception("`IfCondition` should only be used in the context of an adaptive dialog.");
            }
        }
        protected async override Task <QnADialogResponseOptions> GetQnAResponseOptionsAsync(DialogContext dc)
        {
            var dcState  = dc.GetState();
            var noAnswer = (this.NoAnswer != null) ? await this.NoAnswer.BindToData(dc.Context, dcState).ConfigureAwait(false) : null;

            var cardNoMatchResponse = (this.CardNoMatchResponse != null) ? await this.CardNoMatchResponse.BindToData(dc.Context, dcState).ConfigureAwait(false) : null;

            if (noAnswer != null)
            {
                var properties = new Dictionary <string, string>()
                {
                    { "template", JsonConvert.SerializeObject(this.NoAnswer) },
                    { "result", noAnswer == null ? string.Empty : JsonConvert.SerializeObject(noAnswer, new JsonSerializerSettings()
                        {
                            NullValueHandling = NullValueHandling.Ignore
                        }) },
                };
                TelemetryClient.TrackEvent("GeneratorResult", properties);
            }

            if (cardNoMatchResponse != null)
            {
                var properties = new Dictionary <string, string>()
                {
                    { "template", JsonConvert.SerializeObject(this.CardNoMatchResponse) },
                    { "result", cardNoMatchResponse == null ? string.Empty : JsonConvert.SerializeObject(cardNoMatchResponse, new JsonSerializerSettings()
                        {
                            NullValueHandling = NullValueHandling.Ignore
                        }) },
                };
                TelemetryClient.TrackEvent("GeneratorResult", properties);
            }

            var responseOptions = new QnADialogResponseOptions
            {
                ActiveLearningCardTitle = this.ActiveLearningCardTitle.GetValue(dcState),
                CardNoMatchText         = this.CardNoMatchText.GetValue(dcState),
                NoAnswer            = noAnswer,
                CardNoMatchResponse = cardNoMatchResponse,
            };

            return(responseOptions);
        }
        protected virtual async Task <IActivity> OnRenderPrompt(DialogContext dc, InputState state)
        {
            IMessageActivity msg = null;
            var dcState          = dc.GetState();

            switch (state)
            {
            case InputState.Unrecognized:
                if (this.UnrecognizedPrompt != null)
                {
                    msg = await this.UnrecognizedPrompt.BindToData(dc.Context, dcState).ConfigureAwait(false);
                }
                else if (this.InvalidPrompt != null)
                {
                    msg = await this.InvalidPrompt.BindToData(dc.Context, dcState).ConfigureAwait(false);
                }

                break;

            case InputState.Invalid:
                if (this.InvalidPrompt != null)
                {
                    msg = await this.InvalidPrompt.BindToData(dc.Context, dcState).ConfigureAwait(false);
                }
                else if (this.UnrecognizedPrompt != null)
                {
                    msg = await this.UnrecognizedPrompt.BindToData(dc.Context, dcState).ConfigureAwait(false);
                }

                break;
            }

            if (msg == null)
            {
                msg = await this.Prompt.BindToData(dc.Context, dcState).ConfigureAwait(false);
            }

            msg.InputHint = InputHints.ExpectingInput;

            return(msg);
        }
Beispiel #20
0
        public override async Task <DialogTurnResult> BeginDialogAsync(DialogContext dc, object options = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (options is CancellationToken)
            {
                throw new ArgumentException($"{nameof(options)} cannot be a cancellation token");
            }

            var dialog = this.ResolveDialog(dc);

            // use bindingOptions to bind to the bound options
            var boundOptions = BindOptions(dc, options);

            if (this.IncludeActivity)
            {
                // reset this to false so that new dialog has opportunity to process the activity
                dc.GetState().SetValue(TurnPath.ACTIVITYPROCESSED, false);
            }

            // replace dialog with bound options passed in as the options
            return(await dc.ReplaceDialogAsync(dialog.Id, options : boundOptions, cancellationToken : cancellationToken).ConfigureAwait(false));
        }
Beispiel #21
0
        protected override async Task <bool> OnPreBubbleEventAsync(DialogContext dc, DialogEvent e, CancellationToken cancellationToken)
        {
            if (e.Name == DialogEvents.ActivityReceived && dc.Context.Activity.Type == ActivityTypes.Message)
            {
                // Ask parent to perform recognition
                await dc.Parent.EmitEventAsync(AdaptiveEvents.RecognizeUtterance, value : dc.Context.Activity, bubble : false, cancellationToken : cancellationToken).ConfigureAwait(false);

                // Should we allow interruptions
                var canInterrupt = true;
                if (allowInterruptions != null)
                {
                    var(value, error) = allowInterruptions.TryEvaluate(dc.GetState());
                    canInterrupt      = error == null && value != null && (bool)value;
                }

                // Stop bubbling if interruptions ar NOT allowed
                return(!canInterrupt);
            }

            return(false);
        }
        public override async Task <DialogTurnResult> BeginDialogAsync(DialogContext dc, object options = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (options is CancellationToken)
            {
                throw new ArgumentException($"{nameof(options)} cannot be a cancellation token");
            }

            var dcState = dc.GetState();

            if (this.Disabled != null && this.Disabled.GetValue(dcState) == true)
            {
                return(await dc.EndDialogAsync(cancellationToken : cancellationToken).ConfigureAwait(false));
            }

            var activity = await Activity.BindToData(dc.Context, dcState).ConfigureAwait(false);

            var properties = new Dictionary <string, string>()
            {
                { "template", JsonConvert.SerializeObject(Activity) },
                { "result", activity == null ? string.Empty : JsonConvert.SerializeObject(activity, new JsonSerializerSettings()
                    {
                        NullValueHandling = NullValueHandling.Ignore
                    }) },
            };

            TelemetryClient.TrackEvent("GeneratorResult", properties);

            ResourceResponse response = null;

            if (activity.Type != "message" ||
                !string.IsNullOrEmpty(activity.Text) ||
                activity.Attachments?.Any() == true ||
                !string.IsNullOrEmpty(activity.Speak) ||
                activity.SuggestedActions != null)
            {
                response = await dc.Context.SendActivityAsync(activity, cancellationToken).ConfigureAwait(false);
            }

            return(await dc.EndDialogAsync(response, cancellationToken).ConfigureAwait(false));
        }
        public override async Task <DialogTurnResult> BeginDialogAsync(DialogContext dc, object options = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (options is CancellationToken)
            {
                throw new ArgumentException($"{nameof(options)} cannot be a cancellation token");
            }

            var dcState = dc.GetState();

            if (this.Disabled != null && this.Disabled.GetValue(dcState) == true)
            {
                return(await dc.EndDialogAsync(cancellationToken : cancellationToken).ConfigureAwait(false));
            }

            var bfAdapter = dc.Context.Adapter as BotFrameworkAdapter;

            if (bfAdapter == null)
            {
                throw new Exception("GetActivityMembers() only works with BotFrameworkAdapter");
            }

            string id = dc.Context.Activity.Id;

            if (this.ActivityId != null)
            {
                var(value, valueError) = this.ActivityId.TryGetValue(dcState);
                if (valueError != null)
                {
                    throw new Exception($"Expression evaluation resulted in an error. Expression: {this.ActivityId}. Error: {valueError}");
                }

                id = value as string;
            }

            var result = await bfAdapter.GetActivityMembersAsync(dc.Context, id, cancellationToken).ConfigureAwait(false);

            dcState.SetValue(this.Property.GetValue(dcState), result);

            return(await dc.EndDialogAsync(result, cancellationToken : cancellationToken).ConfigureAwait(false));
        }
Beispiel #24
0
        public override async Task <DialogTurnResult> BeginDialogAsync(DialogContext dc, object options = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (options is CancellationToken)
            {
                throw new ArgumentException($"{nameof(options)} cannot be a cancellation token");
            }

            var dcState = dc.GetState();

            if (this.Disabled != null && this.Disabled.GetValue(dcState) == true)
            {
                return(await dc.EndDialogAsync(cancellationToken : cancellationToken).ConfigureAwait(false));
            }

            LoadScript();

            // use bindingOptions to bind to the bound options
            var boundOptions = BindOptions(dc, options);

            dcState.SetValue(ThisPath.OPTIONS, boundOptions);

            var engine = new Engine();

            foreach (var scope in dcState.Where(ms => ms.Key != "this"))
            {
                engine.SetValue(scope.Key, scope.Value);
            }

            var result = engine.Execute(this.script)
                         .GetValue("doAction")
                         .Invoke(Jint.Native.JsValue.FromObject(engine, boundOptions ?? new object()))
                         .ToObject();

            if (this.ResultProperty != null)
            {
                dcState.SetValue(this.ResultProperty.GetValue(dcState), result);
            }

            return(await dc.EndDialogAsync(result, cancellationToken : cancellationToken));
        }
        public override async Task <DialogTurnResult> BeginDialogAsync(DialogContext dc, object options = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (options is CancellationToken)
            {
                throw new ArgumentException($"{nameof(options)} cannot be a cancellation token");
            }

            var dcState = dc.GetState();

            if (this.Disabled != null && this.Disabled.GetValue(dcState) == true)
            {
                return(await dc.EndDialogAsync(cancellationToken : cancellationToken).ConfigureAwait(false));
            }

            object value = null;

            if (this.Value != null)
            {
                var(val, valError) = this.Value.TryGetValue(dcState);
                if (valError != null)
                {
                    throw new Exception(valError);
                }

                value = val;
            }
            else
            {
                value = dcState.GetMemorySnapshot();
            }

            var name      = this.Name?.GetValue(dcState);
            var valueType = this.ValueType?.GetValue(dcState);
            var label     = this.Label?.GetValue(dcState);

            var traceActivity = Activity.CreateTraceActivity(name ?? "Trace", valueType: valueType ?? "State", value: value, label: label ?? name ?? dc.Parent?.ActiveDialog?.Id);
            await dc.Context.SendActivityAsync(traceActivity, cancellationToken).ConfigureAwait(false);

            return(await dc.EndDialogAsync(traceActivity, cancellationToken : cancellationToken).ConfigureAwait(false));
        }
        protected override Task <InputState> OnRecognizeInput(DialogContext dc)
        {
            var dcState = dc.GetState();
            var input   = dcState.GetValue <object>(VALUE_PROPERTY);
            var culture = GetCulture(dc);
            var refTime = dc.Context.Activity.LocalTimestamp?.LocalDateTime;
            var results = DateTimeRecognizer.RecognizeDateTime(input.ToString(), culture, refTime: refTime);

            if (results.Count > 0)
            {
                // Return list of resolutions from first match
                var result = new List <DateTimeResolution>();
                var values = (List <Dictionary <string, string> >)results[0].Resolution["values"];
                foreach (var value in values)
                {
                    result.Add(ReadResolution(value));
                }

                dcState.SetValue(VALUE_PROPERTY, result);

                if (OutputFormat != null)
                {
                    var(outputValue, error) = this.OutputFormat.TryGetValue(dcState);
                    if (error == null)
                    {
                        dcState.SetValue(VALUE_PROPERTY, outputValue);
                    }
                    else
                    {
                        throw new Exception($"OutputFormat Expression evaluation resulted in an error. Expression: {this.OutputFormat}. Error: {error}");
                    }
                }
            }
            else
            {
                return(Task.FromResult(InputState.Unrecognized));
            }

            return(Task.FromResult(InputState.Valid));
        }
Beispiel #27
0
        public async Task <DialogTurnResult> PrimaryHandler(DialogContext context, object data)
        {
            bool isBusy = context.GetState().GetValue <bool>("conversation.busy", () => false);

            //Always hit LUIS first
            if (Services.LuisRecognizer != null)
            {
                var recognizerResult = await Services.LuisRecognizer.RecognizeAsync(context.Context, CancellationToken.None);

                foreach (var checkIntent in recognizerResult.Intents)
                {
                    if (Constants.IntentThresholds.ContainsKey(checkIntent.Key) && checkIntent.Value.Score >= Constants.IntentThresholds[checkIntent.Key])
                    {
                        return(await PerformIntent(checkIntent.Key, recognizerResult, context));
                    }
                }
            }


            if (Services.LeadQualQnA != null)
            {
                if (Constants.HelpOptions.Contains(context.Context.Activity.Text))
                {
                    //await context.EmitEventAsync(Constants.Event_Interest);
                    return(new DialogTurnResult(DialogTurnStatus.CompleteAndWait));
                }
                else
                {
                    return(await ProcessDefaultResponse(context, data, isBusy));
                }
            }
            else
            {
                await context.Context.SendActivityAsync("We must be in Kansas, Dorothy, 'cause there ain't no QnA!");
            }

            //You can change status to alter the behaviour post-completion
            return(new DialogTurnResult(DialogTurnStatus.Waiting, null));
        }
        public override async Task <DialogTurnResult> BeginDialogAsync(DialogContext dc, object options = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (options is CancellationToken)
            {
                throw new ArgumentException($"{nameof(options)} cannot be a cancellation token");
            }

            var dcState = dc.GetState();

            if (this.Disabled != null && this.Disabled.GetValue(dcState) == true)
            {
                return(await dc.EndDialogAsync(cancellationToken : cancellationToken).ConfigureAwait(false));
            }

            // Continue is simply returning an ActionScopeResult with ContinueLoop command in it.
            var actionScopeResult = new ActionScopeResult()
            {
                ActionScopeCommand = ActionScopeCommands.ContinueLoop
            };

            return(await dc.EndDialogAsync(result : actionScopeResult, cancellationToken : cancellationToken).ConfigureAwait(false));
        }
        protected override Task <InputState> OnRecognizeInput(DialogContext dc)
        {
            var dcState = dc.GetState();

            var input = dcState.GetValue <string>(VALUE_PROPERTY);

            if (this.OutputFormat != null)
            {
                var(outputValue, error) = this.OutputFormat.TryGetValue(dcState);
                if (error == null)
                {
                    input = outputValue.ToString();
                }
                else
                {
                    throw new Exception($"In TextInput, OutputFormat Expression evaluation resulted in an error. Expression: {OutputFormat.ToString()}. Error: {error}");
                }
            }

            dcState.SetValue(VALUE_PROPERTY, input);
            return(input.Length > 0 ? Task.FromResult(InputState.Valid) : Task.FromResult(InputState.Unrecognized));
        }
        public override async Task <DialogTurnResult> BeginDialogAsync(DialogContext dc, object options = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (options is CancellationToken)
            {
                throw new ArgumentException($"{nameof(options)} cannot be a cancellation token");
            }

            var dcState = dc.GetState();

            if (this.Disabled != null && this.Disabled.GetValue(dcState) == true)
            {
                return(await dc.EndDialogAsync(cancellationToken : cancellationToken).ConfigureAwait(false));
            }

            var activity = await Activity.BindToData(dc.Context, dcState).ConfigureAwait(false);

            var properties = new Dictionary <string, string>()
            {
                { "template", JsonConvert.SerializeObject(Activity) },
                { "result", activity == null ? string.Empty : JsonConvert.SerializeObject(activity, new JsonSerializerSettings()
                    {
                        NullValueHandling = NullValueHandling.Ignore
                    }) },
            };

            TelemetryClient.TrackEvent("GeneratorResult", properties);

            var(result, error) = this.ActivityId.TryGetValue(dcState);
            if (error != null)
            {
                throw new ArgumentException(error);
            }

            activity.Id = (string)result;

            var response = await dc.Context.UpdateActivityAsync(activity, cancellationToken).ConfigureAwait(false);

            return(await dc.EndDialogAsync(response, cancellationToken).ConfigureAwait(false));
        }