diff --git a/sdk/communication/Azure.Communication.Chat/README.md b/sdk/communication/Azure.Communication.Chat/README.md index 8c26473eaa36..4668c142182d 100644 --- a/sdk/communication/Azure.Communication.Chat/README.md +++ b/sdk/communication/Azure.Communication.Chat/README.md @@ -87,7 +87,6 @@ Once you initialized a `ChatThreadClient` class, you can do the following chat o ```C# Snippet:Azure_Communication_Chat_Tests_Samples_UpdateThread_KeyConcepts chatThreadClient.UpdateTopic(topic: "Launch meeting"); ``` - ### Send a message ```C# Snippet:Azure_Communication_Chat_Tests_Samples_SendMessage_KeyConcepts SendChatMessageResult sendChatMessageResult = chatThreadClient.SendMessage("Let's meet at 11am"); @@ -215,9 +214,7 @@ await chatClient.DeleteChatThreadAsync(threadId); ### Update a thread -Use `UpdateTopic` to update the chat thread topic. -- `topic` is used to describe the updated topic for the thread. - +Use `UpdatePropertiesAsync` to update the chat thread topic or metadata. ```C# Snippet:Azure_Communication_Chat_Tests_Samples_UpdateThread await chatThreadClient.UpdateTopicAsync(topic: "new topic !"); ``` @@ -376,12 +373,12 @@ This project has adopted the [Microsoft Open Source Code of Conduct][coc]. For m [coc_contact]: mailto:opencode@microsoft.com [nuget]: https://www.nuget.org/ [netstandars2mappings]:https://github.com/dotnet/standard/blob/master/docs/versions.md -[useraccesstokens]:https://learn.microsoft.com/azure/communication-services/quickstarts/access-tokens?pivots=programming-language-csharp -[communication_resource_docs]: https://learn.microsoft.com/azure/communication-services/quickstarts/create-communication-resource?tabs=windows&pivots=platform-azp -[communication_resource_create_portal]: https://learn.microsoft.com/azure/communication-services/quickstarts/create-communication-resource?tabs=windows&pivots=platform-azp -[communication_resource_create_power_shell]: https://learn.microsoft.com/powershell/module/az.communication/new-azcommunicationservice -[communication_resource_create_net]: https://learn.microsoft.com/azure/communication-services/quickstarts/create-communication-resource?tabs=windows&pivots=platform-net -[nextsteps]:https://learn.microsoft.com/azure/communication-services/quickstarts/chat/get-started?pivots=programming-language-csharp +[useraccesstokens]:https://docs.microsoft.com/azure/communication-services/quickstarts/access-tokens?pivots=programming-language-csharp +[communication_resource_docs]: https://docs.microsoft.com/azure/communication-services/quickstarts/create-communication-resource?tabs=windows&pivots=platform-azp +[communication_resource_create_portal]: https://docs.microsoft.com/azure/communication-services/quickstarts/create-communication-resource?tabs=windows&pivots=platform-azp +[communication_resource_create_power_shell]: https://docs.microsoft.com/powershell/module/az.communication/new-azcommunicationservice +[communication_resource_create_net]: https://docs.microsoft.com/azure/communication-services/quickstarts/create-communication-resource?tabs=windows&pivots=platform-net +[nextsteps]:https://docs.microsoft.com/azure/communication-services/quickstarts/chat/get-started?pivots=programming-language-csharp [source]: https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/communication/Azure.Communication.Chat/src -[product_docs]: https://learn.microsoft.com/azure/communication-services/overview +[product_docs]: https://docs.microsoft.com/azure/communication-services/overview [package]: https://www.nuget.org/packages/Azure.Communication.Chat diff --git a/sdk/communication/Azure.Communication.Chat/api/Azure.Communication.Chat.net8.0.cs b/sdk/communication/Azure.Communication.Chat/api/Azure.Communication.Chat.net8.0.cs index 500a0abce04b..95e26f8ca157 100644 --- a/sdk/communication/Azure.Communication.Chat/api/Azure.Communication.Chat.net8.0.cs +++ b/sdk/communication/Azure.Communication.Chat/api/Azure.Communication.Chat.net8.0.cs @@ -42,7 +42,9 @@ public partial class ChatClient { protected ChatClient() { } public ChatClient(System.Uri endpoint, Azure.Communication.CommunicationTokenCredential communicationTokenCredential, Azure.Communication.Chat.ChatClientOptions options = null) { } + public virtual Azure.Response CreateChatThread(Azure.Communication.Chat.CreateChatThreadOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response CreateChatThread(string topic, System.Collections.Generic.IEnumerable participants, string idempotencyToken = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> CreateChatThreadAsync(Azure.Communication.Chat.CreateChatThreadOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task> CreateChatThreadAsync(string topic, System.Collections.Generic.IEnumerable participants = null, string idempotencyToken = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response DeleteChatThread(string threadId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task DeleteChatThreadAsync(string threadId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } @@ -52,13 +54,14 @@ public ChatClient(System.Uri endpoint, Azure.Communication.CommunicationTokenCre } public partial class ChatClientOptions : Azure.Core.ClientOptions { - public ChatClientOptions(Azure.Communication.Chat.ChatClientOptions.ServiceVersion version = Azure.Communication.Chat.ChatClientOptions.ServiceVersion.V2024_03_07) { } + public ChatClientOptions(Azure.Communication.Chat.ChatClientOptions.ServiceVersion version = Azure.Communication.Chat.ChatClientOptions.ServiceVersion.V2025_03_15) { } public enum ServiceVersion { V2021_03_07 = 1, V2021_09_07 = 2, V2023_11_07 = 3, V2024_03_07 = 4, + V2025_03_15 = 5, } } public partial class ChatError @@ -136,9 +139,11 @@ public static partial class ChatModelFactory [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public static Azure.Communication.Chat.ChatMessageReadReceipt ChatMessageReadReceipt(Azure.Communication.CommunicationIdentifier sender, string chatMessageId, System.DateTimeOffset readOn) { throw null; } public static Azure.Communication.Chat.ChatParticipant ChatParticipant(Azure.Communication.CommunicationIdentifier user, string displayName, System.DateTimeOffset? shareHistoryTime) { throw null; } + public static Azure.Communication.Chat.ChatParticipant ChatParticipant(Azure.Communication.CommunicationIdentifier user, string displayName, System.DateTimeOffset? shareHistoryTime, System.Collections.Generic.IDictionary metadata) { throw null; } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public static Azure.Communication.Chat.ChatThreadItem ChatThreadItem(string id, string topic, System.DateTimeOffset? deletedOn, System.DateTimeOffset? lastMessageReceivedOn) { throw null; } public static Azure.Communication.Chat.ChatThreadProperties ChatThreadProperties(string id, string topic, System.DateTimeOffset createdOn, Azure.Communication.CommunicationIdentifier createdBy, System.DateTimeOffset deletedOn) { throw null; } + public static Azure.Communication.Chat.ChatThreadProperties ChatThreadProperties(string id, string topic, System.DateTimeOffset createdOn, Azure.Communication.CommunicationIdentifier createdBy, System.DateTimeOffset deletedOn, System.Collections.Generic.IDictionary metadata) { throw null; } public static Azure.Communication.Chat.CreateChatThreadResult CreateChatThreadResult(Azure.Communication.Chat.ChatThreadProperties chatThread, System.Collections.Generic.IEnumerable invalidParticipants) { throw null; } public static Azure.Communication.Chat.SendChatMessageResult SendChatMessageResult(string id) { throw null; } } @@ -146,9 +151,14 @@ public partial class ChatParticipant { public ChatParticipant(Azure.Communication.CommunicationIdentifier identifier) { } public string DisplayName { get { throw null; } set { } } + public System.Collections.Generic.IDictionary Metadata { get { throw null; } } public System.DateTimeOffset? ShareHistoryTime { get { throw null; } set { } } public Azure.Communication.CommunicationIdentifier User { get { throw null; } set { } } } + public abstract partial class ChatRetentionPolicy + { + protected ChatRetentionPolicy() { } + } public partial class ChatThreadClient { protected ChatThreadClient() { } @@ -186,6 +196,8 @@ public ChatThreadClient(string threadId, System.Uri endpoint, Azure.Communicatio public virtual Azure.Response UpdateMessage(string messageId, string content, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task UpdateMessageAsync(Azure.Communication.Chat.UpdateChatMessageOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task UpdateMessageAsync(string messageId, string content, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response UpdateProperties(Azure.Communication.Chat.UpdateChatThreadPropertiesOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task UpdatePropertiesAsync(Azure.Communication.Chat.UpdateChatThreadPropertiesOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response UpdateTopic(string topic, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task UpdateTopicAsync(string topic, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } } @@ -204,6 +216,17 @@ internal ChatThreadProperties() { } public System.DateTimeOffset CreatedOn { get { throw null; } } public System.DateTimeOffset? DeletedOn { get { throw null; } } public string Id { get { throw null; } } + public System.Collections.Generic.IReadOnlyDictionary Metadata { get { throw null; } } + public Azure.Communication.Chat.ChatRetentionPolicy RetentionPolicy { get { throw null; } } + public string Topic { get { throw null; } } + } + public partial class CreateChatThreadOptions + { + public CreateChatThreadOptions(string topic) { } + public string IdempotencyToken { get { throw null; } set { } } + public System.Collections.Generic.IDictionary Metadata { get { throw null; } } + public System.Collections.Generic.IList Participants { get { throw null; } } + public Azure.Communication.Chat.ChatRetentionPolicy RetentionPolicy { get { throw null; } set { } } public string Topic { get { throw null; } } } public partial class CreateChatThreadResult @@ -212,6 +235,28 @@ internal CreateChatThreadResult() { } public Azure.Communication.Chat.ChatThreadProperties ChatThread { get { throw null; } } public System.Collections.Generic.IReadOnlyList InvalidParticipants { get { throw null; } } } + public partial class NoneRetentionPolicy : Azure.Communication.Chat.ChatRetentionPolicy + { + public NoneRetentionPolicy() { } + } + [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] + public readonly partial struct RetentionPolicyKind : System.IEquatable + { + private readonly object _dummy; + private readonly int _dummyPrimitive; + public RetentionPolicyKind(string value) { throw null; } + public static Azure.Communication.Chat.RetentionPolicyKind None { get { throw null; } } + public static Azure.Communication.Chat.RetentionPolicyKind ThreadCreationDate { get { throw null; } } + public bool Equals(Azure.Communication.Chat.RetentionPolicyKind other) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public override bool Equals(object obj) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public override int GetHashCode() { throw null; } + public static bool operator ==(Azure.Communication.Chat.RetentionPolicyKind left, Azure.Communication.Chat.RetentionPolicyKind right) { throw null; } + public static implicit operator Azure.Communication.Chat.RetentionPolicyKind (string value) { throw null; } + public static bool operator !=(Azure.Communication.Chat.RetentionPolicyKind left, Azure.Communication.Chat.RetentionPolicyKind right) { throw null; } + public override string ToString() { throw null; } + } public partial class SendChatMessageOptions { public SendChatMessageOptions() { } @@ -225,6 +270,11 @@ public partial class SendChatMessageResult internal SendChatMessageResult() { } public string Id { get { throw null; } } } + public partial class ThreadCreationDateRetentionPolicy : Azure.Communication.Chat.ChatRetentionPolicy + { + public ThreadCreationDateRetentionPolicy(int deleteThreadAfterDays) { } + public int DeleteThreadAfterDays { get { throw null; } set { } } + } public partial class TypingNotificationOptions { public TypingNotificationOptions() { } @@ -237,4 +287,11 @@ public UpdateChatMessageOptions() { } public string MessageId { get { throw null; } set { } } public System.Collections.Generic.IDictionary Metadata { get { throw null; } } } + public partial class UpdateChatThreadPropertiesOptions + { + public UpdateChatThreadPropertiesOptions() { } + public System.Collections.Generic.IDictionary Metadata { get { throw null; } } + public Azure.Communication.Chat.ChatRetentionPolicy RetentionPolicy { get { throw null; } set { } } + public string Topic { get { throw null; } set { } } + } } diff --git a/sdk/communication/Azure.Communication.Chat/api/Azure.Communication.Chat.netstandard2.0.cs b/sdk/communication/Azure.Communication.Chat/api/Azure.Communication.Chat.netstandard2.0.cs index 500a0abce04b..95e26f8ca157 100644 --- a/sdk/communication/Azure.Communication.Chat/api/Azure.Communication.Chat.netstandard2.0.cs +++ b/sdk/communication/Azure.Communication.Chat/api/Azure.Communication.Chat.netstandard2.0.cs @@ -42,7 +42,9 @@ public partial class ChatClient { protected ChatClient() { } public ChatClient(System.Uri endpoint, Azure.Communication.CommunicationTokenCredential communicationTokenCredential, Azure.Communication.Chat.ChatClientOptions options = null) { } + public virtual Azure.Response CreateChatThread(Azure.Communication.Chat.CreateChatThreadOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response CreateChatThread(string topic, System.Collections.Generic.IEnumerable participants, string idempotencyToken = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> CreateChatThreadAsync(Azure.Communication.Chat.CreateChatThreadOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task> CreateChatThreadAsync(string topic, System.Collections.Generic.IEnumerable participants = null, string idempotencyToken = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response DeleteChatThread(string threadId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task DeleteChatThreadAsync(string threadId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } @@ -52,13 +54,14 @@ public ChatClient(System.Uri endpoint, Azure.Communication.CommunicationTokenCre } public partial class ChatClientOptions : Azure.Core.ClientOptions { - public ChatClientOptions(Azure.Communication.Chat.ChatClientOptions.ServiceVersion version = Azure.Communication.Chat.ChatClientOptions.ServiceVersion.V2024_03_07) { } + public ChatClientOptions(Azure.Communication.Chat.ChatClientOptions.ServiceVersion version = Azure.Communication.Chat.ChatClientOptions.ServiceVersion.V2025_03_15) { } public enum ServiceVersion { V2021_03_07 = 1, V2021_09_07 = 2, V2023_11_07 = 3, V2024_03_07 = 4, + V2025_03_15 = 5, } } public partial class ChatError @@ -136,9 +139,11 @@ public static partial class ChatModelFactory [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public static Azure.Communication.Chat.ChatMessageReadReceipt ChatMessageReadReceipt(Azure.Communication.CommunicationIdentifier sender, string chatMessageId, System.DateTimeOffset readOn) { throw null; } public static Azure.Communication.Chat.ChatParticipant ChatParticipant(Azure.Communication.CommunicationIdentifier user, string displayName, System.DateTimeOffset? shareHistoryTime) { throw null; } + public static Azure.Communication.Chat.ChatParticipant ChatParticipant(Azure.Communication.CommunicationIdentifier user, string displayName, System.DateTimeOffset? shareHistoryTime, System.Collections.Generic.IDictionary metadata) { throw null; } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public static Azure.Communication.Chat.ChatThreadItem ChatThreadItem(string id, string topic, System.DateTimeOffset? deletedOn, System.DateTimeOffset? lastMessageReceivedOn) { throw null; } public static Azure.Communication.Chat.ChatThreadProperties ChatThreadProperties(string id, string topic, System.DateTimeOffset createdOn, Azure.Communication.CommunicationIdentifier createdBy, System.DateTimeOffset deletedOn) { throw null; } + public static Azure.Communication.Chat.ChatThreadProperties ChatThreadProperties(string id, string topic, System.DateTimeOffset createdOn, Azure.Communication.CommunicationIdentifier createdBy, System.DateTimeOffset deletedOn, System.Collections.Generic.IDictionary metadata) { throw null; } public static Azure.Communication.Chat.CreateChatThreadResult CreateChatThreadResult(Azure.Communication.Chat.ChatThreadProperties chatThread, System.Collections.Generic.IEnumerable invalidParticipants) { throw null; } public static Azure.Communication.Chat.SendChatMessageResult SendChatMessageResult(string id) { throw null; } } @@ -146,9 +151,14 @@ public partial class ChatParticipant { public ChatParticipant(Azure.Communication.CommunicationIdentifier identifier) { } public string DisplayName { get { throw null; } set { } } + public System.Collections.Generic.IDictionary Metadata { get { throw null; } } public System.DateTimeOffset? ShareHistoryTime { get { throw null; } set { } } public Azure.Communication.CommunicationIdentifier User { get { throw null; } set { } } } + public abstract partial class ChatRetentionPolicy + { + protected ChatRetentionPolicy() { } + } public partial class ChatThreadClient { protected ChatThreadClient() { } @@ -186,6 +196,8 @@ public ChatThreadClient(string threadId, System.Uri endpoint, Azure.Communicatio public virtual Azure.Response UpdateMessage(string messageId, string content, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task UpdateMessageAsync(Azure.Communication.Chat.UpdateChatMessageOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task UpdateMessageAsync(string messageId, string content, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response UpdateProperties(Azure.Communication.Chat.UpdateChatThreadPropertiesOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task UpdatePropertiesAsync(Azure.Communication.Chat.UpdateChatThreadPropertiesOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response UpdateTopic(string topic, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task UpdateTopicAsync(string topic, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } } @@ -204,6 +216,17 @@ internal ChatThreadProperties() { } public System.DateTimeOffset CreatedOn { get { throw null; } } public System.DateTimeOffset? DeletedOn { get { throw null; } } public string Id { get { throw null; } } + public System.Collections.Generic.IReadOnlyDictionary Metadata { get { throw null; } } + public Azure.Communication.Chat.ChatRetentionPolicy RetentionPolicy { get { throw null; } } + public string Topic { get { throw null; } } + } + public partial class CreateChatThreadOptions + { + public CreateChatThreadOptions(string topic) { } + public string IdempotencyToken { get { throw null; } set { } } + public System.Collections.Generic.IDictionary Metadata { get { throw null; } } + public System.Collections.Generic.IList Participants { get { throw null; } } + public Azure.Communication.Chat.ChatRetentionPolicy RetentionPolicy { get { throw null; } set { } } public string Topic { get { throw null; } } } public partial class CreateChatThreadResult @@ -212,6 +235,28 @@ internal CreateChatThreadResult() { } public Azure.Communication.Chat.ChatThreadProperties ChatThread { get { throw null; } } public System.Collections.Generic.IReadOnlyList InvalidParticipants { get { throw null; } } } + public partial class NoneRetentionPolicy : Azure.Communication.Chat.ChatRetentionPolicy + { + public NoneRetentionPolicy() { } + } + [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] + public readonly partial struct RetentionPolicyKind : System.IEquatable + { + private readonly object _dummy; + private readonly int _dummyPrimitive; + public RetentionPolicyKind(string value) { throw null; } + public static Azure.Communication.Chat.RetentionPolicyKind None { get { throw null; } } + public static Azure.Communication.Chat.RetentionPolicyKind ThreadCreationDate { get { throw null; } } + public bool Equals(Azure.Communication.Chat.RetentionPolicyKind other) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public override bool Equals(object obj) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public override int GetHashCode() { throw null; } + public static bool operator ==(Azure.Communication.Chat.RetentionPolicyKind left, Azure.Communication.Chat.RetentionPolicyKind right) { throw null; } + public static implicit operator Azure.Communication.Chat.RetentionPolicyKind (string value) { throw null; } + public static bool operator !=(Azure.Communication.Chat.RetentionPolicyKind left, Azure.Communication.Chat.RetentionPolicyKind right) { throw null; } + public override string ToString() { throw null; } + } public partial class SendChatMessageOptions { public SendChatMessageOptions() { } @@ -225,6 +270,11 @@ public partial class SendChatMessageResult internal SendChatMessageResult() { } public string Id { get { throw null; } } } + public partial class ThreadCreationDateRetentionPolicy : Azure.Communication.Chat.ChatRetentionPolicy + { + public ThreadCreationDateRetentionPolicy(int deleteThreadAfterDays) { } + public int DeleteThreadAfterDays { get { throw null; } set { } } + } public partial class TypingNotificationOptions { public TypingNotificationOptions() { } @@ -237,4 +287,11 @@ public UpdateChatMessageOptions() { } public string MessageId { get { throw null; } set { } } public System.Collections.Generic.IDictionary Metadata { get { throw null; } } } + public partial class UpdateChatThreadPropertiesOptions + { + public UpdateChatThreadPropertiesOptions() { } + public System.Collections.Generic.IDictionary Metadata { get { throw null; } } + public Azure.Communication.Chat.ChatRetentionPolicy RetentionPolicy { get { throw null; } set { } } + public string Topic { get { throw null; } set { } } + } } diff --git a/sdk/communication/Azure.Communication.Chat/assets.json b/sdk/communication/Azure.Communication.Chat/assets.json index 4cca83b8b70f..addd31fdf8b0 100644 --- a/sdk/communication/Azure.Communication.Chat/assets.json +++ b/sdk/communication/Azure.Communication.Chat/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "net", "TagPrefix": "net/communication/Azure.Communication.Chat", - "Tag": "net/communication/Azure.Communication.Chat_882b0672f3" + "Tag": "net/communication/Azure.Communication.Chat_6c14b0d3f3" } diff --git a/sdk/communication/Azure.Communication.Chat/src/ChatClient.cs b/sdk/communication/Azure.Communication.Chat/src/ChatClient.cs index 2f1b28ed7c0c..ffc1d9564907 100644 --- a/sdk/communication/Azure.Communication.Chat/src/ChatClient.cs +++ b/sdk/communication/Azure.Communication.Chat/src/ChatClient.cs @@ -62,7 +62,57 @@ public virtual async Task> CreateChatThreadAsyn scope.Start(); try { - Response createChatThreadResultInternal = await _chatRestClient.CreateChatThreadAsync(topic, idempotencyToken, participants.Select(x => x.ToChatParticipantInternal()), cancellationToken).ConfigureAwait(false); + var createChatThreadOptions = new CreateChatThreadOptions(topic) + { + IdempotencyToken = idempotencyToken, + }; + + foreach (var value in participants.ToList()) + { + createChatThreadOptions.Participants.Add(value); + } + + Response createChatThreadResultInternal = await _chatRestClient.CreateChatThreadAsync(createChatThreadOptions, cancellationToken).ConfigureAwait(false); + return Response.FromValue(new CreateChatThreadResult(createChatThreadResultInternal.Value), createChatThreadResultInternal.GetRawResponse()); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// Creates a ChatThreadClient asynchronously. . + /// CreateChatThreadOptions + /// The cancellation token for the task. + /// The server returned an error. See for details returned from the server. + public virtual async Task> CreateChatThreadAsync(CreateChatThreadOptions options, CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ChatClient)}.{nameof(CreateChatThread)}"); + scope.Start(); + try + { + Response createChatThreadResultInternal = await _chatRestClient.CreateChatThreadAsync(options, cancellationToken).ConfigureAwait(false); + return Response.FromValue(new CreateChatThreadResult(createChatThreadResultInternal.Value), createChatThreadResultInternal.GetRawResponse()); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// Creates a ChatThreadClient asynchronously. . + /// CreateChatThread Options + /// The cancellation token for the task. + /// The server returned an error. See for details returned from the server. + public virtual Response CreateChatThread(CreateChatThreadOptions options, CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ChatClient)}.{nameof(CreateChatThread)}"); + scope.Start(); + try + { + Response createChatThreadResultInternal = _chatRestClient.CreateChatThread(options, cancellationToken); return Response.FromValue(new CreateChatThreadResult(createChatThreadResultInternal.Value), createChatThreadResultInternal.GetRawResponse()); } catch (Exception ex) @@ -84,7 +134,17 @@ public virtual Response CreateChatThread(string topic, I scope.Start(); try { - Response createChatThreadResultInternal = _chatRestClient.CreateChatThread(topic, idempotencyToken,participants.Select(x => x.ToChatParticipantInternal()), cancellationToken); + var createChatThreadOptions = new CreateChatThreadOptions(topic) + { + IdempotencyToken = idempotencyToken, + }; + + foreach (var value in participants.ToList()) + { + createChatThreadOptions.Participants.Add(value); + } + + Response createChatThreadResultInternal = _chatRestClient.CreateChatThread(createChatThreadOptions); return Response.FromValue(new CreateChatThreadResult(createChatThreadResultInternal.Value), createChatThreadResultInternal.GetRawResponse()); } catch (Exception ex) @@ -193,7 +253,7 @@ Page NextPageFunc(string nextLink, int? pageSizeHint) throw; } } - return PageableHelpers.CreateEnumerable(FirstPageFunc, NextPageFunc); + return PageableHelpers.CreateEnumerable(FirstPageFunc, NextPageFunc); } /// Deletes a thread asynchronously. diff --git a/sdk/communication/Azure.Communication.Chat/src/ChatClientOptions.cs b/sdk/communication/Azure.Communication.Chat/src/ChatClientOptions.cs index 5d68c4db18e7..f44cd14d5d9b 100644 --- a/sdk/communication/Azure.Communication.Chat/src/ChatClientOptions.cs +++ b/sdk/communication/Azure.Communication.Chat/src/ChatClientOptions.cs @@ -14,7 +14,7 @@ public class ChatClientOptions : ClientOptions /// /// The latest version of the Chat service. /// - internal const ServiceVersion LatestVersion = ServiceVersion.V2024_03_07; + internal const ServiceVersion LatestVersion = ServiceVersion.V2025_03_15; internal string ApiVersion { get; } @@ -29,6 +29,7 @@ public ChatClientOptions(ServiceVersion version = LatestVersion) ServiceVersion.V2021_09_07 => "2021-09-07", ServiceVersion.V2023_11_07 => "2023-11-07", ServiceVersion.V2024_03_07 => "2024-03-07", + ServiceVersion.V2025_03_15 => "2025-03-15", _ => throw new ArgumentOutOfRangeException(nameof(version)), }; } @@ -57,7 +58,12 @@ public enum ServiceVersion /// The V2024_03_07 of the Chat service. /// #pragma warning restore CA1707 // Identifiers should not contain underscores - V2024_03_07 = 4 + V2024_03_07 = 4, + /// + /// The V2025_03_15 of the Chat service. + /// + #pragma warning restore CA1707 // Identifiers should not contain underscores + V2025_03_15 = 5 } } } diff --git a/sdk/communication/Azure.Communication.Chat/src/ChatRestClient.cs b/sdk/communication/Azure.Communication.Chat/src/ChatRestClient.cs index 68e43b5ddd24..38437e32a1ea 100644 --- a/sdk/communication/Azure.Communication.Chat/src/ChatRestClient.cs +++ b/sdk/communication/Azure.Communication.Chat/src/ChatRestClient.cs @@ -16,11 +16,11 @@ namespace Azure.Communication.Chat { // for backward compatibility, keep the previous method signature which will accept `repeatability-request-id` as a parameter [CodeGenSuppress("CreateCreateChatThreadRequest", typeof(string), typeof(IEnumerable))] - [CodeGenSuppress("CreateChatThreadAsync", typeof(string), typeof(IEnumerable), typeof(CancellationToken))] - [CodeGenSuppress("CreateChatThread", typeof(string), typeof(IEnumerable), typeof(CancellationToken))] + [CodeGenSuppress("CreateChatThreadAsync", typeof(string), typeof(IEnumerable), typeof(IDictionary), typeof(CancellationToken))] + [CodeGenSuppress("CreateChatThread", typeof(string), typeof(IEnumerable), typeof(IDictionary), typeof(CancellationToken))] internal partial class ChatRestClient { - internal HttpMessage CreateCreateChatThreadRequest(string topic, string repeatabilityRequestId, IEnumerable participants) + internal HttpMessage CreateCreateChatThreadRequest(CreateChatThreadOptions options) { var message = _pipeline.CreateMessage(); var request = message.Request; @@ -30,17 +30,31 @@ internal HttpMessage CreateCreateChatThreadRequest(string topic, string repeatab uri.AppendPath("/chat/threads", false); uri.AppendQuery("api-version", _apiVersion, true); request.Uri = uri; - request.Headers.Add("repeatability-request-id", repeatabilityRequestId ?? Guid.NewGuid().ToString()); + request.Headers.Add("repeatability-request-id", options.IdempotencyToken ?? Guid.NewGuid().ToString()); request.Headers.Add("Accept", "application/json"); request.Headers.Add("Content-Type", "application/json"); - CreateChatThreadRequest createChatThreadRequest = new CreateChatThreadRequest(topic); - if (participants != null) + CreateChatThreadRequest createChatThreadRequest = new CreateChatThreadRequest(options.Topic); + if (options.Participants != null) { - foreach (var value in participants) + foreach (var value in options.Participants) { - createChatThreadRequest.Participants.Add(value); + createChatThreadRequest.Participants.Add(value.ToChatParticipantInternal()); } } + + if (options.Metadata != null) + { + foreach (var value in options.Metadata) + { + createChatThreadRequest.Metadata.Add(value); + } + } + + if (options.RetentionPolicy != null) + { + createChatThreadRequest.RetentionPolicy = options.RetentionPolicy; + } + var model = createChatThreadRequest; var content = new Utf8JsonRequestContent(); content.JsonWriter.WriteObjectValue(model); @@ -49,19 +63,17 @@ internal HttpMessage CreateCreateChatThreadRequest(string topic, string repeatab } /// Creates a chat thread. - /// The chat thread topic. - /// If specified, the client directs that the request is repeatable; that is, that the client can make the request multiple times with the same Repeatability-Request-Id and get back an appropriate response without the server executing the request multiple times. The value of the Repeatability-Request-Id is an opaque string representing a client-generated, globally unique for all time, identifier for the request. It is recommended to use version 4 (random) UUIDs. - /// Participants to be added to the chat thread. + /// Participants to be added to the chat thread. /// The cancellation token to use. - /// is null. - public async Task> CreateChatThreadAsync(string topic, string repeatabilityRequestId = null, IEnumerable participants = null, CancellationToken cancellationToken = default) + /// is null. + public async Task> CreateChatThreadAsync(CreateChatThreadOptions options, CancellationToken cancellationToken = default) { - if (topic == null) + if (options?.Topic == null) { - throw new ArgumentNullException(nameof(topic)); + throw new ArgumentNullException(nameof(options.Topic)); } - using var message = CreateCreateChatThreadRequest(topic, repeatabilityRequestId, participants); + using var message = CreateCreateChatThreadRequest(options); await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); switch (message.Response.Status) { @@ -78,19 +90,17 @@ public async Task> CreateChatThreadAsyn } /// Creates a chat thread. - /// The chat thread topic. - /// If specified, the client directs that the request is repeatable; that is, that the client can make the request multiple times with the same Repeatability-Request-Id and get back an appropriate response without the server executing the request multiple times. The value of the Repeatability-Request-Id is an opaque string representing a client-generated, globally unique for all time, identifier for the request. It is recommended to use version 4 (random) UUIDs. - /// Participants to be added to the chat thread. + /// Participants to be added to the chat thread. /// The cancellation token to use. - /// is null. - public Response CreateChatThread(string topic, string repeatabilityRequestId = null, IEnumerable participants = null, CancellationToken cancellationToken = default) + /// is null. + public Response CreateChatThread(CreateChatThreadOptions options, CancellationToken cancellationToken = default) { - if (topic == null) + if (options.Topic == null) { - throw new ArgumentNullException(nameof(topic)); + throw new ArgumentNullException(nameof(options.Topic)); } - using var message = CreateCreateChatThreadRequest(topic, repeatabilityRequestId, participants); + using var message = CreateCreateChatThreadRequest(options); _pipeline.Send(message, cancellationToken); switch (message.Response.Status) { diff --git a/sdk/communication/Azure.Communication.Chat/src/ChatThreadClient.cs b/sdk/communication/Azure.Communication.Chat/src/ChatThreadClient.cs index 7bb1762b347a..86fed4922b25 100644 --- a/sdk/communication/Azure.Communication.Chat/src/ChatThreadClient.cs +++ b/sdk/communication/Azure.Communication.Chat/src/ChatThreadClient.cs @@ -63,7 +63,45 @@ public virtual async Task UpdateTopicAsync(string topic, CancellationT scope.Start(); try { - return await _chatThreadRestClient.UpdateChatThreadPropertiesAsync(Id, topic, cancellationToken).ConfigureAwait(false); + return await _chatThreadRestClient.UpdateChatThreadPropertiesAsync(Id, topic, null, null, cancellationToken).ConfigureAwait(false); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// Updates the thread's properties. + /// Chat thread options. + /// The cancellation token to use. + /// The server returned an error. See for details returned from the server. + public virtual Response UpdateProperties(UpdateChatThreadPropertiesOptions options, CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ChatThreadClient)}.{nameof(UpdateProperties)}"); + scope.Start(); + try + { + return _chatThreadRestClient.UpdateChatThreadProperties(Id, options.Topic, options.Metadata.ToDictionary(pair => pair.Key, pair => pair.Value), options.RetentionPolicy, cancellationToken); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// Updates the thread's properties asynchronously. + /// Chat thread options. + /// The cancellation token to use. + /// The server returned an error. See for details returned from the server. + public virtual async Task UpdatePropertiesAsync(UpdateChatThreadPropertiesOptions options, CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ChatThreadClient)}.{nameof(UpdateProperties)}"); + scope.Start(); + try + { + return await _chatThreadRestClient.UpdateChatThreadPropertiesAsync(Id, options.Topic, options.Metadata, options.RetentionPolicy, cancellationToken).ConfigureAwait(false); } catch (Exception ex) { @@ -82,7 +120,7 @@ public virtual Response UpdateTopic(string topic, CancellationToken cancellation scope.Start(); try { - return _chatThreadRestClient.UpdateChatThreadProperties(Id, topic, cancellationToken); + return _chatThreadRestClient.UpdateChatThreadProperties(Id, topic, null, null, cancellationToken); } catch (Exception ex) { diff --git a/sdk/communication/Azure.Communication.Chat/src/Generated/ChatRestClient.cs b/sdk/communication/Azure.Communication.Chat/src/Generated/ChatRestClient.cs index 50f5f2101ead..00089f22dc95 100644 --- a/sdk/communication/Azure.Communication.Chat/src/Generated/ChatRestClient.cs +++ b/sdk/communication/Azure.Communication.Chat/src/Generated/ChatRestClient.cs @@ -30,7 +30,7 @@ internal partial class ChatRestClient /// The endpoint of the Azure Communication resource. /// Api Version. /// , , or is null. - public ChatRestClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string endpoint, string apiVersion = "2024-03-07") + public ChatRestClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string endpoint, string apiVersion = "2025-03-15") { ClientDiagnostics = clientDiagnostics ?? throw new ArgumentNullException(nameof(clientDiagnostics)); _pipeline = pipeline ?? throw new ArgumentNullException(nameof(pipeline)); @@ -38,6 +38,104 @@ public ChatRestClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline _apiVersion = apiVersion ?? throw new ArgumentNullException(nameof(apiVersion)); } + internal HttpMessage CreateCreateChatThreadRequest(string topic, IEnumerable participants, IDictionary metadata, ChatRetentionPolicy retentionPolicy) + { + var message = _pipeline.CreateMessage(); + var request = message.Request; + request.Method = RequestMethod.Post; + var uri = new RawRequestUriBuilder(); + uri.AppendRaw(_endpoint, false); + uri.AppendPath("/chat/threads", false); + uri.AppendQuery("api-version", _apiVersion, true); + request.Uri = uri; + request.Headers.Add("repeatability-request-id", Guid.NewGuid()); + request.Headers.Add("Accept", "application/json"); + request.Headers.Add("Content-Type", "application/json"); + CreateChatThreadRequest createChatThreadRequest = new CreateChatThreadRequest(topic) + { + RetentionPolicy = retentionPolicy + }; + if (participants != null) + { + foreach (var value in participants) + { + createChatThreadRequest.Participants.Add(value); + } + } + if (metadata != null) + { + foreach (var value in metadata) + { + createChatThreadRequest.Metadata.Add(value); + } + } + var model = createChatThreadRequest; + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(model); + request.Content = content; + return message; + } + + /// Creates a chat thread. + /// The chat thread topic. + /// Participants to be added to the chat thread. + /// Contextual metadata for the thread. The metadata consists of name/value pairs. The total size of all metadata pairs can be up to 1KB in size. + /// Data retention policy for auto deletion. + /// The cancellation token to use. + /// is null. + public async Task> CreateChatThreadAsync(string topic, IEnumerable participants = null, IDictionary metadata = null, ChatRetentionPolicy retentionPolicy = null, CancellationToken cancellationToken = default) + { + if (topic == null) + { + throw new ArgumentNullException(nameof(topic)); + } + + using var message = CreateCreateChatThreadRequest(topic, participants, metadata, retentionPolicy); + await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); + switch (message.Response.Status) + { + case 201: + { + CreateChatThreadResultInternal value = default; + using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, ModelSerializationExtensions.JsonDocumentOptions, cancellationToken).ConfigureAwait(false); + value = CreateChatThreadResultInternal.DeserializeCreateChatThreadResultInternal(document.RootElement); + return Response.FromValue(value, message.Response); + } + default: + throw new RequestFailedException(message.Response); + } + } + + /// Creates a chat thread. + /// The chat thread topic. + /// Participants to be added to the chat thread. + /// Contextual metadata for the thread. The metadata consists of name/value pairs. The total size of all metadata pairs can be up to 1KB in size. + /// Data retention policy for auto deletion. + /// The cancellation token to use. + /// is null. + public Response CreateChatThread(string topic, IEnumerable participants = null, IDictionary metadata = null, ChatRetentionPolicy retentionPolicy = null, CancellationToken cancellationToken = default) + { + if (topic == null) + { + throw new ArgumentNullException(nameof(topic)); + } + + using var message = CreateCreateChatThreadRequest(topic, participants, metadata, retentionPolicy); + _pipeline.Send(message, cancellationToken); + switch (message.Response.Status) + { + case 201: + { + CreateChatThreadResultInternal value = default; + using var document = JsonDocument.Parse(message.Response.ContentStream, ModelSerializationExtensions.JsonDocumentOptions); + value = CreateChatThreadResultInternal.DeserializeCreateChatThreadResultInternal(document.RootElement); + return Response.FromValue(value, message.Response); + } + default: + throw new RequestFailedException(message.Response); + } + } + internal HttpMessage CreateListChatThreadsRequest(int? maxPageSize, DateTimeOffset? startTime) { var message = _pipeline.CreateMessage(); diff --git a/sdk/communication/Azure.Communication.Chat/src/Generated/ChatThreadRestClient.cs b/sdk/communication/Azure.Communication.Chat/src/Generated/ChatThreadRestClient.cs index f53917d4c7a4..adc3dfcd2793 100644 --- a/sdk/communication/Azure.Communication.Chat/src/Generated/ChatThreadRestClient.cs +++ b/sdk/communication/Azure.Communication.Chat/src/Generated/ChatThreadRestClient.cs @@ -31,7 +31,7 @@ internal partial class ChatThreadRestClient /// The endpoint of the Azure Communication resource. /// Api Version. /// , , or is null. - public ChatThreadRestClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string endpoint, string apiVersion = "2024-03-07") + public ChatThreadRestClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string endpoint, string apiVersion = "2025-03-15") { ClientDiagnostics = clientDiagnostics ?? throw new ArgumentNullException(nameof(clientDiagnostics)); _pipeline = pipeline ?? throw new ArgumentNullException(nameof(pipeline)); @@ -326,7 +326,7 @@ internal HttpMessage CreateListChatMessagesRequest(string chatThreadId, int? max /// Gets a list of messages from a thread. /// The thread id of the message. /// The maximum number of messages to be returned per page. - /// The earliest point in time to get messages up to. The timestamp should be in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. + /// The earliest point in time to get messages after. The timestamp should be in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. /// The cancellation token to use. /// is null. public async Task> ListChatMessagesAsync(string chatThreadId, int? maxPageSize = null, DateTimeOffset? startTime = null, CancellationToken cancellationToken = default) @@ -355,7 +355,7 @@ public async Task> ListChatMessagesAsync(string /// Gets a list of messages from a thread. /// The thread id of the message. /// The maximum number of messages to be returned per page. - /// The earliest point in time to get messages up to. The timestamp should be in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. + /// The earliest point in time to get messages after. The timestamp should be in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. /// The cancellation token to use. /// is null. public Response ListChatMessages(string chatThreadId, int? maxPageSize = null, DateTimeOffset? startTime = null, CancellationToken cancellationToken = default) @@ -876,7 +876,7 @@ public Response AddChatParticipants(string chatThread } } - internal HttpMessage CreateUpdateChatThreadPropertiesRequest(string chatThreadId, string topic) + internal HttpMessage CreateUpdateChatThreadPropertiesRequest(string chatThreadId, string topic, IDictionary metadata, ChatRetentionPolicy retentionPolicy) { var message = _pipeline.CreateMessage(); var request = message.Request; @@ -889,10 +889,19 @@ internal HttpMessage CreateUpdateChatThreadPropertiesRequest(string chatThreadId request.Uri = uri; request.Headers.Add("Accept", "application/json"); request.Headers.Add("Content-Type", "application/merge-patch+json"); - var model = new UpdateChatThreadRequest() + UpdateChatThreadRequest updateChatThreadRequest = new UpdateChatThreadRequest() { - Topic = topic + Topic = topic, + RetentionPolicy = retentionPolicy }; + if (metadata != null) + { + foreach (var value in metadata) + { + updateChatThreadRequest.Metadata.Add(value); + } + } + var model = updateChatThreadRequest; var content = new Utf8JsonRequestContent(); content.JsonWriter.WriteObjectValue(model); request.Content = content; @@ -902,16 +911,18 @@ internal HttpMessage CreateUpdateChatThreadPropertiesRequest(string chatThreadId /// Updates a thread's properties. /// The id of the thread to update. /// Chat thread topic. + /// Contextual metadata for the thread. The metadata consists of name/value pairs. The total size of all metadata pairs can be up to 1KB in size. + /// Data retention policy for auto deletion. /// The cancellation token to use. /// is null. - public async Task UpdateChatThreadPropertiesAsync(string chatThreadId, string topic = null, CancellationToken cancellationToken = default) + public async Task UpdateChatThreadPropertiesAsync(string chatThreadId, string topic = null, IDictionary metadata = null, ChatRetentionPolicy retentionPolicy = null, CancellationToken cancellationToken = default) { if (chatThreadId == null) { throw new ArgumentNullException(nameof(chatThreadId)); } - using var message = CreateUpdateChatThreadPropertiesRequest(chatThreadId, topic); + using var message = CreateUpdateChatThreadPropertiesRequest(chatThreadId, topic, metadata, retentionPolicy); await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); switch (message.Response.Status) { @@ -925,16 +936,18 @@ public async Task UpdateChatThreadPropertiesAsync(string chatThreadId, /// Updates a thread's properties. /// The id of the thread to update. /// Chat thread topic. + /// Contextual metadata for the thread. The metadata consists of name/value pairs. The total size of all metadata pairs can be up to 1KB in size. + /// Data retention policy for auto deletion. /// The cancellation token to use. /// is null. - public Response UpdateChatThreadProperties(string chatThreadId, string topic = null, CancellationToken cancellationToken = default) + public Response UpdateChatThreadProperties(string chatThreadId, string topic = null, IDictionary metadata = null, ChatRetentionPolicy retentionPolicy = null, CancellationToken cancellationToken = default) { if (chatThreadId == null) { throw new ArgumentNullException(nameof(chatThreadId)); } - using var message = CreateUpdateChatThreadPropertiesRequest(chatThreadId, topic); + using var message = CreateUpdateChatThreadPropertiesRequest(chatThreadId, topic, metadata, retentionPolicy); _pipeline.Send(message, cancellationToken); switch (message.Response.Status) { @@ -1182,7 +1195,7 @@ internal HttpMessage CreateListChatMessagesNextPageRequest(string nextLink, stri /// The URL to the next page of results. /// The thread id of the message. /// The maximum number of messages to be returned per page. - /// The earliest point in time to get messages up to. The timestamp should be in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. + /// The earliest point in time to get messages after. The timestamp should be in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. /// The cancellation token to use. /// or is null. public async Task> ListChatMessagesNextPageAsync(string nextLink, string chatThreadId, int? maxPageSize = null, DateTimeOffset? startTime = null, CancellationToken cancellationToken = default) @@ -1216,7 +1229,7 @@ public async Task> ListChatMessagesNextPageAsyn /// The URL to the next page of results. /// The thread id of the message. /// The maximum number of messages to be returned per page. - /// The earliest point in time to get messages up to. The timestamp should be in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. + /// The earliest point in time to get messages after. The timestamp should be in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. /// The cancellation token to use. /// or is null. public Response ListChatMessagesNextPage(string nextLink, string chatThreadId, int? maxPageSize = null, DateTimeOffset? startTime = null, CancellationToken cancellationToken = default) diff --git a/sdk/communication/Azure.Communication.Chat/src/Generated/Models/ChatParticipantInternal.Serialization.cs b/sdk/communication/Azure.Communication.Chat/src/Generated/Models/ChatParticipantInternal.Serialization.cs index 7797aa4b7e25..9a86134748cf 100644 --- a/sdk/communication/Azure.Communication.Chat/src/Generated/Models/ChatParticipantInternal.Serialization.cs +++ b/sdk/communication/Azure.Communication.Chat/src/Generated/Models/ChatParticipantInternal.Serialization.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using System.Text.Json; using Azure.Core; @@ -28,6 +29,17 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WritePropertyName("shareHistoryTime"u8); writer.WriteStringValue(ShareHistoryTime.Value, "O"); } + if (Optional.IsCollectionDefined(Metadata)) + { + writer.WritePropertyName("metadata"u8); + writer.WriteStartObject(); + foreach (var item in Metadata) + { + writer.WritePropertyName(item.Key); + writer.WriteStringValue(item.Value); + } + writer.WriteEndObject(); + } writer.WriteEndObject(); } @@ -40,6 +52,7 @@ internal static ChatParticipantInternal DeserializeChatParticipantInternal(JsonE CommunicationIdentifierModel communicationIdentifier = default; string displayName = default; DateTimeOffset? shareHistoryTime = default; + IDictionary metadata = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("communicationIdentifier"u8)) @@ -61,8 +74,22 @@ internal static ChatParticipantInternal DeserializeChatParticipantInternal(JsonE shareHistoryTime = property.Value.GetDateTimeOffset("O"); continue; } + if (property.NameEquals("metadata"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + Dictionary dictionary = new Dictionary(); + foreach (var property0 in property.Value.EnumerateObject()) + { + dictionary.Add(property0.Name, property0.Value.GetString()); + } + metadata = dictionary; + continue; + } } - return new ChatParticipantInternal(communicationIdentifier, displayName, shareHistoryTime); + return new ChatParticipantInternal(communicationIdentifier, displayName, shareHistoryTime, metadata ?? new ChangeTrackingDictionary()); } /// Deserializes the model from a raw response. diff --git a/sdk/communication/Azure.Communication.Chat/src/Generated/Models/ChatParticipantInternal.cs b/sdk/communication/Azure.Communication.Chat/src/Generated/Models/ChatParticipantInternal.cs index f60721a6061e..976064907860 100644 --- a/sdk/communication/Azure.Communication.Chat/src/Generated/Models/ChatParticipantInternal.cs +++ b/sdk/communication/Azure.Communication.Chat/src/Generated/Models/ChatParticipantInternal.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; namespace Azure.Communication.Chat { @@ -20,17 +21,20 @@ public ChatParticipantInternal(CommunicationIdentifierModel communicationIdentif Argument.AssertNotNull(communicationIdentifier, nameof(communicationIdentifier)); CommunicationIdentifier = communicationIdentifier; + Metadata = new ChangeTrackingDictionary(); } /// Initializes a new instance of . /// Identifies a participant in Azure Communication services. A participant is, for example, a phone number or an Azure communication user. This model is polymorphic: Apart from kind and rawId, at most one further property may be set which must match the kind enum value. /// Display name for the chat participant. /// Time from which the chat history is shared with the participant. The timestamp is in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. - internal ChatParticipantInternal(CommunicationIdentifierModel communicationIdentifier, string displayName, DateTimeOffset? shareHistoryTime) + /// Contextual metadata for the chat participant. The metadata consists of name/value pairs. The total size of all metadata pairs can be up to 1KB in size. + internal ChatParticipantInternal(CommunicationIdentifierModel communicationIdentifier, string displayName, DateTimeOffset? shareHistoryTime, IDictionary metadata) { CommunicationIdentifier = communicationIdentifier; DisplayName = displayName; ShareHistoryTime = shareHistoryTime; + Metadata = metadata; } /// Identifies a participant in Azure Communication services. A participant is, for example, a phone number or an Azure communication user. This model is polymorphic: Apart from kind and rawId, at most one further property may be set which must match the kind enum value. @@ -39,5 +43,7 @@ internal ChatParticipantInternal(CommunicationIdentifierModel communicationIdent public string DisplayName { get; set; } /// Time from which the chat history is shared with the participant. The timestamp is in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. public DateTimeOffset? ShareHistoryTime { get; set; } + /// Contextual metadata for the chat participant. The metadata consists of name/value pairs. The total size of all metadata pairs can be up to 1KB in size. + public IDictionary Metadata { get; } } } diff --git a/sdk/communication/Azure.Communication.Chat/src/Generated/Models/ChatRetentionPolicy.Serialization.cs b/sdk/communication/Azure.Communication.Chat/src/Generated/Models/ChatRetentionPolicy.Serialization.cs new file mode 100644 index 000000000000..0e9b9dc1da94 --- /dev/null +++ b/sdk/communication/Azure.Communication.Chat/src/Generated/Models/ChatRetentionPolicy.Serialization.cs @@ -0,0 +1,56 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure.Core; + +namespace Azure.Communication.Chat +{ + public partial class ChatRetentionPolicy : IUtf8JsonSerializable + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + { + writer.WriteStartObject(); + writer.WritePropertyName("kind"u8); + writer.WriteStringValue(Kind.ToString()); + writer.WriteEndObject(); + } + + internal static ChatRetentionPolicy DeserializeChatRetentionPolicy(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + if (element.TryGetProperty("kind", out JsonElement discriminator)) + { + switch (discriminator.GetString()) + { + case "none": return NoneRetentionPolicy.DeserializeNoneRetentionPolicy(element); + case "threadCreationDate": return ThreadCreationDateRetentionPolicy.DeserializeThreadCreationDateRetentionPolicy(element); + } + } + return UnknownChatRetentionPolicy.DeserializeUnknownChatRetentionPolicy(element); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static ChatRetentionPolicy FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeChatRetentionPolicy(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } + } +} diff --git a/sdk/communication/Azure.Communication.Chat/src/Generated/Models/ChatRetentionPolicy.cs b/sdk/communication/Azure.Communication.Chat/src/Generated/Models/ChatRetentionPolicy.cs new file mode 100644 index 000000000000..ba56728a2ff3 --- /dev/null +++ b/sdk/communication/Azure.Communication.Chat/src/Generated/Models/ChatRetentionPolicy.cs @@ -0,0 +1,32 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +namespace Azure.Communication.Chat +{ + /// + /// Data retention policy for auto deletion. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include and . + /// + public abstract partial class ChatRetentionPolicy + { + /// Initializes a new instance of . + protected ChatRetentionPolicy() + { + } + + /// Initializes a new instance of . + /// Retention Policy Type. + internal ChatRetentionPolicy(RetentionPolicyKind kind) + { + Kind = kind; + } + + /// Retention Policy Type. + internal RetentionPolicyKind Kind { get; set; } + } +} diff --git a/sdk/communication/Azure.Communication.Chat/src/Generated/Models/ChatThreadPropertiesInternal.Serialization.cs b/sdk/communication/Azure.Communication.Chat/src/Generated/Models/ChatThreadPropertiesInternal.Serialization.cs index 1b9b985adf88..b344553f86fb 100644 --- a/sdk/communication/Azure.Communication.Chat/src/Generated/Models/ChatThreadPropertiesInternal.Serialization.cs +++ b/sdk/communication/Azure.Communication.Chat/src/Generated/Models/ChatThreadPropertiesInternal.Serialization.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; using System.Text.Json; namespace Azure.Communication.Chat @@ -23,6 +24,8 @@ internal static ChatThreadPropertiesInternal DeserializeChatThreadPropertiesInte DateTimeOffset createdOn = default; CommunicationIdentifierModel createdByCommunicationIdentifier = default; DateTimeOffset? deletedOn = default; + IReadOnlyDictionary metadata = default; + ChatRetentionPolicy retentionPolicy = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("id"u8)) @@ -54,8 +57,38 @@ internal static ChatThreadPropertiesInternal DeserializeChatThreadPropertiesInte deletedOn = property.Value.GetDateTimeOffset("O"); continue; } + if (property.NameEquals("metadata"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + Dictionary dictionary = new Dictionary(); + foreach (var property0 in property.Value.EnumerateObject()) + { + dictionary.Add(property0.Name, property0.Value.GetString()); + } + metadata = dictionary; + continue; + } + if (property.NameEquals("retentionPolicy"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + retentionPolicy = ChatRetentionPolicy.DeserializeChatRetentionPolicy(property.Value); + continue; + } } - return new ChatThreadPropertiesInternal(id, topic, createdOn, createdByCommunicationIdentifier, deletedOn); + return new ChatThreadPropertiesInternal( + id, + topic, + createdOn, + createdByCommunicationIdentifier, + deletedOn, + metadata ?? new ChangeTrackingDictionary(), + retentionPolicy); } /// Deserializes the model from a raw response. diff --git a/sdk/communication/Azure.Communication.Chat/src/Generated/Models/ChatThreadPropertiesInternal.cs b/sdk/communication/Azure.Communication.Chat/src/Generated/Models/ChatThreadPropertiesInternal.cs index 12ee5c3b1736..051424b777aa 100644 --- a/sdk/communication/Azure.Communication.Chat/src/Generated/Models/ChatThreadPropertiesInternal.cs +++ b/sdk/communication/Azure.Communication.Chat/src/Generated/Models/ChatThreadPropertiesInternal.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Collections.Generic; namespace Azure.Communication.Chat { @@ -28,6 +29,7 @@ internal ChatThreadPropertiesInternal(string id, string topic, DateTimeOffset cr Topic = topic; CreatedOn = createdOn; CreatedByCommunicationIdentifier = createdByCommunicationIdentifier; + Metadata = new ChangeTrackingDictionary(); } /// Initializes a new instance of . @@ -36,13 +38,21 @@ internal ChatThreadPropertiesInternal(string id, string topic, DateTimeOffset cr /// The timestamp when the chat thread was created. The timestamp is in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. /// Identifies a participant in Azure Communication services. A participant is, for example, a phone number or an Azure communication user. This model is polymorphic: Apart from kind and rawId, at most one further property may be set which must match the kind enum value. /// The timestamp when the chat thread was deleted. The timestamp is in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. - internal ChatThreadPropertiesInternal(string id, string topic, DateTimeOffset createdOn, CommunicationIdentifierModel createdByCommunicationIdentifier, DateTimeOffset? deletedOn) + /// Contextual metadata for the thread. The metadata consists of name/value pairs. The total size of all metadata pairs can be up to 1KB in size. + /// + /// Data retention policy for auto deletion. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include and . + /// + internal ChatThreadPropertiesInternal(string id, string topic, DateTimeOffset createdOn, CommunicationIdentifierModel createdByCommunicationIdentifier, DateTimeOffset? deletedOn, IReadOnlyDictionary metadata, ChatRetentionPolicy retentionPolicy) { Id = id; Topic = topic; CreatedOn = createdOn; CreatedByCommunicationIdentifier = createdByCommunicationIdentifier; DeletedOn = deletedOn; + Metadata = metadata; + RetentionPolicy = retentionPolicy; } /// Chat thread id. @@ -55,5 +65,13 @@ internal ChatThreadPropertiesInternal(string id, string topic, DateTimeOffset cr public CommunicationIdentifierModel CreatedByCommunicationIdentifier { get; } /// The timestamp when the chat thread was deleted. The timestamp is in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. public DateTimeOffset? DeletedOn { get; } + /// Contextual metadata for the thread. The metadata consists of name/value pairs. The total size of all metadata pairs can be up to 1KB in size. + public IReadOnlyDictionary Metadata { get; } + /// + /// Data retention policy for auto deletion. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include and . + /// + public ChatRetentionPolicy RetentionPolicy { get; } } } diff --git a/sdk/communication/Azure.Communication.Chat/src/Generated/Models/CreateChatThreadRequest.Serialization.cs b/sdk/communication/Azure.Communication.Chat/src/Generated/Models/CreateChatThreadRequest.Serialization.cs index 832cd3588a46..8cdb33e1183d 100644 --- a/sdk/communication/Azure.Communication.Chat/src/Generated/Models/CreateChatThreadRequest.Serialization.cs +++ b/sdk/communication/Azure.Communication.Chat/src/Generated/Models/CreateChatThreadRequest.Serialization.cs @@ -27,6 +27,22 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) } writer.WriteEndArray(); } + if (Optional.IsCollectionDefined(Metadata)) + { + writer.WritePropertyName("metadata"u8); + writer.WriteStartObject(); + foreach (var item in Metadata) + { + writer.WritePropertyName(item.Key); + writer.WriteStringValue(item.Value); + } + writer.WriteEndObject(); + } + if (Optional.IsDefined(RetentionPolicy)) + { + writer.WritePropertyName("retentionPolicy"u8); + writer.WriteObjectValue(RetentionPolicy); + } writer.WriteEndObject(); } diff --git a/sdk/communication/Azure.Communication.Chat/src/Generated/Models/CreateChatThreadRequest.cs b/sdk/communication/Azure.Communication.Chat/src/Generated/Models/CreateChatThreadRequest.cs index 1310fb36c72c..107844b3d816 100644 --- a/sdk/communication/Azure.Communication.Chat/src/Generated/Models/CreateChatThreadRequest.cs +++ b/sdk/communication/Azure.Communication.Chat/src/Generated/Models/CreateChatThreadRequest.cs @@ -22,20 +22,37 @@ public CreateChatThreadRequest(string topic) Topic = topic; Participants = new ChangeTrackingList(); + Metadata = new ChangeTrackingDictionary(); } /// Initializes a new instance of . /// The chat thread topic. /// Participants to be added to the chat thread. - internal CreateChatThreadRequest(string topic, IList participants) + /// Contextual metadata for the thread. The metadata consists of name/value pairs. The total size of all metadata pairs can be up to 1KB in size. + /// + /// Data retention policy for auto deletion. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include and . + /// + internal CreateChatThreadRequest(string topic, IList participants, IDictionary metadata, ChatRetentionPolicy retentionPolicy) { Topic = topic; Participants = participants; + Metadata = metadata; + RetentionPolicy = retentionPolicy; } /// The chat thread topic. public string Topic { get; } /// Participants to be added to the chat thread. public IList Participants { get; } + /// Contextual metadata for the thread. The metadata consists of name/value pairs. The total size of all metadata pairs can be up to 1KB in size. + public IDictionary Metadata { get; } + /// + /// Data retention policy for auto deletion. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include and . + /// + public ChatRetentionPolicy RetentionPolicy { get; set; } } } diff --git a/sdk/communication/Azure.Communication.Chat/src/Generated/Models/NoneRetentionPolicy.Serialization.cs b/sdk/communication/Azure.Communication.Chat/src/Generated/Models/NoneRetentionPolicy.Serialization.cs new file mode 100644 index 000000000000..7ea37bc61a6c --- /dev/null +++ b/sdk/communication/Azure.Communication.Chat/src/Generated/Models/NoneRetentionPolicy.Serialization.cs @@ -0,0 +1,57 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure.Core; + +namespace Azure.Communication.Chat +{ + public partial class NoneRetentionPolicy : IUtf8JsonSerializable + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + { + writer.WriteStartObject(); + writer.WritePropertyName("kind"u8); + writer.WriteStringValue(Kind.ToString()); + writer.WriteEndObject(); + } + + internal static NoneRetentionPolicy DeserializeNoneRetentionPolicy(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + RetentionPolicyKind kind = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("kind"u8)) + { + kind = new RetentionPolicyKind(property.Value.GetString()); + continue; + } + } + return new NoneRetentionPolicy(kind); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new NoneRetentionPolicy FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeNoneRetentionPolicy(document.RootElement); + } + + /// Convert into a . + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } + } +} diff --git a/sdk/communication/Azure.Communication.Chat/src/Generated/Models/NoneRetentionPolicy.cs b/sdk/communication/Azure.Communication.Chat/src/Generated/Models/NoneRetentionPolicy.cs new file mode 100644 index 000000000000..4e85b38f5ac7 --- /dev/null +++ b/sdk/communication/Azure.Communication.Chat/src/Generated/Models/NoneRetentionPolicy.cs @@ -0,0 +1,26 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +namespace Azure.Communication.Chat +{ + /// No thread retention policy. + public partial class NoneRetentionPolicy : ChatRetentionPolicy + { + /// Initializes a new instance of . + public NoneRetentionPolicy() + { + Kind = RetentionPolicyKind.None; + } + + /// Initializes a new instance of . + /// Retention Policy Type. + internal NoneRetentionPolicy(RetentionPolicyKind kind) : base(kind) + { + Kind = kind; + } + } +} diff --git a/sdk/communication/Azure.Communication.Chat/src/Generated/Models/RetentionPolicyKind.cs b/sdk/communication/Azure.Communication.Chat/src/Generated/Models/RetentionPolicyKind.cs new file mode 100644 index 000000000000..43098fe1a17e --- /dev/null +++ b/sdk/communication/Azure.Communication.Chat/src/Generated/Models/RetentionPolicyKind.cs @@ -0,0 +1,51 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.Communication.Chat +{ + /// Retention Policy Type. + public readonly partial struct RetentionPolicyKind : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public RetentionPolicyKind(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string ThreadCreationDateValue = "threadCreationDate"; + private const string NoneValue = "none"; + + /// Thread retention policy based on thread creation date. + public static RetentionPolicyKind ThreadCreationDate { get; } = new RetentionPolicyKind(ThreadCreationDateValue); + /// No thread retention policy. + public static RetentionPolicyKind None { get; } = new RetentionPolicyKind(NoneValue); + /// Determines if two values are the same. + public static bool operator ==(RetentionPolicyKind left, RetentionPolicyKind right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(RetentionPolicyKind left, RetentionPolicyKind right) => !left.Equals(right); + /// Converts a to a . + public static implicit operator RetentionPolicyKind(string value) => new RetentionPolicyKind(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is RetentionPolicyKind other && Equals(other); + /// + public bool Equals(RetentionPolicyKind other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; + /// + public override string ToString() => _value; + } +} diff --git a/sdk/communication/Azure.Communication.Chat/src/Generated/Models/ThreadCreationDateRetentionPolicy.Serialization.cs b/sdk/communication/Azure.Communication.Chat/src/Generated/Models/ThreadCreationDateRetentionPolicy.Serialization.cs new file mode 100644 index 000000000000..ec7d2157dc4d --- /dev/null +++ b/sdk/communication/Azure.Communication.Chat/src/Generated/Models/ThreadCreationDateRetentionPolicy.Serialization.cs @@ -0,0 +1,65 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure.Core; + +namespace Azure.Communication.Chat +{ + public partial class ThreadCreationDateRetentionPolicy : IUtf8JsonSerializable + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + { + writer.WriteStartObject(); + writer.WritePropertyName("deleteThreadAfterDays"u8); + writer.WriteNumberValue(DeleteThreadAfterDays); + writer.WritePropertyName("kind"u8); + writer.WriteStringValue(Kind.ToString()); + writer.WriteEndObject(); + } + + internal static ThreadCreationDateRetentionPolicy DeserializeThreadCreationDateRetentionPolicy(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + int deleteThreadAfterDays = default; + RetentionPolicyKind kind = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("deleteThreadAfterDays"u8)) + { + deleteThreadAfterDays = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("kind"u8)) + { + kind = new RetentionPolicyKind(property.Value.GetString()); + continue; + } + } + return new ThreadCreationDateRetentionPolicy(kind, deleteThreadAfterDays); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new ThreadCreationDateRetentionPolicy FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeThreadCreationDateRetentionPolicy(document.RootElement); + } + + /// Convert into a . + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } + } +} diff --git a/sdk/communication/Azure.Communication.Chat/src/Generated/Models/ThreadCreationDateRetentionPolicy.cs b/sdk/communication/Azure.Communication.Chat/src/Generated/Models/ThreadCreationDateRetentionPolicy.cs new file mode 100644 index 000000000000..e628fa2589e0 --- /dev/null +++ b/sdk/communication/Azure.Communication.Chat/src/Generated/Models/ThreadCreationDateRetentionPolicy.cs @@ -0,0 +1,33 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +namespace Azure.Communication.Chat +{ + /// Thread retention policy based on thread creation date. + public partial class ThreadCreationDateRetentionPolicy : ChatRetentionPolicy + { + /// Initializes a new instance of . + /// Indicates how many days after the thread creation the thread will be deleted. + public ThreadCreationDateRetentionPolicy(int deleteThreadAfterDays) + { + DeleteThreadAfterDays = deleteThreadAfterDays; + Kind = RetentionPolicyKind.ThreadCreationDate; + } + + /// Initializes a new instance of . + /// Retention Policy Type. + /// Indicates how many days after the thread creation the thread will be deleted. + internal ThreadCreationDateRetentionPolicy(RetentionPolicyKind kind, int deleteThreadAfterDays) : base(kind) + { + DeleteThreadAfterDays = deleteThreadAfterDays; + Kind = kind; + } + + /// Indicates how many days after the thread creation the thread will be deleted. + public int DeleteThreadAfterDays { get; set; } + } +} diff --git a/sdk/communication/Azure.Communication.Chat/src/Generated/Models/UnknownChatRetentionPolicy.Serialization.cs b/sdk/communication/Azure.Communication.Chat/src/Generated/Models/UnknownChatRetentionPolicy.Serialization.cs new file mode 100644 index 000000000000..17620d15eb9c --- /dev/null +++ b/sdk/communication/Azure.Communication.Chat/src/Generated/Models/UnknownChatRetentionPolicy.Serialization.cs @@ -0,0 +1,57 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure.Core; + +namespace Azure.Communication.Chat +{ + internal partial class UnknownChatRetentionPolicy : IUtf8JsonSerializable + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + { + writer.WriteStartObject(); + writer.WritePropertyName("kind"u8); + writer.WriteStringValue(Kind.ToString()); + writer.WriteEndObject(); + } + + internal static UnknownChatRetentionPolicy DeserializeUnknownChatRetentionPolicy(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + RetentionPolicyKind kind = "Unknown"; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("kind"u8)) + { + kind = new RetentionPolicyKind(property.Value.GetString()); + continue; + } + } + return new UnknownChatRetentionPolicy(kind); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new UnknownChatRetentionPolicy FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeUnknownChatRetentionPolicy(document.RootElement); + } + + /// Convert into a . + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } + } +} diff --git a/sdk/communication/Azure.Communication.Chat/src/Generated/Models/UnknownChatRetentionPolicy.cs b/sdk/communication/Azure.Communication.Chat/src/Generated/Models/UnknownChatRetentionPolicy.cs new file mode 100644 index 000000000000..3a7cbb5fdbb1 --- /dev/null +++ b/sdk/communication/Azure.Communication.Chat/src/Generated/Models/UnknownChatRetentionPolicy.cs @@ -0,0 +1,20 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +namespace Azure.Communication.Chat +{ + /// Unknown version of ChatRetentionPolicy. + internal partial class UnknownChatRetentionPolicy : ChatRetentionPolicy + { + /// Initializes a new instance of . + /// Retention Policy Type. + internal UnknownChatRetentionPolicy(RetentionPolicyKind kind) : base(kind) + { + Kind = kind; + } + } +} diff --git a/sdk/communication/Azure.Communication.Chat/src/Generated/Models/UpdateChatThreadRequest.Serialization.cs b/sdk/communication/Azure.Communication.Chat/src/Generated/Models/UpdateChatThreadRequest.Serialization.cs index 103b1ab0b6e4..1446c231a1ee 100644 --- a/sdk/communication/Azure.Communication.Chat/src/Generated/Models/UpdateChatThreadRequest.Serialization.cs +++ b/sdk/communication/Azure.Communication.Chat/src/Generated/Models/UpdateChatThreadRequest.Serialization.cs @@ -20,6 +20,22 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WritePropertyName("topic"u8); writer.WriteStringValue(Topic); } + if (Optional.IsCollectionDefined(Metadata)) + { + writer.WritePropertyName("metadata"u8); + writer.WriteStartObject(); + foreach (var item in Metadata) + { + writer.WritePropertyName(item.Key); + writer.WriteStringValue(item.Value); + } + writer.WriteEndObject(); + } + if (Optional.IsDefined(RetentionPolicy)) + { + writer.WritePropertyName("retentionPolicy"u8); + writer.WriteObjectValue(RetentionPolicy); + } writer.WriteEndObject(); } diff --git a/sdk/communication/Azure.Communication.Chat/src/Generated/Models/UpdateChatThreadRequest.cs b/sdk/communication/Azure.Communication.Chat/src/Generated/Models/UpdateChatThreadRequest.cs index 36f0cfa33809..33d258c2ec45 100644 --- a/sdk/communication/Azure.Communication.Chat/src/Generated/Models/UpdateChatThreadRequest.cs +++ b/sdk/communication/Azure.Communication.Chat/src/Generated/Models/UpdateChatThreadRequest.cs @@ -5,6 +5,8 @@ #nullable disable +using System.Collections.Generic; + namespace Azure.Communication.Chat { /// Request payload for updating a chat thread. @@ -13,16 +15,33 @@ internal partial class UpdateChatThreadRequest /// Initializes a new instance of . public UpdateChatThreadRequest() { + Metadata = new ChangeTrackingDictionary(); } /// Initializes a new instance of . /// Chat thread topic. - internal UpdateChatThreadRequest(string topic) + /// Contextual metadata for the thread. The metadata consists of name/value pairs. The total size of all metadata pairs can be up to 1KB in size. + /// + /// Data retention policy for auto deletion. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include and . + /// + internal UpdateChatThreadRequest(string topic, IDictionary metadata, ChatRetentionPolicy retentionPolicy) { Topic = topic; + Metadata = metadata; + RetentionPolicy = retentionPolicy; } /// Chat thread topic. public string Topic { get; set; } + /// Contextual metadata for the thread. The metadata consists of name/value pairs. The total size of all metadata pairs can be up to 1KB in size. + public IDictionary Metadata { get; } + /// + /// Data retention policy for auto deletion. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include and . + /// + public ChatRetentionPolicy RetentionPolicy { get; set; } } } diff --git a/sdk/communication/Azure.Communication.Chat/src/Models/ChatModelFactory.cs b/sdk/communication/Azure.Communication.Chat/src/Models/ChatModelFactory.cs index 9593ae454243..ed04e0c6d0d3 100644 --- a/sdk/communication/Azure.Communication.Chat/src/Models/ChatModelFactory.cs +++ b/sdk/communication/Azure.Communication.Chat/src/Models/ChatModelFactory.cs @@ -96,16 +96,28 @@ public static ChatMessageReadReceipt ChatMessageReadReceipt(CommunicationIdentif public static ChatMessageContent ChatMessageContent(string message, string topic, CommunicationUserIdentifier communicationUserIdentifier, IEnumerable participants, IEnumerable attachments = null) => new ChatMessageContent(message, topic, communicationUserIdentifier, participants, attachments); /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// Chat message. /// Topic of the message content. /// Created on date time /// Created by /// Deleted on date time - /// A new instance for mocking. + /// A new instance for mocking. public static ChatThreadProperties ChatThreadProperties(string id, string topic, DateTimeOffset createdOn, CommunicationIdentifier createdBy, DateTimeOffset deletedOn) => new ChatThreadProperties(id, topic, createdOn, createdBy, deletedOn); + /// + /// Initializes a new instance of the class. + /// + /// Chat message. + /// Topic of the message content. + /// Created on date time + /// Created by + /// Deleted on date time + /// Property bag of chat thread metadata key - value pairs. + /// A new instance for mocking. + public static ChatThreadProperties ChatThreadProperties(string id, string topic, DateTimeOffset createdOn, CommunicationIdentifier createdBy, DateTimeOffset deletedOn, IDictionary metadata) => new ChatThreadProperties(id, topic, createdOn, createdBy, deletedOn); + /// /// Initializes a new instance of the class. /// @@ -126,14 +138,24 @@ public static ChatMessageReadReceipt ChatMessageReadReceipt(CommunicationIdentif public static ChatAttachment ChatAttachment(string id, ChatAttachmentType attachmentType, string name, Uri uri, Uri previewUri) => new ChatAttachment(id, attachmentType, name, uri, previewUri); /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// User /// Display name for the chat thread member. /// Time from which the chat history is shared with the member. The timestamp is in ISO8601 format: `yyyy-MM-ddTHH:mm:ssZ`. - /// A new instance for mocking. + /// A new instance for mocking. public static ChatParticipant ChatParticipant(CommunicationIdentifier user, string displayName, DateTimeOffset? shareHistoryTime) => new ChatParticipant(user, displayName, shareHistoryTime); + /// + /// Initializes a new instance of the class. + /// + /// User + /// Display name for the chat thread member. + /// Time from which the chat history is shared with the member. The timestamp is in ISO8601 format: `yyyy-MM-ddTHH:mm:ssZ`. + /// Property bag of participant metadata key - value pairs. + /// A new instance for mocking. + public static ChatParticipant ChatParticipant(CommunicationIdentifier user, string displayName, DateTimeOffset? shareHistoryTime, IDictionary metadata) => new ChatParticipant(user, displayName, shareHistoryTime, metadata); + /// /// Initializes a new instance of the class. /// diff --git a/sdk/communication/Azure.Communication.Chat/src/Models/ChatParticipant.cs b/sdk/communication/Azure.Communication.Chat/src/Models/ChatParticipant.cs index a274ecf9243b..e470a5a857dd 100644 --- a/sdk/communication/Azure.Communication.Chat/src/Models/ChatParticipant.cs +++ b/sdk/communication/Azure.Communication.Chat/src/Models/ChatParticipant.cs @@ -2,6 +2,8 @@ // Licensed under the MIT License. using System; +using System.Collections.Generic; +using Azure.Core; namespace Azure.Communication.Chat { @@ -15,13 +17,15 @@ public partial class ChatParticipant public ChatParticipant(CommunicationIdentifier identifier) { User = identifier; + Metadata = new ChangeTrackingDictionary(); } - internal ChatParticipant(CommunicationIdentifier user, string displayName, DateTimeOffset? shareHistoryTime) + internal ChatParticipant(CommunicationIdentifier user, string displayName, DateTimeOffset? shareHistoryTime, IDictionary metadata = null) { User = user; DisplayName = displayName; ShareHistoryTime = shareHistoryTime; + Metadata = metadata; } internal ChatParticipant(ChatParticipantInternal chatParticipantInternal) @@ -29,6 +33,7 @@ internal ChatParticipant(ChatParticipantInternal chatParticipantInternal) User = CommunicationIdentifierSerializer.Deserialize(chatParticipantInternal.CommunicationIdentifier); DisplayName = chatParticipantInternal.DisplayName; ShareHistoryTime = chatParticipantInternal.ShareHistoryTime; + Metadata = chatParticipantInternal.Metadata; } ///Instance of . @@ -38,9 +43,14 @@ internal ChatParticipant(ChatParticipantInternal chatParticipantInternal) /// Time from which the chat history is shared with the member. The timestamp is in ISO8601 format: `yyyy-MM-ddTHH:mm:ssZ`. public DateTimeOffset? ShareHistoryTime { get; set; } + /// + /// Metadata + /// + public IDictionary Metadata { get; } + internal ChatParticipantInternal ToChatParticipantInternal() { - return new ChatParticipantInternal(CommunicationIdentifierSerializer.Serialize(User), DisplayName, ShareHistoryTime); + return new ChatParticipantInternal(CommunicationIdentifierSerializer.Serialize(User), DisplayName, ShareHistoryTime, Metadata); } } } diff --git a/sdk/communication/Azure.Communication.Chat/src/Models/ChatThreadProperties.cs b/sdk/communication/Azure.Communication.Chat/src/Models/ChatThreadProperties.cs index ed1c5ebd34a9..e40b8c914c64 100644 --- a/sdk/communication/Azure.Communication.Chat/src/Models/ChatThreadProperties.cs +++ b/sdk/communication/Azure.Communication.Chat/src/Models/ChatThreadProperties.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System; +using System.Collections.Generic; namespace Azure.Communication.Chat { @@ -15,6 +16,8 @@ internal ChatThreadProperties(ChatThreadPropertiesInternal chatThreadPropertiesI CreatedOn = chatThreadPropertiesInternal.CreatedOn; CreatedBy = CommunicationIdentifierSerializer.Deserialize(chatThreadPropertiesInternal.CreatedByCommunicationIdentifier); DeletedOn = chatThreadPropertiesInternal.DeletedOn; + Metadata = chatThreadPropertiesInternal.Metadata; + RetentionPolicy = chatThreadPropertiesInternal.RetentionPolicy; } internal ChatThreadProperties(string id, string topic, DateTimeOffset createdOn, CommunicationIdentifier createdBy, DateTimeOffset deletedOn) @@ -36,5 +39,15 @@ internal ChatThreadProperties(string id, string topic, DateTimeOffset createdOn, public CommunicationIdentifier CreatedBy { get; } /// The timestamp when the chat thread was deleted. The timestamp is in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. public DateTimeOffset? DeletedOn { get; } + + /// + /// Metadata + /// + public IReadOnlyDictionary Metadata { get; } = new ChangeTrackingDictionary(); + + /// + /// Thread retention policy + /// + public ChatRetentionPolicy RetentionPolicy { get; } } } diff --git a/sdk/communication/Azure.Communication.Chat/src/Models/CreateChatThreadOptions.cs b/sdk/communication/Azure.Communication.Chat/src/Models/CreateChatThreadOptions.cs new file mode 100644 index 000000000000..93f2a5690a34 --- /dev/null +++ b/sdk/communication/Azure.Communication.Chat/src/Models/CreateChatThreadOptions.cs @@ -0,0 +1,42 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +using System.Collections.Generic; +namespace Azure.Communication.Chat +{ + /// + /// Create chat thread parameter option + /// + public class CreateChatThreadOptions + { + /// + /// Create chat thread parameter option + /// + public CreateChatThreadOptions(string topic) + { + Topic = topic; + Metadata = new Dictionary(); + Participants = new List(); + } + /// + /// Topic of the thread + /// + public string Topic { get; } + /// + /// List of thread participants + /// + public IList Participants { get; } + /// + /// If specified, the client directs that the request is repeatable; that is, that the client can make the request multiple times with the same Repeatability-Request-ID and get back an appropriate response without the server executing the request multiple times. The value of the Repeatability-Request-ID is an opaque string representing a client-generated, globally unique for all time, identifier for the request. It is recommended to use version 4 (random) UUIDs. + /// + public string IdempotencyToken { get; set; } + /// + /// Property bag of chat thread metadata key - value pairs. + /// + public IDictionary Metadata { get; } + + /// + /// Thread retention policy + /// + public ChatRetentionPolicy RetentionPolicy { get; set; } + } +} diff --git a/sdk/communication/Azure.Communication.Chat/src/Models/UpdateChatThreadPropertiesOptions.cs b/sdk/communication/Azure.Communication.Chat/src/Models/UpdateChatThreadPropertiesOptions.cs new file mode 100644 index 000000000000..bdf8f2a3ba9b --- /dev/null +++ b/sdk/communication/Azure.Communication.Chat/src/Models/UpdateChatThreadPropertiesOptions.cs @@ -0,0 +1,33 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +using System.Collections.Generic; +using Azure.Core; +namespace Azure.Communication.Chat +{ + /// + /// Update chat thread parameter options + /// + public class UpdateChatThreadPropertiesOptions + { + /// + /// Update chat thread parameter options + /// + public UpdateChatThreadPropertiesOptions() + { + Metadata = new ChangeTrackingDictionary(); + } + /// + /// Topic of the thread + /// + public string Topic { get; set; } + /// + /// Property bag of chat thread metadata key - value pairs. + /// + public IDictionary Metadata { get; } + + /// + /// Thread retention policy + /// + public ChatRetentionPolicy RetentionPolicy { get; set; } + } +} diff --git a/sdk/communication/Azure.Communication.Chat/src/autorest.md b/sdk/communication/Azure.Communication.Chat/src/autorest.md index 76a1f852bce3..eed453cbb3de 100644 --- a/sdk/communication/Azure.Communication.Chat/src/autorest.md +++ b/sdk/communication/Azure.Communication.Chat/src/autorest.md @@ -11,9 +11,9 @@ If any of the new objects needs to be overwritten, add the required changes to t ``` yaml title: Chat -tag: package-chat-2024-03-07 +tag: package-chat-2025-03-15 model-namespace: false require: - - https://raw.githubusercontent.com/Azure/azure-rest-api-specs/72d4c8cae964a12dc27ad4684b0bddf493225338/specification/communication/data-plane/Chat/readme.md + - https://raw.githubusercontent.com/Azure/azure-rest-api-specs/b97334ac101d4a5e6556e4d67d1bcdd46fc12139/specification/communication/data-plane/Chat/readme.md payload-flattening-threshold: 10 generation1-convenience-client: true diff --git a/sdk/communication/Azure.Communication.Chat/tests/ChatClients/ChatClientsLiveTests.cs b/sdk/communication/Azure.Communication.Chat/tests/ChatClients/ChatClientsLiveTests.cs index f77e49e7e326..56865ace5d03 100644 --- a/sdk/communication/Azure.Communication.Chat/tests/ChatClients/ChatClientsLiveTests.cs +++ b/sdk/communication/Azure.Communication.Chat/tests/ChatClients/ChatClientsLiveTests.cs @@ -53,25 +53,97 @@ public async Task Thread_CGUD__Participant_AUR__Message_GSU__Notification_T() var topic = "Thread async from C# sdk"; var displayNameMessage = "DisplayName sender message 1"; - var participants = new List - { - new ChatParticipant(user1) { DisplayName = "user1" }, - new ChatParticipant(user2) { DisplayName = "user2" }, - new ChatParticipant(user3) { DisplayName = "user3" } - }; + + var participant1 = new ChatParticipant(user1) { DisplayName = "user1" }; + participant1.Metadata.Add("ParticipantMetaKey1", "ParticipantMetaValue1"); + participant1.Metadata.Add("ParticipantMetaKey2", "ParticipantMetaValue2"); ChatClient chatClient = CreateInstrumentedChatClient(token1); ChatClient chatClient3 = CreateInstrumentedChatClient(token3); + var options = new CreateChatThreadOptions(topic); + options.Metadata.Add("MetaKey1", "MetaValue1"); + options.Metadata.Add("MetaKey2", "MetaValue2"); + options.IdempotencyToken = repeatabilityRequestId1; + options.Participants.Add(participant1); + options.Participants.Add(new ChatParticipant(user2) { DisplayName = "user2" }); + options.Participants.Add(new ChatParticipant(user3) { DisplayName = "user3" }); + options.RetentionPolicy = new ThreadCreationDateRetentionPolicy(60); + + CreateChatThreadResult createChatThreadResult = await chatClient.CreateChatThreadAsync(options); + //act - CreateChatThreadResult createChatThreadResult = await chatClient.CreateChatThreadAsync(topic, participants, repeatabilityRequestId1); ChatThreadClient chatThreadClient = GetInstrumentedChatThreadClient(chatClient, createChatThreadResult.ChatThread.Id); var threadId = chatThreadClient.Id; + + Assert.IsNotNull(createChatThreadResult.ChatThread.Metadata); + Assert.AreEqual("MetaValue1", createChatThreadResult.ChatThread.Metadata["MetaKey1"]); + Assert.AreEqual("MetaValue2", createChatThreadResult.ChatThread.Metadata["MetaKey2"]); + + Assert.IsNotNull(createChatThreadResult.ChatThread.RetentionPolicy); + var threadCreationDateRetentionPolicy = createChatThreadResult.ChatThread.RetentionPolicy as ThreadCreationDateRetentionPolicy; + Assert.IsNotNull(threadCreationDateRetentionPolicy); + Assert.AreEqual(RetentionPolicyKind.ThreadCreationDate, threadCreationDateRetentionPolicy?.Kind); + Assert.AreEqual(60, threadCreationDateRetentionPolicy?.DeleteThreadAfterDays); + + var updateOptionsWithSameProperties = new UpdateChatThreadPropertiesOptions(); + await chatThreadClient.UpdatePropertiesAsync(updateOptionsWithSameProperties); + + var updateResponseWithSameProperties = await chatThreadClient.GetPropertiesAsync(); + Assert.IsNotNull(updateResponseWithSameProperties.Value.Metadata); + Assert.AreEqual("MetaValue1", updateResponseWithSameProperties.Value.Metadata["MetaKey1"]); + Assert.AreEqual("MetaValue2", updateResponseWithSameProperties.Value.Metadata["MetaKey2"]); + + var sameDataRetentionPolicy = updateResponseWithSameProperties.Value.RetentionPolicy as ThreadCreationDateRetentionPolicy; + Assert.IsNotNull(sameDataRetentionPolicy); + Assert.AreEqual(RetentionPolicyKind.ThreadCreationDate, sameDataRetentionPolicy?.Kind); + Assert.AreEqual(60, sameDataRetentionPolicy?.DeleteThreadAfterDays); + + var updateOptionsWithNewMetadata = new UpdateChatThreadPropertiesOptions(); + updateOptionsWithNewMetadata.Metadata.Add("MetaKeyNew1", "MetaValueNew1"); + updateOptionsWithNewMetadata.Metadata.Add("MetaKeyNew2", "MetaValueNew2"); + + await chatThreadClient.UpdatePropertiesAsync(updateOptionsWithNewMetadata); + var updateResponseWithNewMetadata = await chatThreadClient.GetPropertiesAsync(); + Assert.IsNotNull(updateResponseWithNewMetadata.Value.Metadata); + Assert.AreEqual("MetaValueNew1", updateResponseWithNewMetadata.Value.Metadata["MetaKeyNew1"]); + Assert.AreEqual("MetaValueNew2", updateResponseWithNewMetadata.Value.Metadata["MetaKeyNew2"]); + + var updateOptionsWithNewRetentionPolicy = new UpdateChatThreadPropertiesOptions(); + updateOptionsWithNewRetentionPolicy.RetentionPolicy = new ThreadCreationDateRetentionPolicy(40); + + await chatThreadClient.UpdatePropertiesAsync(updateOptionsWithNewRetentionPolicy); + var updateResponseWithNewRetentionPolicy = await chatThreadClient.GetPropertiesAsync(); + var newDataRetentionPolicy = updateResponseWithNewRetentionPolicy.Value.RetentionPolicy as ThreadCreationDateRetentionPolicy; + Assert.IsNotNull(newDataRetentionPolicy); + Assert.AreEqual(RetentionPolicyKind.ThreadCreationDate, newDataRetentionPolicy?.Kind); + Assert.AreEqual(40, newDataRetentionPolicy?.DeleteThreadAfterDays); + + var updateOptionsWithNoneRetentionPolicy = new UpdateChatThreadPropertiesOptions(); + updateOptionsWithNoneRetentionPolicy.RetentionPolicy = new NoneRetentionPolicy(); + + await chatThreadClient.UpdatePropertiesAsync(updateOptionsWithNoneRetentionPolicy); + var updateResponseWithNoneRetentionPolicy = await chatThreadClient.GetPropertiesAsync(); + var noneDataRetentionPolicy = updateResponseWithNoneRetentionPolicy.Value.RetentionPolicy as NoneRetentionPolicy; + Assert.IsNotNull(noneDataRetentionPolicy); + Assert.AreEqual(RetentionPolicyKind.None, noneDataRetentionPolicy?.Kind); + + var participants = new List + { + new ChatParticipant(user1) { DisplayName = "user1" }, + new ChatParticipant(user2) { DisplayName = "user2" }, + new ChatParticipant(user3) { DisplayName = "user3" } + }; CreateChatThreadResult createChatThreadResult2 = await chatClient.CreateChatThreadAsync(topic, participants, repeatabilityRequestId2); ChatThreadClient chatThreadClient2 = GetInstrumentedChatThreadClient(chatClient, createChatThreadResult2.ChatThread.Id); ChatThreadClient chatThreadClient3 = GetInstrumentedChatThreadClient(chatClient3, threadId); AsyncPageable chatParticipantsOnCreation = chatThreadClient.GetParticipantsAsync(); - var chatParticipantsOnCreationCount = chatParticipantsOnCreation.ToEnumerableAsync().Result.Count; + var chatParticipantsOnCreationList = chatParticipantsOnCreation.ToEnumerableAsync().Result; + var chatParticipantsOnCreationCount = chatParticipantsOnCreationList.Count; + + var chatParticipant1 = chatParticipantsOnCreationList.FirstOrDefault(x => x.User == user1); + Assert.AreEqual("ParticipantMetaValue1", chatParticipant1?.Metadata["ParticipantMetaKey1"]); + Assert.AreEqual("ParticipantMetaValue2", chatParticipant1?.Metadata["ParticipantMetaKey2"]); var updatedTopic = "Updated topic - C# sdk"; await chatThreadClient.UpdateTopicAsync(updatedTopic); diff --git a/sdk/communication/Azure.Communication.Chat/tests/ChatClients/ChatClientsTests.cs b/sdk/communication/Azure.Communication.Chat/tests/ChatClients/ChatClientsTests.cs index b4ad1d9cdccb..e25f1ddc9e67 100644 --- a/sdk/communication/Azure.Communication.Chat/tests/ChatClients/ChatClientsTests.cs +++ b/sdk/communication/Azure.Communication.Chat/tests/ChatClients/ChatClientsTests.cs @@ -25,7 +25,8 @@ public class ChatClientsTests : ClientTestBase private const string AddParticipantsdWithErrorsApiResponsePayload = "{\"invalidParticipants\":[{\"code\":\"404\",\"message\":\"Not found\",\"target\":\"8:acs:1b5cc06b-f352-4571-b1e6-d9b259b7c776_00000007-1234-1234-1234-223a12345677\"},{\"code\":\"401\",\"message\":\"Authentication failed\",\"target\":\"8:acs:1b5cc06b-f352-4571-b1e6-d9b259b7c776_00000007-1234-1234-1234-223a12345678\"},{\"code\":\"403\",\"message\":\"Permissions check failed\",\"target\":\"8:acs:1b5cc06b-f352-4571-b1e6-d9b259b7c776_00000007-1234-1234-1234-223a12345679\"}]}"; - private const string CreateChatThreadSuccessApiResponsePayload = "{\"chatThread\":{\"id\":\"19:e5e7a3fa5f314a01b2d12c6c7b37f433@thread.v2\",\"topic\":\"Topic for testing success\",\"createdOn\":\"2021-02-25T22:34:48Z\",\"createdByCommunicationIdentifier\":{\"rawId\":\"8:acs:46849534-eb08-4ab7-bde7-c36928cd1547_00000007-165c-9b10-b0b7-3a3a0d00076c\",\"communicationUser\":{\"id\":\"8:acs:46849534-eb08-4ab7-bde7-c36928cd1547_00000007-165c-9b10-b0b7-3a3a0d00076c\"}}}}"; + private const string CreateChatThreadSuccessApiResponsePayload = "{\"chatThread\":{\"id\":\"19:e5e7a3fa5f314a01b2d12c6c7b37f433@thread.v2\",\"topic\":\"Topic for testing success\",\"createdOn\":\"2021-02-25T22:34:48Z\",\"createdByCommunicationIdentifier\":{\"rawId\":\"8:acs:46849534-eb08-4ab7-bde7-c36928cd1547_00000007-165c-9b10-b0b7-3a3a0d00076c\",\"communicationUser\":{\"id\":\"8:acs:46849534-eb08-4ab7-bde7-c36928cd1547_00000007-165c-9b10-b0b7-3a3a0d00076c\"}},\"metadata\": {\"MetaKey1\":\"MetaValue1\",\"MetaKey2\": \"MetaValue2\"}, \"retentionPolicy\":{ \"kind\":\"threadCreationDate\", \"deleteThreadAfterDays\":40 }}}"; + private const string CreateChatThreadNoneRetentionSuccessApiResponsePayload = "{\"chatThread\":{\"id\":\"19:e5e7a3fa5f314a01b2d12c6c7b37f433@thread.v2\",\"topic\":\"Topic for testing success\",\"createdOn\":\"2021-02-25T22:34:48Z\",\"createdByCommunicationIdentifier\":{\"rawId\":\"8:acs:46849534-eb08-4ab7-bde7-c36928cd1547_00000007-165c-9b10-b0b7-3a3a0d00076c\",\"communicationUser\":{\"id\":\"8:acs:46849534-eb08-4ab7-bde7-c36928cd1547_00000007-165c-9b10-b0b7-3a3a0d00076c\"}},\"metadata\": {\"MetaKey1\":\"MetaValue1\",\"MetaKey2\": \"MetaValue2\"}, \"retentionPolicy\":{ \"kind\":\"none\"}}}"; private const string GetThreadApiResponsePayload = "{\"id\":\"19:e5e7a3fa5f314a01b2d12c6c7b37f433@thread.v2\",\"topic\":\"Test Thread\",\"createdOn\":\"2021-02-26T00:46:08Z\",\"createdByCommunicationIdentifier\":{\"rawId\":\"8:acs:1b5cc06b-f352-4571-b1e6-d9b259b7c776_00000007-8f5e-776d-ea7c-5a3a0d0027b7\",\"communicationUser\":{\"id\":\"8:acs:1b5cc06b-f352-4571-b1e6-d9b259b7c776_00000007-8f5e-776d-ea7c-5a3a0d0027b7\"}}}"; @@ -1260,6 +1261,45 @@ public async Task CreateChatThreadAsyncShouldExposePartialErrors() Assert.AreEqual("19:e5e7a3fa5f314a01b2d12c6c7b37f433@thread.v2", createChatThreadResult.ChatThread.Id); } + [Test] + public void CreateChatThreadWithThreadRetentionPolicyShouldSucceed() + { + //act + var chatClient = CreateMockChatClient(201, CreateChatThreadSuccessApiResponsePayload); + var chatParticipant = new ChatParticipant(new CommunicationUserIdentifier("8:acs:46849534-eb08-4ab7-bde7-c36928cd1547_00000007-165c-9b10-b0b7-3a3a0d00076c")); + CreateChatThreadResult createChatThreadResult = chatClient.CreateChatThread(new CreateChatThreadOptions("new topic") { RetentionPolicy = new ThreadCreationDateRetentionPolicy(40) }); + + //assert + var chatThread = createChatThreadResult.ChatThread; + Assert.AreEqual("8:acs:46849534-eb08-4ab7-bde7-c36928cd1547_00000007-165c-9b10-b0b7-3a3a0d00076c", CommunicationIdentifierSerializer.Serialize(chatThread.CreatedBy).CommunicationUser.Id); + Assert.AreEqual("Topic for testing success", chatThread.Topic); + Assert.AreEqual("19:e5e7a3fa5f314a01b2d12c6c7b37f433@thread.v2", chatThread.Id); + + var threadCreationDateRetentionPolicy = chatThread.RetentionPolicy as ThreadCreationDateRetentionPolicy; + + Assert.IsNotNull(threadCreationDateRetentionPolicy); + Assert.AreEqual(40, threadCreationDateRetentionPolicy?.DeleteThreadAfterDays); + } + + [Test] + public void CreateChatThreadWithNoneRetentionPolicyShouldSucceed() + { + //act + var chatClient = CreateMockChatClient(201, CreateChatThreadNoneRetentionSuccessApiResponsePayload); + var chatParticipant = new ChatParticipant(new CommunicationUserIdentifier("8:acs:46849534-eb08-4ab7-bde7-c36928cd1547_00000007-165c-9b10-b0b7-3a3a0d00076c")); + CreateChatThreadResult createChatThreadResult = chatClient.CreateChatThread(new CreateChatThreadOptions("new topic") { RetentionPolicy = new NoneRetentionPolicy() }); + + //assert + var chatThread = createChatThreadResult.ChatThread; + Assert.AreEqual("8:acs:46849534-eb08-4ab7-bde7-c36928cd1547_00000007-165c-9b10-b0b7-3a3a0d00076c", CommunicationIdentifierSerializer.Serialize(chatThread.CreatedBy).CommunicationUser.Id); + Assert.AreEqual("Topic for testing success", chatThread.Topic); + Assert.AreEqual("19:e5e7a3fa5f314a01b2d12c6c7b37f433@thread.v2", chatThread.Id); + + var noneRetentionPolicy = chatThread.RetentionPolicy as NoneRetentionPolicy; + + Assert.IsNotNull(noneRetentionPolicy); + } + [Test] public void CreateChatThreadShouldExposePartialErrors() { @@ -1335,7 +1375,7 @@ public void TestMockingModels() Assert.AreEqual(chatError.Details, chatErrorDetails); Assert.AreEqual(chatError.InnerError, innerChatError); - var chatParticipant = ChatModelFactory.ChatParticipant(It.IsAny(), It.IsAny(), It.IsAny()); + var chatParticipant = ChatModelFactory.ChatParticipant(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny>()); Assert.IsNotNull(chatParticipant); var addChatParticipantsResult = ChatModelFactory.AddChatParticipantsResult(It.IsAny>());