Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for message metadata. #21097

Merged
merged 3 commits into from
May 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
619 changes: 403 additions & 216 deletions eng/CodeAnalysis.ruleset

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions sdk/communication/Azure.Communication.Chat/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Release History

## 1.1.0-beta.1 (Unreleased)
### Added
- Added support for metadata in messages.
- Added new overloads for sendmessage and updatemessage operations with options : SendChatMessageOptions and UpdateChatMessageOptions.


## 1.0.1 (2021-05-11)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ 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.V2021_03_07) { }
public ChatClientOptions(Azure.Communication.Chat.ChatClientOptions.ServiceVersion version = Azure.Communication.Chat.ChatClientOptions.ServiceVersion.V2021_04_05_preview6) { }
public enum ServiceVersion
{
V2021_03_07 = 1,
V2021_04_05_preview6 = 2,
}
}
public partial class ChatError
Expand All @@ -42,6 +43,7 @@ internal ChatMessage() { }
public System.DateTimeOffset? DeletedOn { get { throw null; } }
public System.DateTimeOffset? EditedOn { get { throw null; } }
public string Id { get { throw null; } }
public System.Collections.Generic.IReadOnlyDictionary<string, string> Metadata { get { throw null; } }
public Azure.Communication.CommunicationIdentifier Sender { get { throw null; } }
public string SenderDisplayName { get { throw null; } }
public string SequenceId { get { throw null; } }
Expand Down Expand Up @@ -89,6 +91,8 @@ public static partial class ChatModelFactory
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public static Azure.Communication.Chat.ChatMessage ChatMessage(string id, Azure.Communication.Chat.ChatMessageType type, string sequenceId, string version, Azure.Communication.Chat.ChatMessageContent content, string senderDisplayName, System.DateTimeOffset createdOn, string senderId, System.DateTimeOffset? deletedOn, System.DateTimeOffset? editedOn) { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public static Azure.Communication.Chat.ChatMessage ChatMessage(string id, Azure.Communication.Chat.ChatMessageType type, string sequenceId, string version, Azure.Communication.Chat.ChatMessageContent content, string senderDisplayName, System.DateTimeOffset createdOn, string senderId, System.DateTimeOffset? deletedOn, System.DateTimeOffset? editedOn, System.Collections.Generic.IReadOnlyDictionary<string, string> metadata) { throw null; }
[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; }
[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; }
Expand Down Expand Up @@ -123,13 +127,17 @@ public ChatThreadClient(string threadId, System.Uri endpoint, Azure.Communicatio
public virtual Azure.AsyncPageable<Azure.Communication.Chat.ChatMessageReadReceipt> GetReadReceiptsAsync(int? skip = default(int?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response RemoveParticipant(Azure.Communication.CommunicationIdentifier identifier, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response> RemoveParticipantAsync(Azure.Communication.CommunicationIdentifier identifier, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response<Azure.Communication.Chat.SendChatMessageResult> SendMessage(Azure.Communication.Chat.SendChatMessageOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response<Azure.Communication.Chat.SendChatMessageResult> SendMessage(string content, Azure.Communication.Chat.ChatMessageType type = default(Azure.Communication.Chat.ChatMessageType), string senderDisplayName = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Communication.Chat.SendChatMessageResult>> SendMessageAsync(Azure.Communication.Chat.SendChatMessageOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Communication.Chat.SendChatMessageResult>> SendMessageAsync(string content, Azure.Communication.Chat.ChatMessageType type = default(Azure.Communication.Chat.ChatMessageType), string senderDisplayName = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response SendReadReceipt(string messageId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response> SendReadReceiptAsync(string messageId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response SendTypingNotification(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response> SendTypingNotificationAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response UpdateMessage(Azure.Communication.Chat.UpdateChatMessageOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
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<Azure.Response> UpdateMessageAsync(Azure.Communication.Chat.UpdateChatMessageOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response> UpdateMessageAsync(string messageId, string content, 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<Azure.Response> UpdateTopicAsync(string topic, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
Expand Down Expand Up @@ -157,9 +165,24 @@ internal CreateChatThreadResult() { }
public Azure.Communication.Chat.ChatThreadProperties ChatThread { get { throw null; } }
public System.Collections.Generic.IReadOnlyList<Azure.Communication.Chat.ChatError> InvalidParticipants { get { throw null; } }
}
public partial class SendChatMessageOptions
{
public SendChatMessageOptions() { }
public string Content { get { throw null; } set { } }
public Azure.Communication.Chat.ChatMessageType MessageType { get { throw null; } set { } }
public System.Collections.Generic.IDictionary<string, string> Metadata { get { throw null; } }
public string SenderDisplayName { get { throw null; } set { } }
}
public partial class SendChatMessageResult
{
internal SendChatMessageResult() { }
public string Id { get { throw null; } }
}
public partial class UpdateChatMessageOptions
{
public UpdateChatMessageOptions() { }
public string Content { get { throw null; } set { } }
public string MessageId { get { throw null; } set { } }
public System.Collections.Generic.IDictionary<string, string> Metadata { get { throw null; } }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class ChatClientOptions : ClientOptions
/// <summary>
/// The latest version of the Chat service.
/// </summary>
internal const ServiceVersion LatestVersion = ServiceVersion.V2021_03_07;
internal const ServiceVersion LatestVersion = ServiceVersion.V2021_04_05_preview6;

internal string ApiVersion { get; }

Expand All @@ -25,7 +25,7 @@ public ChatClientOptions(ServiceVersion version = LatestVersion)
{
ApiVersion = version switch
{
ServiceVersion.V2021_03_07 => "2021-03-07",
ServiceVersion.V2021_04_05_preview6 => "2021-04-05-preview6",
_ => throw new ArgumentOutOfRangeException(nameof(version)),
};
}
Expand All @@ -39,7 +39,11 @@ public enum ServiceVersion
/// The V1 of the Chat service.
/// </summary>
#pragma warning disable CA1707 // Identifiers should not contain underscores
V2021_03_07 = 1
V2021_03_07 = 1,
/// <summary>
/// The V2021_04_05_preview6 of the Chat service.
/// </summary>
V2021_04_05_preview6 = 2,
#pragma warning restore CA1707 // Identifiers should not contain underscores

}
Expand Down
46 changes: 41 additions & 5 deletions sdk/communication/Azure.Communication.Chat/src/ChatThreadClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,22 @@ public virtual Response<ChatThreadProperties> GetProperties(CancellationToken ca
/// <param name="cancellationToken"> The cancellation token to use. </param>
/// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> for details returned from the server.</exception>
public virtual async Task<Response<SendChatMessageResult>> SendMessageAsync(string content, ChatMessageType type = default, string senderDisplayName = null, CancellationToken cancellationToken = default)
{
return await SendMessageAsync(new SendChatMessageOptions { Content = content, MessageType = type, SenderDisplayName = senderDisplayName }, cancellationToken).ConfigureAwait(false);
}

/// <summary> Sends a message to a thread asynchronously. </summary>
/// <param name="options"> Options for the message. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
/// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> for details returned from the server.</exception>
public virtual async Task<Response<SendChatMessageResult>> SendMessageAsync(SendChatMessageOptions options, CancellationToken cancellationToken = default)
{
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ChatThreadClient)}.{nameof(SendMessage)}");
scope.Start();
try
{
Response<SendChatMessageResultInternal> sendChatMessageResultInternal = await _chatThreadRestClient.SendChatMessageAsync(Id, content, senderDisplayName, type, cancellationToken).ConfigureAwait(false);
Response<SendChatMessageResultInternal> sendChatMessageResultInternal =
await _chatThreadRestClient.SendChatMessageAsync(Id, options.Content, options.SenderDisplayName, options.MessageType, options.Metadata ?? new Dictionary<string, string>(), cancellationToken).ConfigureAwait(false);
return Response.FromValue(new SendChatMessageResult(sendChatMessageResultInternal.Value), sendChatMessageResultInternal.GetRawResponse());
}
catch (Exception ex)
Expand All @@ -160,12 +170,20 @@ public virtual async Task<Response<SendChatMessageResult>> SendMessageAsync(stri
/// <param name="cancellationToken"> The cancellation token to use. </param>
/// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> for details returned from the server.</exception>
public virtual Response<SendChatMessageResult> SendMessage(string content, ChatMessageType type = default, string senderDisplayName = null, CancellationToken cancellationToken = default)
=> SendMessage(new SendChatMessageOptions { Content = content, MessageType = type, SenderDisplayName = senderDisplayName }, cancellationToken);

/// <summary> Sends a message to a thread. </summary>
/// <param name="options">Options for the message. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
/// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> for details returned from the server.</exception>
public virtual Response<SendChatMessageResult> SendMessage(SendChatMessageOptions options, CancellationToken cancellationToken = default)
{
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ChatThreadClient)}.{nameof(SendMessage)}");
scope.Start();
try
{
Response<SendChatMessageResultInternal> sendChatMessageResultInternal = _chatThreadRestClient.SendChatMessage(Id, content, senderDisplayName, type, cancellationToken);
Response<SendChatMessageResultInternal> sendChatMessageResultInternal =
_chatThreadRestClient.SendChatMessage(Id, options.Content, options.SenderDisplayName, options.MessageType, options.Metadata ?? new Dictionary<string, string>(), cancellationToken);
return Response.FromValue(new SendChatMessageResult(sendChatMessageResultInternal.Value), sendChatMessageResultInternal.GetRawResponse());
}
catch (Exception ex)
Expand Down Expand Up @@ -305,12 +323,21 @@ Page<ChatMessage> NextPageFunc(string nextLink, int? pageSizeHint)
/// <param name="cancellationToken"> The cancellation token to use. </param>
/// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> for details returned from the server.</exception>
public virtual async Task<Response> UpdateMessageAsync(string messageId, string content, CancellationToken cancellationToken = default)
{
return await UpdateMessageAsync(new UpdateChatMessageOptions { MessageId = messageId, Content = content }, cancellationToken).ConfigureAwait(false);
}

/// <summary> Updates a message asynchronously. </summary>
/// <param name="options"> Options for the message. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
/// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> for details returned from the server.</exception>
public virtual async Task<Response> UpdateMessageAsync(UpdateChatMessageOptions options, CancellationToken cancellationToken = default)
{
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ChatThreadClient)}.{nameof(UpdateMessage)}");
scope.Start();
try
{
return await _chatThreadRestClient.UpdateChatMessageAsync(Id, messageId, content, cancellationToken).ConfigureAwait(false);
return await _chatThreadRestClient.UpdateChatMessageAsync(Id, options.MessageId, options.Content, options.Metadata ?? new Dictionary<string, string>(), cancellationToken).ConfigureAwait(false);
}
catch (Exception ex)
{
Expand All @@ -319,18 +346,27 @@ public virtual async Task<Response> UpdateMessageAsync(string messageId, string
}
}

/// <summary> Updates a message asynchronously. </summary>
/// <summary> Updates a message synchronously. </summary>
/// <param name="messageId"> The message id. </param>
/// <param name="content"> Chat message content. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
/// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> for details returned from the server.</exception>
public virtual Response UpdateMessage(string messageId, string content, CancellationToken cancellationToken = default)
{
return UpdateMessage(new UpdateChatMessageOptions { MessageId = messageId, Content = content }, cancellationToken);
}

/// <summary> Updates a message synchronously. </summary>
/// <param name="options"> Options for the message. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
/// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> for details returned from the server.</exception>
public virtual Response UpdateMessage(UpdateChatMessageOptions options, CancellationToken cancellationToken = default)
{
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ChatThreadClient)}.{nameof(UpdateMessage)}");
scope.Start();
try
{
return _chatThreadRestClient.UpdateChatMessage(Id, messageId, content, cancellationToken);
return _chatThreadRestClient.UpdateChatMessage(Id, options.MessageId, options.Content, options.Metadata ?? new Dictionary<string, string>(), cancellationToken);
}
catch (Exception ex)
{
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading