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

Libraries/Microsoft.Teams.Api/Clients/ReactionClient.cs

97lines · modecode

1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT License.
3
4using System.Diagnostics.CodeAnalysis;
5
6using Microsoft.Teams.Api.Messages;
7using Microsoft.Teams.Common.Http;
8
9namespace Microsoft.Teams.Api.Clients;
10
11/// <summary>
12/// Client for working with app message reactions for a given conversation/activity.
13/// </summary>
14[Experimental("ExperimentalTeamsReactions")]
15public class ReactionClient : Client
16{
17 public readonly string ServiceUrl;
18
19 public ReactionClient(string serviceUrl, CancellationToken cancellationToken = default)
20 : base(cancellationToken)
21 {
22 ServiceUrl = serviceUrl;
23 }
24
25 public ReactionClient(string serviceUrl, IHttpClient client, CancellationToken cancellationToken = default)
26 : base(client, cancellationToken)
27 {
28 ServiceUrl = serviceUrl;
29 }
30
31 public ReactionClient(string serviceUrl, IHttpClientOptions options, CancellationToken cancellationToken = default)
32 : base(options, cancellationToken)
33 {
34 ServiceUrl = serviceUrl;
35 }
36
37 public ReactionClient(string serviceUrl, IHttpClientFactory factory, CancellationToken cancellationToken = default)
38 : base(factory, cancellationToken)
39 {
40 ServiceUrl = serviceUrl;
41 }
42
43 /// <summary>
44 /// Adds a reaction on an activity in a conversation.
45 /// </summary>
46 /// <param name="conversationId">The conversation id.</param>
47 /// <param name="activityId">The id of the activity to react to.</param>
48 /// <param name="reactionType">
49 /// The reaction type (for example: "like", "heart", "launch", etc.).
50 /// </param>
51 /// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe while waiting for the task to complete.</param>
52 /// <returns>
53 /// A <see cref="Task"/> representing the asynchronous operation.
54 /// </returns>
55 public async Task AddAsync(
56 string conversationId,
57 string activityId,
58 ReactionType reactionType,
59 CancellationToken cancellationToken = default
60 )
61 {
62 // Assumed route:
63 // PUT v3/conversations/{conversationId}/activities/{activityId}/reactions/{reactionType}
64 var url = $"{ServiceUrl}v3/conversations/{conversationId}/activities/{activityId}/reactions/{reactionType}";
65 var req = HttpRequest.Put(url);
66 await _http.SendAsync(req, cancellationToken != default ? cancellationToken : _cancellationToken);
67 }
68
69 /// <summary>
70 /// Removes a reaction from an activity in a conversation.
71 /// </summary>
72 /// <param name="conversationId">The conversation id.</param>
73 /// <param name="activityId">The id of the activity the reaction is on.</param>
74 /// <param name="reactionType">
75 /// The reaction type to remove (for example: "like", "heart", "launch", etc.).
76 /// </param>
77 /// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe while waiting for the task to complete.</param>
78 /// <returns>
79 /// A <see cref="Task"/> representing the asynchronous operation.
80 /// </returns>
81 public async Task DeleteAsync(
82 string conversationId,
83 string activityId,
84 ReactionType reactionType,
85 CancellationToken cancellationToken = default
86 )
87 {
88 // Assumed route:
89 // DELETE v3/conversations/{conversationId}/activities/{activityId}/reactions/{reactionType}
90 var url =
91 $"{ServiceUrl}v3/conversations/{conversationId}/activities/{activityId}/reactions/{reactionType}";
92
93 var req = HttpRequest.Delete(url);
94
95 await _http.SendAsync(req, cancellationToken != default ? cancellationToken : _cancellationToken);
96 }
97}