private static HttpPipeline CreatePipelineFromOptions(ChatClientOptions options, CommunicationTokenCredential communicationTokenCredential)
        {
            var bearerTokenCredential = new CommunicationBearerTokenCredential(communicationTokenCredential);
            var authenticationPolicy  = new BearerTokenAuthenticationPolicy(bearerTokenCredential, "");

            return(HttpPipelineBuilder.Build(options, authenticationPolicy));
        }
Exemplo n.º 2
0
        private static HttpPipeline CreatePipelineFromOptions(ChatClientOptions options, CommunicationUserCredential communicationUserCredential)
        {
            var          httpPipelinePolicy = new CommunicationUserAuthenticationPolicy(communicationUserCredential);
            HttpPipeline httpPipeline       = HttpPipelineBuilder.Build(options, httpPipelinePolicy);

            return(httpPipeline);
        }
Exemplo n.º 3
0
 /// <summary>Initializes a new instance of <see cref="ChatClient"/> for mocking.</summary>
 protected ChatClient()
 {
     _clientDiagnostics           = null !;
     _chatRestClient              = null !;
     _endpointUrl                 = null !;
     _communicationUserCredential = null !;
     _chatClientOptions           = null !;
 }
Exemplo n.º 4
0
        /// <summary> Initializes a new instance of <see cref="ChatClient"/>.</summary>
        /// <param name="endpointUrl">The uri for the Azure Communication Services Chat.</param>
        /// <param name="communicationUserCredential">Instance of <see cref="CommunicationUserCredential"/>.</param>
        /// <param name="options">Chat client options exposing <see cref="ClientOptions.Diagnostics"/>, <see cref="ClientOptions.Retry"/>, <see cref="ClientOptions.Transport"/>, etc.</param>
        public ChatClient(Uri endpointUrl, CommunicationUserCredential communicationUserCredential, ChatClientOptions?options = default)
        {
            Argument.AssertNotNull(communicationUserCredential, nameof(communicationUserCredential));
            Argument.AssertNotNull(endpointUrl, nameof(endpointUrl));
            _chatClientOptions           = options ?? new ChatClientOptions();
            _communicationUserCredential = communicationUserCredential;
            _endpointUrl       = endpointUrl;
            _clientDiagnostics = new ClientDiagnostics(_chatClientOptions);
            HttpPipeline pipeline = CreatePipelineFromOptions(_chatClientOptions, communicationUserCredential);

            _chatRestClient = new ChatRestClient(_clientDiagnostics, pipeline, endpointUrl.AbsoluteUri, _chatClientOptions.ApiVersion);
        }
        /// <summary> Initializes a new instance of <see cref="ChatThreadClient"/>.</summary>
        /// <param name="threadId"></param>
        /// <param name="endpoint">The uri for the Azure Communication Services Chat.</param>
        /// <param name="communicationTokenCredential">Instance of <see cref="CommunicationTokenCredential"/>.</param>
        /// <param name="options">Chat client options exposing <see cref="ClientOptions.Diagnostics"/>, <see cref="ClientOptions.Retry"/>, <see cref="ClientOptions.Transport"/>, etc.</param>
        /// <exception cref="ArgumentNullException"> This occurs when one of the required arguments is null. </exception>

        public ChatThreadClient(string threadId, Uri endpoint, CommunicationTokenCredential communicationTokenCredential, ChatClientOptions options = default)
        {
            Argument.AssertNotNull(threadId, nameof(threadId));
            Argument.AssertNotNull(communicationTokenCredential, nameof(communicationTokenCredential));
            Argument.AssertNotNull(endpoint, nameof(endpoint));
            options ??= new ChatClientOptions();
            Id = threadId;
            _clientDiagnostics = new ClientDiagnostics(options);
            HttpPipeline pipeline = CreatePipelineFromOptions(options, communicationTokenCredential);

            _chatThreadRestClient = new ChatThreadRestClient(_clientDiagnostics, pipeline, endpoint.AbsoluteUri, options.ApiVersion);
        }