microsoft/teams.net
Publicmirrored fromhttps://github.com/microsoft/teams.netAvailable
core/test/TeamsApisDemo/Program.cs
46lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. |
| 2 | // Licensed under the MIT License. |
| 3 | |
| 4 | using Microsoft.Extensions.DependencyInjection; |
| 5 | using Microsoft.Extensions.Configuration; |
| 6 | using Microsoft.Extensions.Logging; |
| 7 | using Microsoft.Teams.Apps; |
| 8 | using Microsoft.Teams.Apps.Schema; |
| 9 | |
| 10 | IConfiguration configuration = new ConfigurationBuilder() |
| 11 | .SetBasePath(AppDomain.CurrentDomain.BaseDirectory) |
| 12 | .AddJsonFile("appsettings.json") |
| 13 | .AddEnvironmentVariables() |
| 14 | .Build(); |
| 15 | |
| 16 | ServiceCollection services = new ServiceCollection(); |
| 17 | services.AddSingleton(configuration); |
| 18 | services.AddLogging(c => { |
| 19 | c.AddConfiguration(configuration.GetSection("Logging")); |
| 20 | c.AddConsole(); |
| 21 | }); |
| 22 | services.AddTeamsBotApplication(); |
| 23 | var provider = services.BuildServiceProvider(); |
| 24 | var teamsBotApplication = provider.GetRequiredService<TeamsBotApplication>(); |
| 25 | Console.WriteLine($"Running Teams Bot Application for appId '{teamsBotApplication.AppId}' with version '{TeamsBotApplication.Version}'."); |
| 26 | |
| 27 | |
| 28 | var smba = new Uri("https://smba.trafficmanager.net/amer"); |
| 29 | var membersClient = teamsBotApplication.Api.ForServiceUrl(smba).Conversations.Members; |
| 30 | |
| 31 | int pages = 1; |
| 32 | string cid = "19%3ALydFnezGKSkhYoiLNP6kZ8AuXQr36EDAkvG9CNJSPKc1%40thread.tacv2"; |
| 33 | var paged = await membersClient.GetPagedAsync(cid, 52); |
| 34 | |
| 35 | List<TeamsConversationAccount?> members = [..paged.Members]; |
| 36 | |
| 37 | while (!string.IsNullOrEmpty(paged.ContinuationToken)) |
| 38 | { |
| 39 | Console.WriteLine("Getting next page of members..."); |
| 40 | paged = await membersClient.GetPagedAsync(cid, 52, paged.ContinuationToken); |
| 41 | members.AddRange(paged.Members); |
| 42 | pages++; |
| 43 | } |
| 44 | |
| 45 | Console.WriteLine("\n*****************\n"); |
| 46 | Console.WriteLine($"Total members: {members.Count} in {pages} pages."); |
| 47 | |