Package com.azure.communication.chat
Class ChatClient
java.lang.Object
com.azure.communication.chat.ChatClient
Sync Client that supports chat operations.
Instantiating a synchronous Chat Client
// Initialize the chat client builder final ChatClientBuilder builder = new ChatClientBuilder() .endpoint(endpoint) .credential(credential); // Build the chat client ChatClient chatClient = builder.buildClient();
View this
for additional ways to construct the client.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptioncreateChatThread
(CreateChatThreadOptions options) Creates a chat thread.createChatThreadWithResponse
(CreateChatThreadOptions options, Context context) Creates a chat thread.void
deleteChatThread
(String chatThreadId) Deletes a chat thread.deleteChatThreadWithResponse
(String chatThreadId, Context context) Deletes a chat thread.getChatThreadClient
(String chatThreadId) Creates a chat thread client.Gets the list of chat threads of a user.listChatThreads
(ListChatThreadsOptions listThreadsOptions, Context context) Gets the list of chat threads of a user.
-
Method Details
-
getChatThreadClient
Creates a chat thread client.- Parameters:
chatThreadId
- The id of the chat thread.- Returns:
- the client.
-
createChatThread
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); // 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 Response<CreateChatThreadResult> createChatThreadWithResponse(CreateChatThreadOptions options, Context context) Creates a chat thread.- Parameters:
options
- Options for creating a chat thread.context
- The context to associate with this operation.- 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.
-
deleteChatThread
Deletes a chat thread.- Parameters:
chatThreadId
- Chat thread id to delete.- Throws:
ChatErrorResponseException
- thrown if the request is rejected by server.RuntimeException
- all other wrapped checked exceptions if the request fails to be sent.
-
deleteChatThreadWithResponse
Deletes a chat thread.- Parameters:
chatThreadId
- Chat thread id to delete.context
- The context to associate with this operation.- 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.
-
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 PagedIterable<ChatThreadItem> listChatThreads(ListChatThreadsOptions listThreadsOptions, Context context) Gets the list of chat threads of a user.- Parameters:
listThreadsOptions
- The request options.context
- The context to associate with this operation.- 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.
-