Skip to content
Open
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
9 changes: 9 additions & 0 deletions Libraries/Microsoft.Teams.Api/Activities/Activity.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.Diagnostics.CodeAnalysis;
using System.Text.Json;
using System.Text.Json.Serialization;

Expand Down Expand Up @@ -146,6 +147,7 @@ public partial class Activity : IActivity
public ChannelData? ChannelData { get; set; }

[JsonIgnore]
[Experimental("TEAMS0002")]
public bool IsTargeted { get; set; }

[JsonExtensionData]
Expand Down Expand Up @@ -226,13 +228,18 @@ public virtual Activity WithRelatesTo(ConversationReference value)

public virtual Activity WithRecipient(Account value)
{
#pragma warning disable TEAMS0002
return WithRecipient(value, false);
#pragma warning restore TEAMS0002
}

[Experimental("TEAMS0002")]
public virtual Activity WithRecipient(Account value, bool isTargeted)
{
Recipient = value;
#pragma warning disable TEAMS0002
IsTargeted = isTargeted;
#pragma warning restore TEAMS0002
return this;
}

Expand Down Expand Up @@ -423,10 +430,12 @@ public Activity Merge(Activity from)
LocalTimestamp ??= from.LocalTimestamp;
AddEntity(from.Entities?.ToArray() ?? []);

#pragma warning disable TEAMS0002
if (from.IsTargeted)
{
IsTargeted = true;
}
#pragma warning restore TEAMS0002

if (from.ChannelData is not null)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.Diagnostics.CodeAnalysis;
using System.Text.Json.Serialization;

using Microsoft.Teams.Api.Entities;
Expand Down Expand Up @@ -63,7 +64,7 @@ public class MessageActivity : Activity
[JsonPropertyName("value")]
[JsonPropertyOrder(43)]
public object? Value { get; set; }

[JsonIgnore]
public bool IsRecipientMentioned
{
Expand Down Expand Up @@ -151,10 +152,13 @@ public override MessageActivity WithRecipient(Account value)
return (MessageActivity)base.WithRecipient(value);
}

[Experimental("TEAMS0002")]
#pragma warning disable TEAMS0002
public override MessageActivity WithRecipient(Account value, bool isTargeted = false)
{
return (MessageActivity)base.WithRecipient(value, isTargeted);
}
#pragma warning restore TEAMS0002

public MessageActivity AddAttachment(params Attachment[] value)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

#pragma warning disable TEAMS0001

using System.Text.Json.Serialization;

using Microsoft.Teams.Common;
Expand Down Expand Up @@ -80,4 +82,5 @@ public MessageReactionActivity RemoveReaction(Messages.ReactionType type)
ReactionsRemoved.Add(new() { Type = type });
return this;
}
}
}
#pragma warning restore TEAMS0001
4 changes: 4 additions & 0 deletions Libraries/Microsoft.Teams.Api/Clients/ActivityClient.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.Diagnostics.CodeAnalysis;
using System.Text.Json;

using Microsoft.Teams.Api.Activities;
Expand Down Expand Up @@ -94,6 +95,7 @@ public async Task DeleteAsync(string conversationId, string id)
/// <param name="conversationId">The ID of the conversation</param>
/// <param name="activity">The activity to create</param>
/// <returns>The created activity resource</returns>
[Experimental("TEAMS0002")]
public async Task<Resource?> CreateTargetedAsync(string conversationId, IActivity activity)
{
var req = HttpRequest.Post(
Expand All @@ -116,6 +118,7 @@ public async Task DeleteAsync(string conversationId, string id)
/// <param name="id">The ID of the activity to update</param>
/// <param name="activity">The updated activity data</param>
/// <returns>The updated activity resource</returns>
[Experimental("TEAMS0002")]
public async Task<Resource?> UpdateTargetedAsync(string conversationId, string id, IActivity activity)
{
var req = HttpRequest.Put(
Expand All @@ -136,6 +139,7 @@ public async Task DeleteAsync(string conversationId, string id)
/// </summary>
/// <param name="conversationId">The ID of the conversation</param>
/// <param name="id">The ID of the activity to delete</param>
[Experimental("TEAMS0002")]
public async Task DeleteTargetedAsync(string conversationId, string id)
{
var req = HttpRequest.Delete(
Expand Down
10 changes: 10 additions & 0 deletions Libraries/Microsoft.Teams.Api/Clients/ConversationClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,48 @@ public class ConversationClient : Client
public readonly string ServiceUrl;
public readonly ActivityClient Activities;
public readonly MemberClient Members;
#pragma warning disable TEAMS0001
public readonly ReactionClient Reactions;
#pragma warning restore TEAMS0001

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

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);
#pragma warning disable TEAMS0001
Reactions = new ReactionClient(serviceUrl, _http, cancellationToken);
#pragma warning restore TEAMS0001
}

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);
#pragma warning disable TEAMS0001
Reactions = new ReactionClient(serviceUrl, _http, cancellationToken);
#pragma warning restore TEAMS0001
}

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);
#pragma warning disable TEAMS0001
Reactions = new ReactionClient(serviceUrl, _http, cancellationToken);
#pragma warning restore TEAMS0001
}

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

