/// <summary> Sends a message to a thread. </summary> /// <param name="content"> Message content. </param> /// <param name="type"> The chat message type. </param> /// <param name="senderDisplayName"> The display name of the message sender. This property is used to populate sender name for push notifications. </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 <string> SendMessage(string content, ChatMessageType?type = null, string?senderDisplayName = null, CancellationToken cancellationToken = default) { using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ChatThreadClient)}.{nameof(SendMessage)}"); scope.Start(); try { Response <SendChatMessageResult> sendChatMessageResult = _chatThreadRestClient.SendChatMessage(Id, content, senderDisplayName, type, cancellationToken); return(Response.FromValue(sendChatMessageResult.Value.Id, sendChatMessageResult.GetRawResponse())); } catch (Exception ex) { scope.Failed(ex); throw; } }
/// <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, 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) { scope.Failed(ex); throw; } }