/// <summary>Creates a ChatThreadClient synchronously.<see cref="ChatThreadClient"/>.</summary> /// <param name="topic">Topic for the chat thread</param> /// <param name="members">Members to be included in the chat thread</param> /// <param name="cancellationToken">The cancellation token for the task.</param> /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> for details returned from the server.</exception> public virtual ChatThreadClient CreateChatThread(string topic, IEnumerable <ChatThreadMember> members, CancellationToken cancellationToken = default) { using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ChatClient)}.{nameof(CreateChatThread)}"); scope.Start(); try { Response <MultiStatusResponse> threadResponse = _chatRestClient.CreateChatThread(topic, members.Select(x => x.ToChatThreadMemberInternal()), cancellationToken); string threadId = threadResponse.Value.MultipleStatus.First(x => x.Type.ToUpperInvariant() == MultiStatusThreadResourceType).Id; return(new ChatThreadClient(threadId, _endpointUrl, _communicationUserCredential, _chatClientOptions)); } catch (Exception ex) { scope.Failed(ex); throw; } }
/// <summary>Creates a ChatThreadClient synchronously.<see cref="ChatThreadClient"/>.</summary> /// <param name="topic">Topic for the chat thread</param> /// <param name="participants">Participants to be included in the chat thread</param> /// <param name="cancellationToken">The cancellation token for the task.</param> /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> for details returned from the server.</exception> public virtual ChatThreadClient CreateChatThread(string topic, IEnumerable <ChatParticipant> participants, CancellationToken cancellationToken = default) { using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ChatClient)}.{nameof(CreateChatThread)}"); scope.Start(); try { Response <ChatThreadInternal> threadResponse = _chatRestClient.CreateChatThread(topic, participants.Select(x => x.ToChatParticipantInternal()), cancellationToken); string threadId = threadId = threadResponse.Value.Id; return(new ChatThreadClient(threadId, _endpointUrl, _communicationUserCredential, _chatClientOptions)); } catch (Exception ex) { scope.Failed(ex); throw; } }
/// <summary>Creates a ChatThreadClient synchronously.<see cref="ChatThreadClient"/>.</summary> /// <param name="topic">Topic for the chat thread</param> /// <param name="participants">Participants to be included in the chat thread</param> /// <param name="idempotencyToken"> 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. </param> /// <param name="cancellationToken">The cancellation token for the task.</param> /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> for details returned from the server.</exception> public virtual Response <CreateChatThreadResult> CreateChatThread(string topic, IEnumerable <ChatParticipant> participants, string idempotencyToken = null, CancellationToken cancellationToken = default) { using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ChatClient)}.{nameof(CreateChatThread)}"); scope.Start(); try { idempotencyToken ??= Guid.NewGuid().ToString(); Response <CreateChatThreadResultInternal> createChatThreadResultInternal = _chatRestClient.CreateChatThread(topic, idempotencyToken, participants.Select(x => x.ToChatParticipantInternal()), cancellationToken); return(Response.FromValue(new CreateChatThreadResult(createChatThreadResultInternal.Value), createChatThreadResultInternal.GetRawResponse())); } catch (Exception ex) { scope.Failed(ex); throw; } }