microsoft/teams.net

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
copilot/update-sample-to-blazor

Branches

Tags

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

Clone

HTTPS

Download ZIP

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

94lines · modecode

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