/// <summary>
        /// Generates the adaptive card string for the unrecognized input.
        /// </summary>
        /// <param name="actionsTeamContext">Team context for the actions</param>
        /// <param name="userStatusForTeam">Enrollment status for the actionsTeamContext for the user</param>
        /// <param name="showAdminActions">Whether to show the admin actions</param>
        /// <returns>The adaptive card for the unrecognized input</returns>
        public static string GetCardJson(TeamContext actionsTeamContext, EnrollmentStatus userStatusForTeam, bool showAdminActions)
        {
            var messageContent = Resources.UnrecognizedInput;

            var card = new AdaptiveCard(new AdaptiveSchemaVersion(1, 0))
            {
                Body = new List <AdaptiveElement>
                {
                    new AdaptiveTextBlock()
                    {
                        Text = messageContent,
                        Wrap = true
                    }
                }
            };

            card.Actions = new List <AdaptiveAction>();

            card.Actions.AddRange(AdaptiveCardHelper.CreateUserActions(actionsTeamContext, userStatusForTeam));

            if (showAdminActions)
            {
                var adminActions = AdaptiveCardHelper.CreateAdminActions(actionsTeamContext);
                card.Actions.AddRange(adminActions);
            }

            return(card.ToJson());
        }
        /// <summary>
        /// Generates the adaptive card string for the unrecognized input in a channel.
        /// It invites the user to chat directly with the bot.
        /// </summary>
        /// <param name="botChannelAccountId">bot ChannelAccount id for deep link to work</param>
        /// <param name="teamId">Team id of the channel this message is for</param>
        /// <returns>The adaptive card for the unrecognized input</returns>
        public static AdaptiveCard GetCard(string botChannelAccountId, string teamId)
        {
            var botMessage = AdaptiveCardHelper.GetChatWithMeMessage(teamId);

            var card = new AdaptiveCard(new AdaptiveSchemaVersion(1, 0))
            {
                Body = new List <AdaptiveElement>
                {
                    new AdaptiveTextBlock
                    {
                        Text = "👋 " + Resources.UnrecognizedInputInChannelText,
                        Wrap = true
                    }
                },
                Actions = new List <AdaptiveAction>
                {
                    new AdaptiveOpenUrlAction
                    {
                        Title = Resources.ChatWithMeButtonText,
                        Url   = new System.Uri("https://teams.microsoft.com/l/chat/0/0?users=" + botChannelAccountId + "&message=" + botMessage)
                    }
                }
            };

            return(card);
        }
        /// <summary>
        /// Creates the editable user profile card
        /// </summary>
        /// <param name="userId">User id the profile is for</param>
        /// <param name="userName">User name the profile is for</param>
        /// <param name="teamName">Team name subteam name hint is for</param>
        /// <param name="discipline">User discipline</param>
        /// <param name="gender">User gender</param>
        /// <param name="seniority">User seniority</param>
        /// <param name="teams">Sub team names the user has been on</param>
        /// <param name="subteamNamesHint">List of suggested sub team names. Can be empty</param>
        /// <param name="lowPreferenceNames">List of full names the user has low preference for. Can be empty</param>
        /// <param name="isOnBehalfOfAnotherUser">Show different title when this card is show for another user</param>
        /// <returns>user profile card</returns>
        public static string GetCardJson(
            string userId,
            string userName,
            string teamName,
            string discipline,
            string gender,
            string seniority,
            List <string> teams,
            string subteamNamesHint,
            List <string> lowPreferenceNames,
            bool isOnBehalfOfAnotherUser = false)
        {
            var teamNamesHint = string.IsNullOrEmpty(subteamNamesHint) ? string.Empty : $"Teams in {teamName}: " + subteamNamesHint;

            // TODO: Lots of strings to put in the resources including those in the json file
            var variablesToValues = new Dictionary <string, string>()
            {
                { "title", isOnBehalfOfAnotherUser ? $"Edit Profile for {userName}" : $"Tell me about yourself" },
                { "description", "This helps me improve your matches." },
                { "defaultDiscipline", GetValueOrDefault(discipline, DEFAULTDISCIPLINE) },
                { "defaultGender", GetValueOrDefault(gender, DEFAULTGENDER) },
                { "defaultSeniority", GetValueOrDefault(seniority, DEFAULTSENIORITY) },
                { "defaultTeams", string.Join(TeamsSeparatorWithSpace, teams) },
                { "teamNamesHint", teamNamesHint },
                { "defaultLowPreferenceNames", string.Join(NamesSeparatorWithSpace, lowPreferenceNames) },
                { "userId", userId }
            };

            return(AdaptiveCardHelper.ReplaceTemplateKeys(CardTemplate, variablesToValues));
        }
        /// <summary>
        /// Creates the welcome new member card that welcomes the user to a specific team.
        /// </summary>
        /// <param name="teamContext">Team context for the card.</param>
        /// <param name="userStatus">User status</param>
        /// <param name="botInstallerName">The name of the person that installed the bot to the team. Can be empty.</param>
        /// <param name="showAdminActions">Whether to show the admin actions</param>
        /// <returns>The welcome new member card</returns>
        public static AdaptiveCard GetCard(TeamContext teamContext, EnrollmentStatus userStatus, string botInstallerName, bool showAdminActions)
        {
            string introMessagePart1;

            if (string.IsNullOrEmpty(botInstallerName))
            {
                introMessagePart1 = string.Format(Resources.InstallMessageUnknownInstaller, teamContext.TeamName);
            }
            else
            {
                introMessagePart1 = string.Format(Resources.InstallMessageKnownInstaller, botInstallerName, teamContext.TeamName);
            }

            var introMessagePart2 = Resources.InstallMessageBotDescription;
            var introMessagePart3 = showAdminActions ? Resources.InstallMessageInstructionAdmin : Resources.InstallMessageInstruction;
            var suggestedNextStep = showAdminActions ?
                                    string.Format(Resources.InstallMessageSuggestedNextStepAdmin, Resources.MakePairsButtonText) : Resources.InstallMessageSuggestedNextStep;

            var baseDomain          = CloudConfigurationManager.GetSetting("AppBaseDomain");
            var welcomeCardImageUrl = $"https://{baseDomain}/Content/welcome-card-image.png";

            var salutationText = Resources.SalutationTitleText;

            var variablesToValues = new Dictionary <string, string>()
            {
                { "salutationText", salutationText },
                { "welcomeCardImageUrl", welcomeCardImageUrl },
                { "introMessagePart1", introMessagePart1 },
                { "introMessagePart2", introMessagePart2 },
                { "introMessagePart3", introMessagePart3 },
                { "suggestedNextStep", suggestedNextStep },
            };

            var cardBody = AdaptiveCardHelper.ReplaceTemplateKeys(CardTemplate, variablesToValues);
            var card     = AdaptiveCard.FromJson(cardBody).Card;

            if (showAdminActions)
            {
                var adminActions = AdaptiveCardHelper.CreateAdminActions(teamContext);
                card.Actions.AddRange(adminActions);
            }

            var userActions = AdaptiveCardHelper.CreateUserActions(teamContext, userStatus);

            card.Actions.AddRange(userActions);

            return(card);
        }
        /// <summary>
        /// Creates the adaptive card for the team welcome message
        /// </summary>
        /// <param name="teamName">The team name</param>
        /// <param name="teamId">Team id</param>
        /// <param name="botChannelAccountId">Bot id that will allow deeplink to chat with the bot</param>
        /// <param name="botInstaller">The name of the person that installed the bot</param>
        /// <returns>The welcome team adaptive card</returns>
        public static string GetCardJson(string teamName, string teamId, string botChannelAccountId, string botInstaller)
        {
            string teamIntroPart1;

            if (string.IsNullOrEmpty(botInstaller))
            {
                teamIntroPart1 = string.Format(Resources.InstallMessageUnknownInstaller, teamName);
            }
            else
            {
                teamIntroPart1 = string.Format(Resources.InstallMessageKnownInstaller, botInstaller, teamName);
            }

            string teamIntroPart2    = Resources.InstallMessageBotDescription;
            string teamIntroPart3    = Resources.InstallMessageInstruction;
            var    suggestedNextStep = Resources.WelcomeTeamSuggestedNextStep;

            var baseDomain           = CloudConfigurationManager.GetSetting("AppBaseDomain");
            var welcomeCardImageUrl  = $"https://{baseDomain}/Content/welcome-card-image.png";
            var salutationText       = Resources.SalutationTitleText;
            var chatWithMeButtonText = Resources.ChatWithMeButtonText;

            var variablesToValues = new Dictionary <string, string>()
            {
                { "teamIntroPart1", teamIntroPart1 },
                { "teamIntroPart2", teamIntroPart2 },
                { "teamIntroPart3", teamIntroPart3 },
                { "suggestedNextStep", suggestedNextStep },
                { "welcomeCardImageUrl", welcomeCardImageUrl },
                { "salutationText", salutationText },
                { "chatWithMeButtonText", chatWithMeButtonText },
                { "botChatId", botChannelAccountId },
                { "botMessage", AdaptiveCardHelper.GetChatWithMeMessage(teamId) }
            };

            var cardBody = CardTemplate;

            foreach (var kvp in variablesToValues)
            {
                cardBody = cardBody.Replace($"%{kvp.Key}%", kvp.Value);
            }

            return(cardBody);
        }
        /// <summary>
        /// Creates the edit team settings card
        /// </summary>
        /// <param name="teamId">Team id</param>
        /// <param name="teamName">User discipline</param>
        /// <param name="adminUser">Admin user. Can be null if bot installed by Graph or changed to no admin</param>
        /// <param name="teamNotifyMode">How pairings will be notified</param>
        /// <param name="subteamNames">Sub team names hints for Edit Profile page</param>
        /// <returns>user profile card</returns>
        public static AdaptiveCard GetCard(string teamId, string teamName, User adminUser, string teamNotifyMode, string subteamNames)
        {
            var variablesToValues = new Dictionary <string, string>()
            {
                { "teamId", teamId },
                { "teamName", teamName },
                { "noApprovalValue", TeamInstallInfo.NotifyModeNoApproval },
                { "needApprovalValue", TeamInstallInfo.NotifyModeNeedApproval },
                { "defaultNotifyMode", teamNotifyMode },
                { "subteamNames", subteamNames },
                { "adminUserName", adminUser == null ? string.Empty : adminUser.Name },
                { "originalAdminUserId", adminUser == null ? string.Empty : adminUser.AadId },
                { "originalAdminUserName", adminUser == null ? string.Empty : adminUser.Name }
            };

            var cardJson = AdaptiveCardHelper.ReplaceTemplateKeys(CardTemplate, variablesToValues);

            // There is an AdaptiveCard template library but it's only for .NET core.
            var card = AdaptiveCard.FromJson(cardJson).Card;

            return(card);
        }
        /// <summary>
        /// Creates the read only team settings card
        /// </summary>
        /// <param name="adminUserName">Admin user name</param>
        /// <param name="notifyMode">Notify mode</param>
        /// <param name="subteamNames">Subteam names</param>
        /// <returns>team settings card</returns>
        public static AdaptiveCard GetResultCard(string adminUserName, string notifyMode, string subteamNames)
        {
            var notifyModeDisplay = string.Empty;

            switch (notifyMode)
            {
            case TeamInstallInfo.NotifyModeNeedApproval:
                notifyModeDisplay = "Need Approval";
                break;

            case TeamInstallInfo.NotifyModeNoApproval:
                notifyModeDisplay = "No Approval";
                break;
            }

            var pairs = new List <Tuple <string, string> >()
            {
                new Tuple <string, string>("Admin User", GetAdminText(adminUserName)),
                new Tuple <string, string>("Subteam Names", GetUIText(subteamNames)),
                new Tuple <string, string>("Notify Mode", notifyModeDisplay)
            };

            return(AdaptiveCardHelper.CreateSubmitResultCard("Saved Team Settings", pairs));
        }
