public async Task OnTurn(ITurnContext turnContext)
        {
            var localContext = new V4ReferenceContext(turnContext);

            // Get the current ActiveTopic from my persisted conversation state
            var conversation = ConversationState <ConversationData> .Get(localContext);

            var handled = false;

            // if we don't have an active subject yet
            if (conversation.CurrentSubject == null)
            {
                // use the default topic
                conversation.CurrentSubject = new MainSubject();
                handled = await conversation.CurrentSubject.StartSubject(localContext);
            }
            else
            {
                // we do have an active subject, so call it
                handled = await conversation.CurrentSubject.ContinueSubject(localContext);
            }

            //// if activeTopic's result is false and the activeTopic is NOT already the default topic
            //if (handled == false && !(conversation.ActiveTopic is DefaultTopic))
            //{
            //    // Use DefaultTopic as the active topic
            //    conversation.CurrentSubject = new DefaultTopic();
            //    await conversation.CurrentSubject.ResumeTopic(localContext);
            //}
        }
        public async Task <bool> StartSubject(V4ReferenceContext context)
        {
            var conversation = ConversationState <ConversationData> .Get(context);

            conversation.MainMenuSubject = this;

            switch (context.Activity.Type)
            {
            case ActivityTypes.ConversationUpdate:

                // greet when added to conversation
                var activity = context.Activity.AsConversationUpdateActivity();
                if (activity.MembersAdded.Any(m => m.Id == activity.Recipient.Id))
                {
                    await MainSubjectResponses.ReplyWithGreeting(context);

                    this.Greeted = true;
                }

                break;

            case ActivityTypes.Message:
                // greet on first message if we haven't already
                if (!Greeted)
                {
                    await MainSubjectResponses.ReplyWithGreeting(context);

                    this.Greeted = true;
                }
                return(await this.ContinueSubject(context));
            }
            return(true);
        }
        public async Task <bool> ContinueSubject(V4ReferenceContext context)
        {
            var conversation = ConversationState <ConversationData> .Get(context);

            var luisResult = context.Services.Get <RecognizerResult>(LuisRecognizerMiddleware.LuisRecognizerResultKey);

            (string key, double score)topItem = luisResult.GetTopScoringIntent();

            switch (context.Activity.Type)
            {
            case ActivityTypes.Message:
                switch (topItem.key)
                {
                case "GuessingGame":
                    conversation.CurrentSubject = new GuessingGameSubject(this);
                    await conversation.CurrentSubject.StartSubject(context);

                    break;

                case "Help":
                    // show help
                    await GamesSubjectResponses.ReplyWithHelp(context);

                    break;

                case "MainMenu":
                    // show Main Menu
                    conversation.CurrentSubject = conversation.MainMenuSubject;
                    await conversation.MainMenuSubject.ContinueSubject(context);

                    break;

                case "Quit":
                    // show Main Menu
                    conversation.CurrentSubject = ParentSubject;
                    await ParentSubject.ContinueSubject(context);

                    break;

                default:
                    // show our confusion
                    await GamesSubjectResponses.ReplyWithConfused(context);

                    break;
                }

                break;

            default:
                await context.SendActivity($"Not setup yet");

                break;
            }

            return(true);
        }
        public async Task <bool> StartSubject(V4ReferenceContext context)
        {
            switch (context.Activity.Type)
            {
            case ActivityTypes.Message:

                await GuessingGamesSubjectResponses.ReplyWithGreeting(context);

                break;

            default:
                break;
            }
            return(true);
        }
        public async Task <bool> StartSubject(V4ReferenceContext context)
        {
            switch (context.Activity.Type)
            {
            case ActivityTypes.Message:

                await context.SendActivity($"Welcome to Granny Bot Central Control");

                break;

            default:
                break;
            }
            return(true);
        }
        public async Task <bool> ContinueSubject(V4ReferenceContext context)
        {
            var conversation = ConversationState <ConversationData> .Get(context);

            if (conversation.SecretNumber == 0)
            {
                conversation.SecretNumber = new Random().Next(1, 10);
            }

            if (context.Activity.Type is ActivityTypes.Message)
            {
                if (int.TryParse(context.Activity.Text, out var guess))
                {
                    if (guess > conversation.SecretNumber)
                    {
                        await context.SendActivity($"Guess Lower");
                    }

                    if (guess < conversation.SecretNumber)
                    {
                        await context.SendActivity($"Guess Higher");
                    }

                    if (int.Parse(context.Activity.Text) == conversation.SecretNumber)
                    {
                        await context.SendActivity($"You Guessed it");
                    }

                    await context.SendActivity($"The number is {conversation.SecretNumber}");
                }
                else
                {
                    var luisResult = context.Services.Get <RecognizerResult>(LuisRecognizerMiddleware.LuisRecognizerResultKey);

                    (string key, double score)topItem = luisResult.GetTopScoringIntent();

                    switch (context.Activity.Type)
                    {
                    case ActivityTypes.Message:
                        switch (topItem.key)
                        {
                        case "Help":
                            // show help
                            await GuessingGamesSubjectResponses.ReplyWithHelp(context);

                            break;

                        case "MainMenu":
                            // show Main Menu
                            conversation.CurrentSubject = conversation.MainMenuSubject;
                            await conversation.MainMenuSubject.ContinueSubject(context);

                            break;

                        case "Quit":
                            // show Main Menu
                            conversation.CurrentSubject = ParentSubject;
                            await ParentSubject.StartSubject(context);

                            break;

                        default:
                            // show our confusion
                            await GuessingGamesSubjectResponses.ReplyWithConfused(context);

                            break;
                        }
                        break;

                    default:
                        break;
                    }
                }
            }

            return(true);
        }
        public async Task <bool> ContinueSubject(V4ReferenceContext context)
        {
            var conversation = ConversationState <ConversationData> .Get(context);

            if (context.Activity.Type == ActivityTypes.Message)
            {
                var luisResult =
                    context.Services.Get <RecognizerResult>(LuisRecognizerMiddleware.LuisRecognizerResultKey);

                if (luisResult != null)
                {
                    (string key, double score)topItem = luisResult.GetTopScoringIntent();

                    switch (topItem.key)
                    {
                    case "GetActivities":
                        // var activityId = luisResult.Entities.GetValue("ActivityID")[0].Value<string>();
                        // await context.SendActivity($" Found Entity Name: ActivityID : 04030201");
                        await context.SendActivities(BotResponses.GetSingle("04030201"));

                        break;

                    case "ListActivities":
                        await context.SendActivities(BotResponses.GetMultiple());

                        break;

                    case "SendAlert":
                        var xactivityId = luisResult.Entities.GetValue("ActivityID")[0].Value <string>();
                        await context.SendActivity($" Alert for Activity: {xactivityId} has been sent");

                        break;

                    case "CancelAlert":
                        var yactivityId = luisResult.Entities.GetValue("ActivityID")[0].Value <string>();
                        await context.SendActivity($"Activity : {yactivityId} has been cancelled");

                        break;

                    case "Help":
                        // show help
                        await context.SendActivity(MessageFactory.Text("Try commands like: latest, get latest alert, get last activity"));

                        break;

                    case "MainMenu":
                        // show Main Menu
                        conversation.CurrentSubject = conversation.MainMenuSubject;
                        await conversation.MainMenuSubject.ContinueSubject(context);

                        break;

                    case "Quit":
                        // show Main Menu
                        conversation.CurrentSubject = ParentSubject;
                        await ParentSubject.StartSubject(context);

                        break;

                    default:
                        // show our confusion
                        await GuessingGamesSubjectResponses.ReplyWithConfused(context);

                        break;
                    }
                }
            }

            return(true);
        }