Class ChatAsyncClient

java.lang.Object
com.azure.communication.chat.ChatAsyncClient

public final class ChatAsyncClient extends Object
Async Client that supports chat operations.

Instantiating an asynchronous Chat Client


 // Initialize the chat client builder
 final ChatClientBuilder builder = new ChatClientBuilder()
     .endpoint(endpoint)
     .credential(credential);

 // Build the chat client
 ChatAsyncClient chatClient = builder.buildAsyncClient();

 

View this for additional ways to construct the client.

See Also:
  • Method Details

    • getChatThreadClient

      public ChatThreadAsyncClient getChatThreadClient(String chatThreadId)
      Creates a chat thread client.
      Parameters:
      chatThreadId - The id of the thread.
      Returns:
      the client.
    • createChatThread

      public Mono<CreateChatThreadResult> createChatThread(CreateChatThreadOptions options)
      Creates a chat thread.

      Code Samples

      Create a chat thread based on "options".

      
       // Initialize the list of chat thread participants
       List<ChatParticipant> participants = new ArrayList<ChatParticipant>();
      
       ChatParticipant firstParticipant = new ChatParticipant()
           .setCommunicationIdentifier(user1)
           .setDisplayName("Participant Display Name 1");
      
       ChatParticipant secondParticipant = new ChatParticipant()
           .setCommunicationIdentifier(user2)
           .setDisplayName("Participant Display Name 2");
      
       participants.add(firstParticipant);
       participants.add(secondParticipant);
      
       // Create the chat thread
       CreateChatThreadOptions createChatThreadOptions = new CreateChatThreadOptions("Topic")
           .setParticipants(participants);
       CreateChatThreadResult result = chatClient.createChatThread(createChatThreadOptions).block();
      
       // Retrieve the chat thread and the id
       ChatThreadProperties chatThread = result.getChatThread();
       String chatThreadId = chatThread.getId();
      
       
      Parameters:
      options - Options for creating a chat thread.
      Returns:
      the response.
      Throws:
      ChatErrorResponseException - thrown if the request is rejected by server.
      RuntimeException - all other wrapped checked exceptions if the request fails to be sent.
    • createChatThreadWithResponse

      public Mono<Response<CreateChatThreadResult>> createChatThreadWithResponse(CreateChatThreadOptions options)
      Creates a chat thread.
      Parameters:
      options - Options for creating a chat thread.
      Returns:
      the response.
      Throws:
      ChatErrorResponseException - thrown if the request is rejected by server.
      RuntimeException - all other wrapped checked exceptions if the request fails to be sent.
    • listChatThreads

      public PagedFlux<ChatThreadItem> listChatThreads()
      Gets the list of chat threads of a user.
      Returns:
      the paged list of chat threads of a user.
      Throws:
      ChatErrorResponseException - thrown if the request is rejected by server.
      RuntimeException - all other wrapped checked exceptions if the request fails to be sent.
    • listChatThreads

      public PagedFlux<ChatThreadItem> listChatThreads(ListChatThreadsOptions listThreadsOptions)
      Gets the list of chat threads of a user.
      Parameters:
      listThreadsOptions - The request options.
      Returns:
      the paged list of chat threads of a user.
      Throws:
      ChatErrorResponseException - thrown if the request is rejected by server.
      RuntimeException - all other wrapped checked exceptions if the request fails to be sent.
    • deleteChatThread

      public Mono<Void> deleteChatThread(String chatThreadId)
      Deletes a chat thread.
      Parameters:
      chatThreadId - Chat thread id to delete.
      Returns:
      the completion.
      Throws:
      ChatErrorResponseException - thrown if the request is rejected by server.
      RuntimeException - all other wrapped checked exceptions if the request fails to be sent.
    • deleteChatThreadWithResponse

      public Mono<Response<Void>> deleteChatThreadWithResponse(String chatThreadId)
      Deletes a chat thread.
      Parameters:
      chatThreadId - Chat thread id to delete.
      Returns:
      the completion.
      Throws:
      ChatErrorResponseException - thrown if the request is rejected by server.
      RuntimeException - all other wrapped checked exceptions if the request fails to be sent.