示例#8
0
        /// <summary>
        /// Creates the editable user profile card which uses the EditUserProfileAdaptiveCard contents and adds
        /// an additional input for changing the opt in status
        /// </summary>
        /// <param name="userStatus">whether user is opted in to matches</param>
        /// <param name="userAndTeam">User and team info</param>
        /// <returns>Edit any user card</returns>
        public static AdaptiveCard GetCard(
            EnrollmentStatus userStatus,
            UserAndTeam userAndTeam)
        {
            var userName = userAndTeam.User.UserName;
            var teamName = userAndTeam.Team.TeamName;

            var card = new AdaptiveCard(new AdaptiveSchemaVersion(1, 2))
            {
                Body = new List <AdaptiveElement>
                {
                    new AdaptiveTextBlock()
                    {
                        Text   = $"Edit User info for {userName} in {teamName}",
                        Size   = AdaptiveTextSize.Large,
                        Wrap   = true,
                        Weight = AdaptiveTextWeight.Bolder
                    }
                }
            };

            card.Actions = AdaptiveCardHelper.CreateUserActionsForAdmin(userAndTeam, userStatus);
            return(card);
        }
        /// <summary>
        /// Creates the read only user profile card
        /// </summary>
        /// <param name="discipline">User discipline</param>
        /// <param name="gender">User gender</param>
        /// <param name="seniority">User seniority</param>
        /// <param name="teams">Sub team names the user has been on</param>
        /// <param name="lowPreferenceNames">Full names of low preference matches</param>
        /// <returns>user profile card</returns>
        public static AdaptiveCard GetResultCard(string discipline, string gender, string seniority, List <string> teams, List <string> lowPreferenceNames)
        {
            var pairs = GetDataForResultCard(discipline, gender, seniority, teams, lowPreferenceNames);

            return(AdaptiveCardHelper.CreateSubmitResultCard("Saved Profile", pairs));
        }