Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Libraries/Microsoft.Teams.Api/Clients/ConversationClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,38 @@ public class ConversationClient : Client
public readonly string ServiceUrl;
public readonly ActivityClient Activities;
public readonly MemberClient Members;
public readonly ReactionClient Reactions;

public ConversationClient(string serviceUrl, CancellationToken cancellationToken = default) : base(cancellationToken)
{
ServiceUrl = serviceUrl;
Activities = new ActivityClient(serviceUrl, _http, cancellationToken);
Members = new MemberClient(serviceUrl, _http, cancellationToken);
Reactions = new ReactionClient(serviceUrl, _http, cancellationToken);
}

public ConversationClient(string serviceUrl, IHttpClient client, CancellationToken cancellationToken = default) : base(client, cancellationToken)
{
ServiceUrl = serviceUrl;
Activities = new ActivityClient(serviceUrl, _http, cancellationToken);
Members = new MemberClient(serviceUrl, _http, cancellationToken);
Reactions = new ReactionClient(serviceUrl, _http, cancellationToken);
}

public ConversationClient(string serviceUrl, IHttpClientOptions options, CancellationToken cancellationToken = default) : base(options, cancellationToken)
{
ServiceUrl = serviceUrl;
Activities = new ActivityClient(serviceUrl, _http, cancellationToken);
Members = new MemberClient(serviceUrl, _http, cancellationToken);
Reactions = new ReactionClient(serviceUrl, _http, cancellationToken);
}

public ConversationClient(string serviceUrl, IHttpClientFactory factory, CancellationToken cancellationToken = default) : base(factory, cancellationToken)
{
ServiceUrl = serviceUrl;
Activities = new ActivityClient(serviceUrl, _http, cancellationToken);
Members = new MemberClient(serviceUrl, _http, cancellationToken);
Reactions = new ReactionClient(serviceUrl, _http, cancellationToken);
}

public async Task<ConversationResource> CreateAsync(CreateRequest request)
Expand Down
93 changes: 93 additions & 0 deletions Libraries/Microsoft.Teams.Api/Clients/ReactionClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using Microsoft.Teams.Api.Messages;
using Microsoft.Teams.Common.Http;

namespace Microsoft.Teams.Api.Clients;

/// <summary>
/// Client for working with app message reactions for a given conversation/activity.
/// </summary>
public class ReactionClient : Client
{
public readonly string ServiceUrl;

public ReactionClient(string serviceUrl, CancellationToken cancellationToken = default)
: base(cancellationToken)
{
ServiceUrl = serviceUrl;
}

public ReactionClient(string serviceUrl, IHttpClient client, CancellationToken cancellationToken = default)
: base(client, cancellationToken)
{
ServiceUrl = serviceUrl;
}

public ReactionClient(string serviceUrl, IHttpClientOptions options, CancellationToken cancellationToken = default)
: base(options, cancellationToken)
{
ServiceUrl = serviceUrl;
}

public ReactionClient(string serviceUrl, IHttpClientFactory factory, CancellationToken cancellationToken = default)
: base(factory, cancellationToken)
{
ServiceUrl = serviceUrl;
}

/// <summary>
/// Creates or updates a reaction on an activity in a conversation.
/// </summary>
/// <param name="conversationId">The conversation id.</param>
/// <param name="activityId">The id of the activity to react to.</param>
/// <param name="reactionType">
/// The reaction type (for example: "like", "heart", "laugh", etc.).
/// </param>
/// <param name="userId">
/// Optional id of the user on whose behalf the reaction is added/updated (if supported by the service).
/// </param>
/// <returns>
/// A <see cref="Resource"/> describing the reaction, or <c>null</c> if the service returned an empty body.
/// </returns>
public async Task CreateOrUpdateAsync(
string conversationId,
string activityId,
ReactionType reactionType
)
{
// Assumed route:
// PUT v3/conversations/{conversationId}/activities/{activityId}/reactions
var url = $"{ServiceUrl}v3/conversations/{conversationId}/activities/{activityId}/reactions/{reactionType}";
var req = HttpRequest.Put(url);
await _http.SendAsync(req, _cancellationToken);
}

/// <summary>
/// Removes a reaction from an activity in a conversation.
/// </summary>
/// <param name="conversationId">The conversation id.</param>
/// <param name="activityId">The id of the activity the reaction is on.</param>
/// <param name="reactionType">
/// The reaction type to remove (for example: "like", "heart", "laugh", etc.).
/// </param>
/// <param name="userId">
/// Optional id of the user whose reaction should be removed (if supported by the service).
/// </param>
public async Task DeleteAsync(
string conversationId,
string activityId,
ReactionType reactionType
)
{
// Assumed route:
// DELETE v3/conversations/{conversationId}/activities/{activityId}/reactions/{reactionType}
var url =
$"{ServiceUrl}v3/conversations/{conversationId}/activities/{activityId}/reactions/{reactionType}";

var req = HttpRequest.Delete(url);

await _http.SendAsync(req, _cancellationToken);
}
}
47 changes: 45 additions & 2 deletions Libraries/Microsoft.Teams.Api/Messages/Reaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,73 @@ namespace Microsoft.Teams.Api.Messages;

/// <summary>
/// The type of reaction given to the
/// message. Possible values include: 'like', 'heart', 'laugh', 'surprised',
/// 'sad', 'angry', 'plusOne'
/// </summary>
[JsonConverter(typeof(JsonConverter<ReactionType>))]
public class ReactionType(string value) : StringEnum(value)
{
/// <summary>
/// 👍
/// </summary>
public static readonly ReactionType Like = new("like");
public bool IsLike => Like.Equals(Value);

/// <summary>
/// ❤️
/// </summary>
public static readonly ReactionType Heart = new("heart");
public bool IsHeart => Heart.Equals(Value);

/// <summary>
/// ✅
/// </summary>
public static readonly ReactionType Checkmark = new("checkmark");
public bool IsCheckmark => Checkmark.Equals(Value);

/// <summary>
/// ⏳
/// </summary>
public static readonly ReactionType Hourglass = new("hourglass");
public bool IsHourglass => Hourglass.Equals(Value);

/// <summary>
/// 📌
/// </summary>
public static readonly ReactionType Pushpin = new("pushpin");
public bool IsPushpin => Pushpin.Equals(Value);

/// <summary>
/// ❗
/// </summary>
public static readonly ReactionType Exclamation = new("exclamation");
public bool IsExclamation => Exclamation.Equals(Value);

/// <summary>
/// 😆
/// </summary>
public static readonly ReactionType Laugh = new("laugh");
public bool IsLaugh => Laugh.Equals(Value);

/// <summary>
/// 😮
/// </summary>
public static readonly ReactionType Surprise = new("surprise");
public bool IsSurprise => Surprise.Equals(Value);

/// <summary>
/// 🙁
/// </summary>
public static readonly ReactionType Sad = new("sad");
public bool IsSad => Sad.Equals(Value);

/// <summary>
/// 😠
/// </summary>
public static readonly ReactionType Angry = new("angry");
public bool IsAngry => Angry.Equals(Value);

/// <summary>
/// plus-one
/// </summary>
public static readonly ReactionType PlusOne = new("plusOne");
public bool IsPlusOne => PlusOne.Equals(Value);
}
Expand Down