using System.Diagnostics.CodeAnalysis;

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

Expand All @@ -9,6 +11,7 @@ namespace Microsoft.Teams.Api.Clients;
/// <summary>
/// Client for working with app message reactions for a given conversation/activity.
/// </summary>
[Experimental("TEAMS0001")]
public class ReactionClient : Client
{
public readonly string ServiceUrl;
Expand Down Expand Up @@ -91,4 +94,4 @@ public async Task DeleteAsync(

await _http.SendAsync(req, cancellationToken != default ? cancellationToken : _cancellationToken);
}
}
}
2 changes: 2 additions & 0 deletions Libraries/Microsoft.Teams.Api/Messages/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,7 @@ public class Message
/// </summary>
[JsonPropertyName("reactions")]
[JsonPropertyOrder(16)]
#pragma warning disable TEAMS0001
public IList<Reaction>? Reactions { get; set; }
#pragma warning restore TEAMS0001
}
3 changes: 3 additions & 0 deletions Libraries/Microsoft.Teams.Api/Messages/Reaction.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.Diagnostics.CodeAnalysis;
using System.Text.Json.Serialization;

using Microsoft.Teams.Common;
Expand All @@ -10,6 +11,7 @@ namespace Microsoft.Teams.Api.Messages;
/// <summary>
/// The type of reaction given to the message.
/// </summary>
[Experimental("TEAMS0001")]
[JsonConverter(typeof(JsonConverter<ReactionType>))]
public class ReactionType(string value) : StringEnum(value)
{
Expand Down Expand Up @@ -53,6 +55,7 @@ public class ReactionType(string value) : StringEnum(value)
/// <summary>
/// Message Reaction
/// </summary>
[Experimental("TEAMS0001")]
public class Reaction
{
/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions Libraries/Microsoft.Teams.Apps/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,12 @@ public async Task<T> Send<T>(string conversationId, T activity, ConversationType
}

// Validate targeted messages in proactive context
#pragma warning disable TEAMS0002
if (activity is MessageActivity messageActivity && messageActivity.IsTargeted == true && messageActivity.Recipient is null)
{
throw new InvalidOperationException("Targeted messages sent proactively must specify an explicit recipient ID. Use WithRecipient(new Account { Id = recipientId }, true) with an explicit recipient.");
}
#pragma warning restore TEAMS0002

var reference = new ConversationReference()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public async Task<TActivity> Send<TActivity>(TActivity activity, Api.Conversatio

// For targeted messages with an explicit Recipient (proactive sends), preserve it.
// Otherwise, use the reference User from the conversation context.
#pragma warning disable TEAMS0002
var isTargetedWithRecipient = activity is MessageActivity msg && msg.IsTargeted == true && msg.Recipient is not null;
if (!isTargetedWithRecipient)
{
Expand Down Expand Up @@ -125,6 +126,7 @@ await client
var res = isTargeted
? await client.Conversations.Activities.CreateTargetedAsync(reference.Conversation.Id, activity)
: await client.Conversations.Activities.CreateAsync(reference.Conversation.Id, activity);
#pragma warning restore TEAMS0002

activity.Id = res?.Id;
return activity;
Expand Down
1 change: 1 addition & 0 deletions Samples/Samples.Reactions/Samples.Reactions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<NoWarn>$(NoWarn);TEAMS0001</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<NoWarn>$(NoWarn);TEAMS0002</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<LangVersion>latest</LangVersion>
<NoWarn>$(NoWarn);TEAMS0001;TEAMS0002</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<NoWarn>$(NoWarn);CS0618</NoWarn>
<NoWarn>$(NoWarn);CS0618;TEAMS0001;TEAMS0002</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand Down