Esempio n. 1
0
        private async Task HandleOptOut(
            ConnectorClient connectorClient,
            Activity activity,
            string tenantId,
            UserAndTeam userAndTeam,
            bool isAnotherUser)
        {
            var userId   = userAndTeam.User.UserAadId;
            var userName = userAndTeam.User.UserName;
            var teamId   = userAndTeam.Team.TeamId;
            var teamName = userAndTeam.Team.TeamName;

            // User opted out
            this.telemetryClient.TrackTrace($"User {userId} opted out");

            var properties = new Dictionary <string, string>
            {
                { "UserAadId", userId },
                { "OptInStatus", "false" },
            };

            this.telemetryClient.TrackEvent("UserOptInStatusSet", properties);

            var isSuccessful = await this.bot.OptOutUser(tenantId, userId, teamId);

            var optOutReply = activity.CreateReply();

            if (isSuccessful)
            {
                var text = isAnotherUser ? string.Format(Resources.OptOutConfirmationAnotherUser, userName, teamName) :
                           string.Format(Resources.OptOutConfirmation, teamName);

                var actionText = string.Format(Resources.ResumePairingsButtonText, teamName);

                optOutReply.Attachments = new List <Attachment>
                {
                    new HeroCard()
                    {
                        Text    = text,
                        Buttons = new List <CardAction>()
                        {
                            new CardAction()
                            {
                                Title       = actionText,
                                DisplayText = actionText,
                                Type        = ActionTypes.MessageBack,
                                Text        = MessageIds.OptIn,
                                Value       = JsonConvert.SerializeObject(userAndTeam)
                            }
                        }
                    }.ToAttachment(),
                };
            }
            else
            {
                optOutReply.Text = Resources.OptOutUserFailText;
            }

            await connectorClient.Conversations.ReplyToActivityAsync(optOutReply);
        }
        private async Task HandleAdminEditUser(string msgId, ConnectorClient connectorClient, Activity activity, string senderAadId)
        {
            // Choose user prompt based on the team, then show the edit any user card once we have the user
            var teamContext = ActivityHelper.ParseCardActionData <TeamContext>(activity);

            if (teamContext != null)
            {
                // Once there's too many users (>100?) we can get an RequestEntityTooLarge status code if
                // we pass in the users to be shown in the dropdown.
                // Just ask for the user name as a text input through passing an empty user list.
                var users        = new List <ChooseUserAdaptiveCard.User>();
                var pickUserCard = ChooseUserAdaptiveCard.GetCard(users, teamContext, msgId);
                await ActivityHelper.ReplyWithAdaptiveCard(connectorClient, activity, pickUserCard);

                return;
            }

            var chooseUserResult = ActivityHelper.ParseCardActionData <ChooseUserResult>(activity);

            if (chooseUserResult == null)
            {
                return;
            }

            if (string.IsNullOrEmpty(chooseUserResult.UserNameInput))
            {
                var errorMsg = Resources.ChooseUserNoUserName;
                await connectorClient.Conversations.ReplyToActivityAsync(activity.CreateReply(errorMsg));

                return;
            }

            var allMembers = await connectorClient.Conversations.GetConversationMembersAsync(chooseUserResult.TeamContext.TeamId);

            var user = allMembers.FirstOrDefault(u => u.Name.ToLower() == chooseUserResult.UserNameInput.Trim().ToLower());

            if (user == null)
            {
                var errorMsg = string.Format(Resources.ChooseUserUnrecognizedUserName, chooseUserResult.UserNameInput);
                await connectorClient.Conversations.ReplyToActivityAsync(activity.CreateReply(errorMsg));

                return;
            }

            var userAndTeam = new UserAndTeam {
                Team = chooseUserResult.TeamContext, User = new UserContext {
                    UserAadId = user.GetUserId(), UserName = user.Name
                }
            };

            await this.SendEditAnyUserCard(connectorClient, activity, ActivityHelper.GetTenantId(activity), userAndTeam);
        }
Esempio n. 3
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>
 /// Returns a list of user actions that are invoked when an admin wishes to perform the action on behalf of someone else
 /// </summary>
 /// <param name="userAndTeam">user and team info</param>
 /// <param name="enrollmentStatus">enrollment status for the team</param>
 /// <returns>List of user actions</returns>
 public static List <AdaptiveAction> CreateUserActionsForAdmin(UserAndTeam userAndTeam, EnrollmentStatus enrollmentStatus)
 {
     return(CreateUserActions(enrollmentStatus, userAndTeam.Team.TeamName, userAndTeam));
 }
        /// <summary>
        /// Handle editing the user with a specified user
        /// </summary>
        /// <param name="connectorClient">connector client</param>
        /// <param name="activity">activity</param>
        /// <param name="tenantId">user's tenant id</param>
        /// <param name="userAndTeam">user and team info</param>
        /// <returns>Task</returns>
        private async Task SendEditAnyUserCard(ConnectorClient connectorClient, Activity activity, string tenantId, UserAndTeam userAndTeam)
        {
            // Provide the user actions for the user
            var userInfo = await this.bot.GetOrCreateUnpersistedUserInfo(tenantId, userAndTeam.User.UserAadId);

            var userStatus = userInfo.GetStatusInTeam(userAndTeam.Team.TeamId);

            var editUserCard = EditAnyUserAdaptiveCard.GetCard(userStatus, userAndTeam);
            await ActivityHelper.ReplyWithAdaptiveCard(connectorClient, activity, editUserCard);
        }