/// <summary> /// Generate pairups and send pairup notifications. /// </summary> /// <returns>The number of pairups that were made</returns> public async Task <int> MakePairsAndNotify() { this.telemetryClient.TrackTrace("Making pairups"); // Recall all the teams where we have been added // For each team where bot has been added: // Pull the roster of the team // Remove the members who have opted out of pairups // Match each member with someone else // Save this pair // Now notify each pair found in 1:1 and ask them to reach out to the other person // When contacting the user in 1:1, give them the button to opt-out 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 teamName = await this.GetTeamNameAsync(connectorClient, team.TeamId); var optedInUsers = await this.GetOptedInUsers(connectorClient, team); foreach (var c in optedInUsers) { var t = c.AsTeamsChannelAccount(); await dataProvider.UserDetailsUpdate(t.ObjectId, t.GivenName, t.Name, t.Email, team.TenantId); } foreach (var pair in this.MakePairs(optedInUsers).Take(this.maxPairUpsPerTeam)) { usersNotifiedCount += await this.NotifyPair(connectorClient, team.TenantId, teamName, pair); pairsNotifiedCount++; } } 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); }