microsoft/teams.net

Public

mirrored from https://github.com/microsoft/teams.netAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
samples/migration-bot

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

core/src/Microsoft.Teams.Bot.Apps/Api/TeamsOperationsApi.cs

109lines · modecode

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4using Microsoft.Teams.Bot.Apps.Schema;
5using Microsoft.Teams.Bot.Core.Schema;
6
7namespace Microsoft.Teams.Bot.Apps.Api;
8
9using CustomHeaders = Dictionary<string, string>;
10
11/// <summary>
12/// Provides Teams-specific operations for managing teams and channels.
13/// </summary>
14public class TeamsOperationsApi
15{
16 private readonly TeamsApiClient _client;
17
18 /// <summary>
19 /// Initializes a new instance of the <see cref="TeamsOperationsApi"/> class.
20 /// </summary>
21 /// <param name="teamsApiClient">The Teams API client for team operations.</param>
22 internal TeamsOperationsApi(TeamsApiClient teamsApiClient)
23 {
24 _client = teamsApiClient;
25 }
26
27 /// <summary>
28 /// Gets details for a team.
29 /// </summary>
30 /// <param name="teamId">The ID of the team.</param>
31 /// <param name="serviceUrl">The service URL for the Teams service.</param>
32 /// <param name="agenticIdentity">Optional agentic identity for authentication.</param>
33 /// <param name="customHeaders">Optional custom headers to include in the request.</param>
34 /// <param name="cancellationToken">A cancellation token that can be used to cancel the operation.</param>
35 /// <returns>A task that represents the asynchronous operation. The task result contains the team details.</returns>
36 public Task<TeamDetails> GetByIdAsync(
37 string teamId,
38 Uri serviceUrl,
39 AgenticIdentity? agenticIdentity = null,
40 CustomHeaders? customHeaders = null,
41 CancellationToken cancellationToken = default)
42 => _client.FetchTeamDetailsAsync(teamId, serviceUrl, agenticIdentity, customHeaders, cancellationToken);
43
44 /// <summary>
45 /// Gets details for a team using activity context, extracting the team ID from channel data.
46 /// </summary>
47 /// <param name="activity">The activity providing team ID, service URL, and identity context.</param>
48 /// <param name="customHeaders">Optional custom headers to include in the request.</param>
49 /// <param name="cancellationToken">A cancellation token that can be used to cancel the operation.</param>
50 /// <returns>A task that represents the asynchronous operation. The task result contains the team details.</returns>
51 public Task<TeamDetails> GetByIdAsync(
52 TeamsActivity activity,
53 CustomHeaders? customHeaders = null,
54 CancellationToken cancellationToken = default)
55 {
56 ArgumentNullException.ThrowIfNull(activity);
57 ArgumentNullException.ThrowIfNull(activity.ServiceUrl);
58 string? teamId = activity.ChannelData?.Team?.Id;
59 ArgumentException.ThrowIfNullOrWhiteSpace(teamId, "activity.ChannelData.Team.Id");
60
61 return _client.FetchTeamDetailsAsync(
62 teamId,
63 activity.ServiceUrl,
64 activity.From?.GetAgenticIdentity(),
65 customHeaders,
66 cancellationToken);
67 }
68
69 /// <summary>
70 /// Gets the list of channels for a team.
71 /// </summary>
72 /// <param name="teamId">The ID of the team.</param>
73 /// <param name="serviceUrl">The service URL for the Teams service.</param>
74 /// <param name="agenticIdentity">Optional agentic identity for authentication.</param>
75 /// <param name="customHeaders">Optional custom headers to include in the request.</param>
76 /// <param name="cancellationToken">A cancellation token that can be used to cancel the operation.</param>
77 /// <returns>A task that represents the asynchronous operation. The task result contains the list of channels.</returns>
78 public Task<ChannelList> GetChannelsAsync(
79 string teamId,
80 Uri serviceUrl,
81 AgenticIdentity? agenticIdentity = null,
82 CustomHeaders? customHeaders = null,
83 CancellationToken cancellationToken = default)
84 => _client.FetchChannelListAsync(teamId, serviceUrl, agenticIdentity, customHeaders, cancellationToken);
85
86 /// <summary>
87 /// Gets the list of channels for a team using activity context.
88 /// </summary>
89 /// <param name="activity">The activity providing service URL and identity context.</param>
90 /// <param name="customHeaders">Optional custom headers to include in the request.</param>
91 /// <param name="cancellationToken">A cancellation token that can be used to cancel the operation.</param>
92 /// <returns>A task that represents the asynchronous operation. The task result contains the list of channels.</returns>
93 public Task<ChannelList> GetChannelsAsync(
94 TeamsActivity activity,
95 CustomHeaders? customHeaders = null,
96 CancellationToken cancellationToken = default)
97 {
98 ArgumentNullException.ThrowIfNull(activity);
99 ArgumentNullException.ThrowIfNull(activity.ServiceUrl);
100 ArgumentException.ThrowIfNullOrWhiteSpace(activity.ChannelData?.Team?.Id, "activity.ChannelData.Team.Id");
101
102 return _client.FetchChannelListAsync(
103 activity.ChannelData.Team.Id,
104 activity.ServiceUrl,
105 activity.From?.GetAgenticIdentity(),
106 customHeaders,
107 cancellationToken);
108 }
109}
110