private async Task <DialogTurnResult> BeginRootDialogAsync(
            WaterfallStepContext stepContext,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            var activity = stepContext.Context.Activity;

            activity = Middleware.StripAtMentionText(activity);

            // Set activity text if request is from an adaptive card submit action
            activity = Middleware.AdaptiveCardSubmitActionHandler(activity);

            // Set activity text if request is from an adaptive card submit action
            activity = Middleware.AdaptiveCardSubmitActionHandler(activity);
            var command = activity.Text.Trim().ToLower();

            if (command == DialogMatches.FetchRosterPayloadMatch)
            {
                return(await stepContext.BeginDialogAsync(
                           nameof(FetchRosterDialog)));
            }
            else if (command == DialogMatches.FetchRosterApiMatch)
            {
                await stepContext.BeginDialogAsync(
                    nameof(ListNamesDialog));

                await stepContext.Context.SendActivityAsync(Strings.ThanksRosterTitleMsg);

                return(await stepContext.EndDialogAsync(null, cancellationToken));
            }
            else if (command == DialogMatches.HelloDialogMatch2 || command == DialogMatches.HelloDialogMatch1)
            {
                return(await stepContext.BeginDialogAsync(
                           nameof(HelloDialog)));
            }
            else if (command == DialogMatches.Help)
            {
                return(await stepContext.BeginDialogAsync(
                           nameof(HelpDialog)));
            }
            else if (command == DialogMatches.MultiDialog1Match1)
            {
                return(await stepContext.BeginDialogAsync(
                           nameof(MultiDialog1)));
            }
            else if (command == DialogMatches.MultiDialog2Match)
            {
                return(await stepContext.BeginDialogAsync(
                           nameof(MultiDialog2)));
            }
            else if (command == DialogMatches.FecthLastExecutedDialogMatch)
            {
                return(await stepContext.BeginDialogAsync(
                           nameof(GetLastDialogUsedDialog)));
            }
            else if (command == DialogMatches.Send1to1Conversation)
            {
                return(await stepContext.BeginDialogAsync(
                           nameof(ProactiveMsgTo1to1Dialog)));
            }
            else if (command == DialogMatches.SetUpTextMsg)
            {
                return(await stepContext.BeginDialogAsync(
                           nameof(UpdateTextMsgSetupDialog)));
            }
            else if (command == DialogMatches.UpdateLastSetupTextMsg)
            {
                return(await stepContext.BeginDialogAsync(
                           nameof(UpdateTextMsgDialog)));
            }
            else if (command == DialogMatches.SetUpCardMsg)
            {
                return(await stepContext.BeginDialogAsync(
                           nameof(UpdateCardMsgSetupDialog)));
            }
            else if (command == DialogMatches.UpdateCard)
            {
                return(await stepContext.BeginDialogAsync(
                           nameof(UpdateCardMsgDialog)));
            }
            else if (command == DialogMatches.TeamInfo)
            {
                return(await stepContext.BeginDialogAsync(
                           nameof(FetchTeamsInfoDialog)));
            }
            else if (command == DialogMatches.DeepLinkTabCard)
            {
                return(await stepContext.BeginDialogAsync(
                           nameof(DeepLinkStaticTabDialog)));
            }
            else if (command == DialogMatches.AtMentionMatch1 || command == DialogMatches.AtMentionMatch2 || command == DialogMatches.AtMentionMatch3)
            {
                return(await stepContext.BeginDialogAsync(
                           nameof(AtMentionDialog)));
            }
            else if (command == DialogMatches.DialogFlowMatch)
            {
                await stepContext.Context.SendActivityAsync(Strings.DialogFlowStep1);

                await stepContext.Context.SendActivityAsync(Strings.DialogFlowStep2);

                await stepContext.BeginDialogAsync(
                    nameof(BeginDialogExampleDialog));

                await stepContext.Context.SendActivityAsync(Strings.DialogFlowStep3);

                return(await stepContext.EndDialogAsync(null, cancellationToken));
            }
            else if (command == DialogMatches.HeroCard)
            {
                return(await stepContext.BeginDialogAsync(
                           nameof(HeroCardDialog)));
            }
            else if (command == DialogMatches.ThumbnailCard)
            {
                return(await stepContext.BeginDialogAsync(
                           nameof(ThumbnailcardDialog)));
            }
            else if (command == DialogMatches.MessageBack)
            {
                return(await stepContext.BeginDialogAsync(
                           nameof(MessagebackDialog)));
            }
            else if (command == DialogMatches.AdaptiveCard)
            {
                return(await stepContext.BeginDialogAsync(
                           nameof(AdaptiveCardDialog)));
            }
            else if (command == DialogMatches.PopUpSignIn)
            {
                return(await stepContext.BeginDialogAsync(
                           nameof(PopupSigninCardDialog)));
            }
            else if (command == DialogMatches.RunQuizQuestionsMatch)
            {
                await stepContext.Context.SendActivityAsync(Strings.QuizTitleWelcomeMsg);

                return(await stepContext.BeginDialogAsync(
                           nameof(QuizFullDialog)));
            }
            else if (command == DialogMatches.PromptFlowGameMatch)
            {
                return(await stepContext.BeginDialogAsync(
                           nameof(PromptDialog)));
            }
            else if (command == DialogMatches.DisplayCards)
            {
                return(await stepContext.BeginDialogAsync(
                           nameof(DisplayCardsDialog)));
            }
            else if (command == DialogMatches.StopShowingCards)
            {
                await stepContext.Context.SendActivityAsync(Strings.DisplayCardsThanksMsg);

                return(await stepContext.EndDialogAsync(null, cancellationToken));
            }
            else if (command == DialogMatches.LocalTime)
            {
                await stepContext.Context.SendActivityAsync(Strings.UTCTimeZonePrompt + stepContext.Context.Activity.Timestamp);

                await stepContext.Context.SendActivityAsync(Strings.LocalTimeZonePrompt + stepContext.Context.Activity.LocalTimestamp);

                return(await stepContext.EndDialogAsync(null, cancellationToken));
            }
            else if (command == DialogMatches.O365ConnectorCardDefault || command == DialogMatches.DisplayCardO365ConnectorCard2 || command == DialogMatches.DisplayCardO365ConnectorCard3)
            {
                return(await stepContext.BeginDialogAsync(
                           nameof(O365ConnectorCardDialog)));
            }
            else if (command == DialogMatches.O365ConnectorCardActionableCardDefault || command == DialogMatches.DisplayCardO365ConnectorActionableCard2)
            {
                return(await stepContext.BeginDialogAsync(
                           nameof(O365ConnectorCardActionsDialog)));
            }
            else if (command == DialogMatches.AuthSample)
            {
                var message = CreateAuthSampleMessage(stepContext);
                await stepContext.Context.SendActivityAsync(message);

                return(await stepContext.EndDialogAsync());
            }
            else if (command == DialogMatches.Facebooklogin)
            {
                return(await stepContext.BeginDialogAsync(
                           nameof(SimpleFacebookAuthDialog)));
            }
            // We shouldn't get here, but fail gracefully if we do.
            await stepContext.Context.SendActivityAsync(
                "I don't recognize that option.",
                cancellationToken : cancellationToken);

            // Continue through to the next step without starting a child dialog.
            return(await stepContext.EndDialogAsync(null, cancellationToken));
        }
        /// <summary>
        /// POST: api/Messages
        /// Receive a message from a user and reply to it
        /// </summary>
        public async Task <HttpResponseMessage> Post([FromBody] Activity activity, CancellationToken cancellationToken)
        {
            var connectorClient = new ConnectorClient(new Uri(activity.ServiceUrl));

            if (activity.Type == ActivityTypes.Message)
            {
                // Special handling for a command to simulate a reset of the bot chat
                if (!(activity.Conversation.IsGroup ?? false) && (activity.Text == "/resetbotchat"))
                {
                    return(await HandleResetBotChatAsync(activity, cancellationToken));
                }

                //Set the Locale for Bot
                activity.Locale = TemplateUtility.GetLocale(activity);

                //Strip At mention from incoming request text
                activity = Middleware.StripAtMentionText(activity);

                //Convert incoming activity text to lower case, to match the intent irrespective of incoming text case
                activity = Middleware.ConvertActivityTextToLower(activity);

                //Set the OFFICE_365_TENANT_FILTER key in web.config file with Tenant Information
                //Validate bot for specific teams tenant if any
                if (Middleware.RejectMessageBasedOnTenant(activity, activity.GetTenantId()))
                {
                    Activity replyActivity = activity.CreateReply();
                    replyActivity.Text = Strings.TenantLevelDeniedAccess;

                    await connectorClient.Conversations.ReplyToActivityAsync(replyActivity);

                    return(Request.CreateResponse(HttpStatusCode.OK));
                }

                // Set activity text if request is from an adaptive card submit action
                activity = Middleware.AdaptiveCardSubmitActionHandler(activity);

                await Conversation.SendAsync(activity, () => new RootDialog());
            }
            else if (activity.Type == ActivityTypes.MessageReaction)
            {
                var      reactionsAdded   = activity.ReactionsAdded;
                var      reactionsRemoved = activity.ReactionsRemoved;
                var      replytoId        = activity.ReplyToId;
                Activity reply;

                if (reactionsAdded != null && reactionsAdded.Count > 0)
                {
                    reply = activity.CreateReply(Strings.LikeMessage);
                    await connectorClient.Conversations.ReplyToActivityAsync(reply);
                }
                else if (reactionsRemoved != null && reactionsRemoved.Count > 0)
                {
                    reply = activity.CreateReply(Strings.RemoveLike);
                    await connectorClient.Conversations.ReplyToActivityAsync(reply);
                }

                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            else if (activity.Type == ActivityTypes.Invoke) // Received an invoke
            {
                // Handle ComposeExtension query
                if (activity.IsComposeExtensionQuery())
                {
                    WikipediaComposeExtension wikipediaComposeExtension = new WikipediaComposeExtension();
                    HttpResponseMessage       httpResponse = null;

                    using (var scope = DialogModule.BeginLifetimeScope(Conversation.Container, activity))
                    {
                        var botDataStore = scope.Resolve <IBotDataStore <BotData> >();
                        // Handle compose extension selected item
                        if (activity.Name == "composeExtension/selectItem")
                        {
                            // This handler is used to process the event when a user in Teams selects wiki item from wiki result
                            ComposeExtensionResponse selectedItemResponse = await wikipediaComposeExtension.HandleComposeExtensionSelectedItem(activity, botDataStore);

                            httpResponse = Request.CreateResponse <ComposeExtensionResponse>(HttpStatusCode.OK, selectedItemResponse);
                        }
                        else
                        {
                            // Handle the wiki compose extension request and returned the wiki result response
                            ComposeExtensionResponse composeExtensionResponse = await wikipediaComposeExtension.GetComposeExtensionResponse(activity, botDataStore);

                            httpResponse = Request.CreateResponse <ComposeExtensionResponse>(HttpStatusCode.OK, composeExtensionResponse);
                        }

                        var address = Address.FromActivity(activity);
                        await botDataStore.FlushAsync(address, CancellationToken.None);
                    }
                    return(httpResponse);
                }
                //Actionable Message
                else if (activity.IsO365ConnectorCardActionQuery())
                {
                    // this will handle the request coming any action on Actionable messages
                    return(await HandleO365ConnectorCardActionQuery(activity));
                }
                //PopUp SignIn
                else if (activity.Name == "signin/verifyState")
                {
                    // this will handle the request coming from PopUp SignIn
                    return(await PopUpSignInHandler(activity));
                }
                // Handle rest of the invoke request
                else
                {
                    var messageActivity = (IMessageActivity)null;

                    //this will parse the invoke value and change the message activity as well
                    messageActivity = InvokeHandler.HandleInvokeRequest(activity);

                    await Conversation.SendAsync(messageActivity, () => new Dialogs.RootDialog());

                    return(Request.CreateResponse(HttpStatusCode.OK));
                }
            }
            else
            {
                await HandleSystemMessageAsync(activity, connectorClient, cancellationToken);
            }

            var response = Request.CreateResponse(HttpStatusCode.OK);

            return(response);
        }