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.com.azure.core.http.rest.Response<CreateChatThreadResult>createChatThreadWithResponse(CreateChatThreadOptions options, com.azure.core.util.Context context) Creates a chat thread.voiddeleteChatThread(String chatThreadId) Deletes a chat thread.com.azure.core.http.rest.Response<Void>deleteChatThreadWithResponse(String chatThreadId, com.azure.core.util.Context context) Deletes a chat thread.getChatThreadClient(String chatThreadId) Creates a chat thread client.com.azure.core.http.rest.PagedIterable<ChatThreadItem>Gets the list of chat threads of a user.com.azure.core.http.rest.PagedIterable<ChatThreadItem>listChatThreads(ListChatThreadsOptions listThreadsOptions, com.azure.core.util.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 com.azure.core.http.rest.Response<CreateChatThreadResult> createChatThreadWithResponse(CreateChatThreadOptions options, com.azure.core.util.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
public com.azure.core.http.rest.Response<Void> deleteChatThreadWithResponse(String chatThreadId, com.azure.core.util.Context context) 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 com.azure.core.http.rest.PagedIterable<ChatThreadItem> listChatThreads(ListChatThreadsOptions listThreadsOptions, com.azure.core.util.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.
-