/// <summary> /// Generate first feedBackmessage to user1 about meetup with user2 /// </summary> /// <returns>The number of pairups that were made</returns> public async Task <int> CreateFeedbackMsgAndNotify() { this.telemetryClient.TrackTrace("generating feedback msgs"); var installedTeamsCount = 0; var pairsNotifiedCount = 0; var usersNotifiedCount = 0; try { var teams = await this.dataProvider.InstalledTeamsGet(); installedTeamsCount = teams.Count; this.telemetryClient.TrackTrace($"Generating pairs for {installedTeamsCount} teams"); foreach (var team in teams) { this.telemetryClient.TrackTrace($"Pairing members of team {team.Id}"); try { MicrosoftAppCredentials.TrustServiceUrl(team.ServiceUrl); var connectorClient = new ConnectorClient(new Uri(team.ServiceUrl)); var allUsers = await connectorClient.Conversations.GetConversationMembersAsync(team.TeamId); var allUsersList = allUsers.Select(x => new { User = x, ChannelAccount = x.AsTeamsChannelAccount() }) .ToList(); var startDate = DateTime.UtcNow.AddDays(-1 * Constants.FeedBackDelayDays); var dbMatchers = await dataProvider.UserMatchInfoSearchByDate(startDate); foreach (var userInfo in allUsersList) { var dbMatch = dbMatchers .Where(p => p.SenderAadId == userInfo.ChannelAccount.ObjectId) .OrderByDescending(p => p.Created) .FirstOrDefault(); if (dbMatch != null) { var senderDetails = await dataProvider.UserDetailsGet(dbMatch.SenderAadId); var recipientDetails = await dataProvider.UserDetailsGet(dbMatch.RecipientAadId); var card = FeedbackCard.GetCard(senderDetails?.GivenName, recipientDetails?.GivenName); await NotifyUser(connectorClient, card, userInfo.User, team.TenantId); await dataProvider.BotLastMessageUpdate( userInfo.ChannelAccount.ObjectId, userInfo.ChannelAccount.Email, BotMessageTypes.Fb); } } } catch (Exception ex) { this.telemetryClient.TrackTrace($"Error pairing up team members: {ex.Message}", SeverityLevel.Warning); this.telemetryClient.TrackException(ex); } } } catch (Exception ex) { this.telemetryClient.TrackTrace($"Error making pairups: {ex.Message}", SeverityLevel.Warning); this.telemetryClient.TrackException(ex); } // Log telemetry about the pairups var properties = new Dictionary <string, string> { { "InstalledTeamsCount", installedTeamsCount.ToString() }, { "PairsNotifiedCount", pairsNotifiedCount.ToString() }, { "UsersNotifiedCount", usersNotifiedCount.ToString() }, }; this.telemetryClient.TrackEvent("ProcessedPairups", properties); this.telemetryClient.TrackTrace($"Made {pairsNotifiedCount} pairups, {usersNotifiedCount} notifications sent"); return(pairsNotifiedCount); return(0); }