コード例 #1
0
        public virtual async Task <ChatThreadClient> CreateChatThreadAsync(string topic, IEnumerable <ChatThreadMember> members, CancellationToken cancellationToken = default)
        {
            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ChatClient)}.{nameof(CreateChatThread)}");
            scope.Start();
            try
            {
                Response <MultiStatusResponse> threadResponse = await _chatRestClient.CreateChatThreadAsync(topic, members.Select(x => x.ToChatThreadMemberInternal()), cancellationToken).ConfigureAwait(false);

                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;
            }
        }
コード例 #2
0
        public virtual async Task <ChatThreadClient> CreateChatThreadAsync(string topic, IEnumerable <ChatParticipant> participants, CancellationToken cancellationToken = default)
        {
            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ChatClient)}.{nameof(CreateChatThread)}");
            scope.Start();
            try
            {
                Response <ChatThreadInternal> threadResponse = await _chatRestClient.CreateChatThreadAsync(topic, participants.Select(x => x.ToChatParticipantInternal()), cancellationToken).ConfigureAwait(false);

                string threadId = threadResponse.Value.Id;
                return(new ChatThreadClient(threadId, _endpointUrl, _communicationUserCredential, _chatClientOptions));
            }
            catch (Exception ex)
            {
                scope.Failed(ex);
                throw;
            }
        }
コード例 #3
0
        /// <summary>Creates a ChatThreadClient asynchronously. <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 async Task <Response <CreateChatThreadResult> > CreateChatThreadAsync(string topic, IEnumerable <ChatParticipant> participants = null, 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 = await _chatRestClient.CreateChatThreadAsync(topic, idempotencyToken, participants.Select(x => x.ToChatParticipantInternal()), cancellationToken).ConfigureAwait(false);

                return(Response.FromValue(new CreateChatThreadResult(createChatThreadResultInternal.Value), createChatThreadResultInternal.GetRawResponse()));
            }
            catch (Exception ex)
            {
                scope.Failed(ex);
                throw;
            }
        }