microsoft/teams.net
Publicmirrored from https://github.com/microsoft/teams.netAvailable
core/src/Microsoft.Teams.Bot.Apps/Api/ReactionsApi.cs
90lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. |
| 2 | // Licensed under the MIT License. |
| 3 | |
| 4 | using Microsoft.Teams.Bot.Apps.Schema; |
| 5 | using Microsoft.Teams.Bot.Core; |
| 6 | |
| 7 | namespace Microsoft.Teams.Bot.Apps.Api; |
| 8 | |
| 9 | using CustomHeaders = Dictionary<string, string>; |
| 10 | |
| 11 | /// <summary> |
| 12 | /// Provides reaction operations for adding and removing reactions on activities in conversations. |
| 13 | /// </summary> |
| 14 | public class ReactionsApi |
| 15 | { |
| 16 | private readonly ConversationClient _client; |
| 17 | |
| 18 | /// <summary> |
| 19 | /// Initializes a new instance of the <see cref="ReactionsApi"/> class. |
| 20 | /// </summary> |
| 21 | /// <param name="conversationClient">The conversation client for reaction operations.</param> |
| 22 | internal ReactionsApi(ConversationClient conversationClient) |
| 23 | { |
| 24 | _client = conversationClient; |
| 25 | } |
| 26 | |
| 27 | /// <summary> |
| 28 | /// Adds a reaction to an activity using activity context. |
| 29 | /// </summary> |
| 30 | /// <param name="activity">The activity to react to. Must contain valid Id, Conversation.Id, and ServiceUrl.</param> |
| 31 | /// <param name="activityId">The ID of the activity to react to. This is separate from activity.Id to allow reacting to a different activity than the one in context if needed.</param> |
| 32 | /// <param name="reactionType">The type of reaction to add (e.g., "like", "heart", "laugh").</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.</returns> |
| 36 | public Task AddAsync( |
| 37 | TeamsActivity activity, |
| 38 | string activityId, |
| 39 | string reactionType, |
| 40 | CustomHeaders? customHeaders = null, |
| 41 | CancellationToken cancellationToken = default) |
| 42 | { |
| 43 | ArgumentNullException.ThrowIfNull(activity); |
| 44 | ArgumentException.ThrowIfNullOrWhiteSpace(activityId); |
| 45 | ArgumentNullException.ThrowIfNull(activity.Conversation); |
| 46 | ArgumentException.ThrowIfNullOrWhiteSpace(activity.Conversation.Id); |
| 47 | ArgumentNullException.ThrowIfNull(activity.ServiceUrl); |
| 48 | |
| 49 | return _client.AddReactionAsync( |
| 50 | activity.Conversation.Id, |
| 51 | activityId, |
| 52 | reactionType, |
| 53 | activity.ServiceUrl, |
| 54 | activity.Recipient?.GetAgenticIdentity(), |
| 55 | customHeaders, |
| 56 | cancellationToken); |
| 57 | } |
| 58 | |
| 59 | /// <summary> |
| 60 | /// Removes a reaction from an activity using activity context. |
| 61 | /// </summary> |
| 62 | /// <param name="activity">The activity to remove the reaction from. Must contain valid Id, Conversation.Id, and ServiceUrl.</param> |
| 63 | /// <param name="activityId">The ID of the activity to remove the reaction from. This is separate from activity.Id to allow removing a reaction from a different activity than the one in context if needed.</param> |
| 64 | /// <param name="reactionType">The type of reaction to remove (e.g., "like", "heart", "laugh").</param> |
| 65 | /// <param name="customHeaders">Optional custom headers to include in the request.</param> |
| 66 | /// <param name="cancellationToken">A cancellation token that can be used to cancel the operation.</param> |
| 67 | /// <returns>A task that represents the asynchronous operation.</returns> |
| 68 | public Task DeleteAsync( |
| 69 | TeamsActivity activity, |
| 70 | string activityId, |
| 71 | string reactionType, |
| 72 | CustomHeaders? customHeaders = null, |
| 73 | CancellationToken cancellationToken = default) |
| 74 | { |
| 75 | ArgumentNullException.ThrowIfNull(activity); |
| 76 | ArgumentException.ThrowIfNullOrWhiteSpace(activityId); |
| 77 | ArgumentNullException.ThrowIfNull(activity.Conversation); |
| 78 | ArgumentException.ThrowIfNullOrWhiteSpace(activity.Conversation.Id); |
| 79 | ArgumentNullException.ThrowIfNull(activity.ServiceUrl); |
| 80 | |
| 81 | return _client.DeleteReactionAsync( |
| 82 | activity.Conversation.Id, |
| 83 | activityId, |
| 84 | reactionType, |
| 85 | activity.ServiceUrl, |
| 86 | activity.Recipient?.GetAgenticIdentity(), |
| 87 | customHeaders, |
| 88 | cancellationToken); |
| 89 | } |
| 90 | } |
| 91 | |