Skip to content

Commit 43d3823

Browse files
juancamilorCamilo Ramirez
andauthored
Added support for message metadata. (Azure#21097)
Co-authored-by: Camilo Ramirez <juramir@microsoft.com>
1 parent cc8b418 commit 43d3823

26 files changed

+3797
-6686
lines changed

eng/CodeAnalysis.ruleset

Lines changed: 403 additions & 216 deletions
Large diffs are not rendered by default.

sdk/communication/Azure.Communication.Chat/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Release History
22

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

58

69
## 1.0.1 (2021-05-11)

sdk/communication/Azure.Communication.Chat/api/Azure.Communication.Chat.netstandard2.0.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ public ChatClient(System.Uri endpoint, Azure.Communication.CommunicationTokenCre
1919
}
2020
public partial class ChatClientOptions : Azure.Core.ClientOptions
2121
{
22-
public ChatClientOptions(Azure.Communication.Chat.ChatClientOptions.ServiceVersion version = Azure.Communication.Chat.ChatClientOptions.ServiceVersion.V2021_03_07) { }
22+
public ChatClientOptions(Azure.Communication.Chat.ChatClientOptions.ServiceVersion version = Azure.Communication.Chat.ChatClientOptions.ServiceVersion.V2021_04_05_preview6) { }
2323
public enum ServiceVersion
2424
{
2525
V2021_03_07 = 1,
26+
V2021_04_05_preview6 = 2,
2627
}
2728
}
2829
public partial class ChatError
@@ -42,6 +43,7 @@ internal ChatMessage() { }
4243
public System.DateTimeOffset? DeletedOn { get { throw null; } }
4344
public System.DateTimeOffset? EditedOn { get { throw null; } }
4445
public string Id { get { throw null; } }
46+
public System.Collections.Generic.IReadOnlyDictionary<string, string> Metadata { get { throw null; } }
4547
public Azure.Communication.CommunicationIdentifier Sender { get { throw null; } }
4648
public string SenderDisplayName { get { throw null; } }
4749
public string SequenceId { get { throw null; } }
@@ -89,6 +91,8 @@ public static partial class ChatModelFactory
8991
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
9092
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; }
9193
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
94+
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; }
95+
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
9296
public static Azure.Communication.Chat.ChatMessageReadReceipt ChatMessageReadReceipt(Azure.Communication.CommunicationIdentifier sender, string chatMessageId, System.DateTimeOffset readOn) { throw null; }
9397
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
9498
public static Azure.Communication.Chat.ChatThreadItem ChatThreadItem(string id, string topic, System.DateTimeOffset? deletedOn, System.DateTimeOffset? lastMessageReceivedOn) { throw null; }
@@ -123,13 +127,17 @@ public ChatThreadClient(string threadId, System.Uri endpoint, Azure.Communicatio
123127
public virtual Azure.AsyncPageable<Azure.Communication.Chat.ChatMessageReadReceipt> GetReadReceiptsAsync(int? skip = default(int?), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
124128
public virtual Azure.Response RemoveParticipant(Azure.Communication.CommunicationIdentifier identifier, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
125129
public virtual System.Threading.Tasks.Task<Azure.Response> RemoveParticipantAsync(Azure.Communication.CommunicationIdentifier identifier, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
130+
public virtual Azure.Response<Azure.Communication.Chat.SendChatMessageResult> SendMessage(Azure.Communication.Chat.SendChatMessageOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
126131
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; }
132+
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; }
127133
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; }
128134
public virtual Azure.Response SendReadReceipt(string messageId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
129135
public virtual System.Threading.Tasks.Task<Azure.Response> SendReadReceiptAsync(string messageId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
130136
public virtual Azure.Response SendTypingNotification(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
131137
public virtual System.Threading.Tasks.Task<Azure.Response> SendTypingNotificationAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
138+
public virtual Azure.Response UpdateMessage(Azure.Communication.Chat.UpdateChatMessageOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
132139
public virtual Azure.Response UpdateMessage(string messageId, string content, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
140+
public virtual System.Threading.Tasks.Task<Azure.Response> UpdateMessageAsync(Azure.Communication.Chat.UpdateChatMessageOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
133141
public virtual System.Threading.Tasks.Task<Azure.Response> UpdateMessageAsync(string messageId, string content, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
134142
public virtual Azure.Response UpdateTopic(string topic, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
135143
public virtual System.Threading.Tasks.Task<Azure.Response> UpdateTopicAsync(string topic, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
@@ -157,9 +165,24 @@ internal CreateChatThreadResult() { }
157165
public Azure.Communication.Chat.ChatThreadProperties ChatThread { get { throw null; } }
158166
public System.Collections.Generic.IReadOnlyList<Azure.Communication.Chat.ChatError> InvalidParticipants { get { throw null; } }
159167
}
168+
public partial class SendChatMessageOptions
169+
{
170+
public SendChatMessageOptions() { }
171+
public string Content { get { throw null; } set { } }
172+
public Azure.Communication.Chat.ChatMessageType MessageType { get { throw null; } set { } }
173+
public System.Collections.Generic.IDictionary<string, string> Metadata { get { throw null; } }
174+
public string SenderDisplayName { get { throw null; } set { } }
175+
}
160176
public partial class SendChatMessageResult
161177
{
162178
internal SendChatMessageResult() { }
163179
public string Id { get { throw null; } }
164180
}
181+
public partial class UpdateChatMessageOptions
182+
{
183+
public UpdateChatMessageOptions() { }
184+
public string Content { get { throw null; } set { } }
185+
public string MessageId { get { throw null; } set { } }
186+
public System.Collections.Generic.IDictionary<string, string> Metadata { get { throw null; } }
187+
}
165188
}

sdk/communication/Azure.Communication.Chat/src/ChatClientOptions.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class ChatClientOptions : ClientOptions
1414
/// <summary>
1515
/// The latest version of the Chat service.
1616
/// </summary>
17-
internal const ServiceVersion LatestVersion = ServiceVersion.V2021_03_07;
17+
internal const ServiceVersion LatestVersion = ServiceVersion.V2021_04_05_preview6;
1818

1919
internal string ApiVersion { get; }
2020

@@ -25,7 +25,7 @@ public ChatClientOptions(ServiceVersion version = LatestVersion)
2525
{
2626
ApiVersion = version switch
2727
{
28-
ServiceVersion.V2021_03_07 => "2021-03-07",
28+
ServiceVersion.V2021_04_05_preview6 => "2021-04-05-preview6",
2929
_ => throw new ArgumentOutOfRangeException(nameof(version)),
3030
};
3131
}
@@ -39,7 +39,11 @@ public enum ServiceVersion
3939
/// The V1 of the Chat service.
4040
/// </summary>
4141
#pragma warning disable CA1707 // Identifiers should not contain underscores
42-
V2021_03_07 = 1
42+
V2021_03_07 = 1,
43+
/// <summary>
44+
/// The V2021_04_05_preview6 of the Chat service.
45+
/// </summary>
46+
V2021_04_05_preview6 = 2,
4347
#pragma warning restore CA1707 // Identifiers should not contain underscores
4448

4549
}

sdk/communication/Azure.Communication.Chat/src/ChatThreadClient.cs

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,22 @@ public virtual Response<ChatThreadProperties> GetProperties(CancellationToken ca
138138
/// <param name="cancellationToken"> The cancellation token to use. </param>
139139
/// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> for details returned from the server.</exception>
140140
public virtual async Task<Response<SendChatMessageResult>> SendMessageAsync(string content, ChatMessageType type = default, string senderDisplayName = null, CancellationToken cancellationToken = default)
141+
{
142+
return await SendMessageAsync(new SendChatMessageOptions { Content = content, MessageType = type, SenderDisplayName = senderDisplayName }, cancellationToken).ConfigureAwait(false);
143+
}
144+
145+
/// <summary> Sends a message to a thread asynchronously. </summary>
146+
/// <param name="options"> Options for the message. </param>
147+
/// <param name="cancellationToken"> The cancellation token to use. </param>
148+
/// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> for details returned from the server.</exception>
149+
public virtual async Task<Response<SendChatMessageResult>> SendMessageAsync(SendChatMessageOptions options, CancellationToken cancellationToken = default)
141150
{
142151
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ChatThreadClient)}.{nameof(SendMessage)}");
143152
scope.Start();
144153
try
145154
{
146-
Response<SendChatMessageResultInternal> sendChatMessageResultInternal = await _chatThreadRestClient.SendChatMessageAsync(Id, content, senderDisplayName, type, cancellationToken).ConfigureAwait(false);
155+
Response<SendChatMessageResultInternal> sendChatMessageResultInternal =
156+
await _chatThreadRestClient.SendChatMessageAsync(Id, options.Content, options.SenderDisplayName, options.MessageType, options.Metadata ?? new Dictionary<string, string>(), cancellationToken).ConfigureAwait(false);
147157
return Response.FromValue(new SendChatMessageResult(sendChatMessageResultInternal.Value), sendChatMessageResultInternal.GetRawResponse());
148158
}
149159
catch (Exception ex)
@@ -160,12 +170,20 @@ public virtual async Task<Response<SendChatMessageResult>> SendMessageAsync(stri
160170
/// <param name="cancellationToken"> The cancellation token to use. </param>
161171
/// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> for details returned from the server.</exception>
162172
public virtual Response<SendChatMessageResult> SendMessage(string content, ChatMessageType type = default, string senderDisplayName = null, CancellationToken cancellationToken = default)
173+
=> SendMessage(new SendChatMessageOptions { Content = content, MessageType = type, SenderDisplayName = senderDisplayName }, cancellationToken);
174+
175+
/// <summary> Sends a message to a thread. </summary>
176+
/// <param name="options">Options for the message. </param>
177+
/// <param name="cancellationToken"> The cancellation token to use. </param>
178+
/// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> for details returned from the server.</exception>
179+
public virtual Response<SendChatMessageResult> SendMessage(SendChatMessageOptions options, CancellationToken cancellationToken = default)
163180
{
164181
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ChatThreadClient)}.{nameof(SendMessage)}");
165182
scope.Start();
166183
try
167184
{
168-
Response<SendChatMessageResultInternal> sendChatMessageResultInternal = _chatThreadRestClient.SendChatMessage(Id, content, senderDisplayName, type, cancellationToken);
185+
Response<SendChatMessageResultInternal> sendChatMessageResultInternal =
186+
_chatThreadRestClient.SendChatMessage(Id, options.Content, options.SenderDisplayName, options.MessageType, options.Metadata ?? new Dictionary<string, string>(), cancellationToken);
169187
return Response.FromValue(new SendChatMessageResult(sendChatMessageResultInternal.Value), sendChatMessageResultInternal.GetRawResponse());
170188
}
171189
catch (Exception ex)
@@ -305,12 +323,21 @@ Page<ChatMessage> NextPageFunc(string nextLink, int? pageSizeHint)
305323
/// <param name="cancellationToken"> The cancellation token to use. </param>
306324
/// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> for details returned from the server.</exception>
307325
public virtual async Task<Response> UpdateMessageAsync(string messageId, string content, CancellationToken cancellationToken = default)
326+
{
327+
return await UpdateMessageAsync(new UpdateChatMessageOptions { MessageId = messageId, Content = content }, cancellationToken).ConfigureAwait(false);
328+
}
329+
330+
/// <summary> Updates a message asynchronously. </summary>
331+
/// <param name="options"> Options for the message. </param>
332+
/// <param name="cancellationToken"> The cancellation token to use. </param>
333+
/// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> for details returned from the server.</exception>
334+
public virtual async Task<Response> UpdateMessageAsync(UpdateChatMessageOptions options, CancellationToken cancellationToken = default)
308335
{
309336
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ChatThreadClient)}.{nameof(UpdateMessage)}");
310337
scope.Start();
311338
try
312339
{
313-
return await _chatThreadRestClient.UpdateChatMessageAsync(Id, messageId, content, cancellationToken).ConfigureAwait(false);
340+
return await _chatThreadRestClient.UpdateChatMessageAsync(Id, options.MessageId, options.Content, options.Metadata ?? new Dictionary<string, string>(), cancellationToken).ConfigureAwait(false);
314341
}
315342
catch (Exception ex)
316343
{
@@ -319,18 +346,27 @@ public virtual async Task<Response> UpdateMessageAsync(string messageId, string
319346
}
320347
}
321348

322-
/// <summary> Updates a message asynchronously. </summary>
349+
/// <summary> Updates a message synchronously. </summary>
323350
/// <param name="messageId"> The message id. </param>
324351
/// <param name="content"> Chat message content. </param>
325352
/// <param name="cancellationToken"> The cancellation token to use. </param>
326353
/// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> for details returned from the server.</exception>
327354
public virtual Response UpdateMessage(string messageId, string content, CancellationToken cancellationToken = default)
355+
{
356+
return UpdateMessage(new UpdateChatMessageOptions { MessageId = messageId, Content = content }, cancellationToken);
357+
}
358+
359+
/// <summary> Updates a message synchronously. </summary>
360+
/// <param name="options"> Options for the message. </param>
361+
/// <param name="cancellationToken"> The cancellation token to use. </param>
362+
/// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> for details returned from the server.</exception>
363+
public virtual Response UpdateMessage(UpdateChatMessageOptions options, CancellationToken cancellationToken = default)
328364
{
329365
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ChatThreadClient)}.{nameof(UpdateMessage)}");
330366
scope.Start();
331367
try
332368
{
333-
return _chatThreadRestClient.UpdateChatMessage(Id, messageId, content, cancellationToken);
369+
return _chatThreadRestClient.UpdateChatMessage(Id, options.MessageId, options.Content, options.Metadata ?? new Dictionary<string, string>(), cancellationToken);
334370
}
335371
catch (Exception ex)
336372
{

sdk/communication/Azure.Communication.Chat/src/Generated/ChatRestClient.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)