/// <summary>
        /// Handle message extension action fetch task received by the bot.
        /// </summary>
        /// <param name="turnContext">Provides context for a turn of a bot.</param>
        /// <param name="action">Messaging extension action value payload.</param>
        /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
        /// <returns>A task that returns messagingExtensionActionResponse.</returns>
        protected override async Task <MessagingExtensionActionResponse> OnTeamsMessagingExtensionFetchTaskAsync(ITurnContext <IInvokeActivity> turnContext, MessagingExtensionAction action, CancellationToken cancellationToken)
        {
            var activity = turnContext.Activity;

            var activityState = ((JObject)activity.Value).GetValue("state")?.ToString();
            var tokenResponse = await(turnContext.Adapter as IUserTokenProvider).GetUserTokenAsync(turnContext, this.connectionName, activityState, cancellationToken);

            if (tokenResponse == null)
            {
                var signInLink = await(turnContext.Adapter as IUserTokenProvider).GetOauthSignInLinkAsync(turnContext, this.connectionName, cancellationToken);

                return(new MessagingExtensionActionResponse
                {
                    ComposeExtension = new MessagingExtensionResult
                    {
                        Type = MessagingExtensionAuthType,
                        SuggestedActions = new MessagingExtensionSuggestedAction
                        {
                            Actions = new List <CardAction>
                            {
                                new CardAction
                                {
                                    Type = ActionTypes.OpenUrl,
                                    Value = signInLink,
                                    Title = Strings.SigninCardText,
                                },
                            },
                        },
                    },
                });
            }

            var teamInformation = activity.TeamsGetTeamInfo();

            if (teamInformation == null || string.IsNullOrEmpty(teamInformation.Id))
            {
                return(new MessagingExtensionActionResponse
                {
                    Task = new TaskModuleContinueResponse
                    {
                        Value = new TaskModuleTaskInfo
                        {
                            Card = GroupActivityCard.GetTeamNotFoundErrorCard(),
                            Height = TaskModuleValidationHeight,
                            Width = TaskModuleValidationWidth,
                            Title = Strings.GroupActivityTitle,
                        },
                    },
                });
            }

            TeamDetails teamDetails;

            try
            {
                teamDetails = await TeamsInfo.GetTeamDetailsAsync(turnContext, teamInformation.Id, cancellationToken);
            }
            catch (Exception ex)
            {
                // if bot is not installed in team or not able to team roster, then show error response.
                this.logger.LogError("Bot is not part of team roster", ex);
                return(new MessagingExtensionActionResponse
                {
                    Task = new TaskModuleContinueResponse
                    {
                        Value = new TaskModuleTaskInfo()
                        {
                            Card = GroupActivityCard.GetTeamNotFoundErrorCard(),
                            Height = TaskModuleHeight,
                            Width = TaskModuleHeight,
                        },
                    },
                });
            }

            if (teamDetails == null)
            {
                this.logger.LogInformation($"Team details obtained is null.");
                return(new MessagingExtensionActionResponse
                {
                    Task = new TaskModuleContinueResponse
                    {
                        Value = new TaskModuleTaskInfo
                        {
                            Card = GroupActivityCard.GetErrorMessageCard(),
                            Height = TaskModuleValidationHeight,
                            Width = TaskModuleValidationWidth,
                            Title = Strings.GroupActivityTitle,
                        },
                    },
                });
            }

            var isTeamOwner = await this.teamUserHelper.VerifyIfUserIsTeamOwnerAsync(tokenResponse.Token, teamDetails.AadGroupId, activity.From.AadObjectId);

            if (isTeamOwner == null)
            {
                await turnContext.SendActivityAsync(Strings.CustomErrorMessage);

                return(new MessagingExtensionActionResponse
                {
                    Task = new TaskModuleContinueResponse
                    {
                        Value = new TaskModuleTaskInfo
                        {
                            Card = GroupActivityCard.GetErrorMessageCard(),
                            Height = TaskModuleValidationHeight,
                            Width = TaskModuleValidationWidth,
                            Title = Strings.GroupActivityTitle,
                        },
                    },
                });
            }

            // If user is team member validation message is shown as only team owner can create a group activity.
            if (isTeamOwner == false)
            {
                return(new MessagingExtensionActionResponse
                {
                    Task = new TaskModuleContinueResponse
                    {
                        Value = new TaskModuleTaskInfo
                        {
                            Card = GroupActivityCard.GetTeamOwnerErrorCard(),
                            Height = TaskModuleValidationHeight,
                            Width = TaskModuleValidationWidth,
                            Title = Strings.GroupActivityTitle,
                        },
                    },
                });
            }

            // Team owner can create group activity.
            return(new MessagingExtensionActionResponse
            {
                Task = new TaskModuleContinueResponse
                {
                    Value = new TaskModuleTaskInfo
                    {
                        Card = GroupActivityCard.GetCreateGroupActivityCard(),
                        Height = TaskModuleHeight,
                        Width = TaskModuleWidth,
                        Title = Strings.GroupActivityTitle,
                    },
                },
            });
        }