Interface ChatProvider
-
public interface ChatProvider
A provider to access and modify the chat state.You can access it as follows:
ChatProvider chatProvider = Chat.INSTANCE.providers().chatProvider();
Make sure to initialize Zendesk Chat SDK first before accessing the providers, see
Chat.init(Context, String)
for more details.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method and Description void
clearDepartment(<any> callback)
Sends a request to clear the currently selected department.boolean
deleteFailedMessage(java.lang.String failedMessageId)
Deletes the failed message from the local chat state.void
endChat(<any> callback)
Sends a request to end the chat session.ObservationToken
observeChatState(Observer<ChatState> observer)
Registers an observer to be notified when chat state changes.void
requestChat()
Sends a request to inform an agent that the visitor wants to chat.boolean
resendFailedMessage(java.lang.String failedMessageId)
Re-sends the failed message and updates the local chat state.void
selectDepartment(java.lang.String departmentName, <any> callback)
Sends a request to select a department for chatting.void
sendMessage(java.lang.String message)
Sends a new text message and updates the local chat state which can be observed usingChatProvider.observeChatState(Observer)
.void
sendTyping(boolean isTyping)
Sends a request to inform involved agents whether the visitor is currently typing or not.
-
-
-
Method Detail
-
requestChat
void requestChat()
Sends a request to inform an agent that the visitor wants to chat.Use this method to proactively start a chat and activate the triggers that you defined in the Zendesk Chat dashboard.
-
selectDepartment
void selectDepartment(java.lang.String departmentName, <any> callback)
Sends a request to select a department for chatting.Make sure to call this method only if not chatting already. See
ChatState.isChatting()
.
Otherwise, call#endChat(ZendeskCallback)
first to end the current chat session, wait for the callback, and then call this method to select the department.Once the department is selected, new chats will be routed there until the selected department is cleared by calling
#clearDepartment(ZendeskCallback)
.- Parameters:
departmentName
- the unique name of the departmentcallback
- an optional callback for success and error handling
-
clearDepartment
void clearDepartment(<any> callback)
Sends a request to clear the currently selected department.Make sure to call this method only if not chatting already. See
ChatState.isChatting()
.
Otherwise, call#endChat(ZendeskCallback)
first to end the current chat session, wait for the callback, and then call this method to clear the selected department.- Parameters:
callback
- an optional callback for success and error handling
-
endChat
void endChat(<any> callback)
Sends a request to end the chat session.Once ended, disconnects from the backend and propagates the result using the given optional callback.
In case when a request to end a chat session fails, the error is propagated to the callback without disconnecting from the backend.Once the chat ends, disconnects from the Zendesk Chat.
- Parameters:
callback
- an optional callback for success and error handling
-
sendTyping
void sendTyping(boolean isTyping)
Sends a request to inform involved agents whether the visitor is currently typing or not.- Parameters:
isTyping
-true
if visitor is typing,false
otherwise
-
sendMessage
void sendMessage(java.lang.String message)
Sends a new text message and updates the local chat state which can be observed usingChatProvider.observeChatState(Observer)
.- Parameters:
message
- new text message from the visitor
-
deleteFailedMessage
boolean deleteFailedMessage(java.lang.String failedMessageId)
Deletes the failed message from the local chat state.Make sure to provide a message ID for a failed message. You can figure out if a message has failed by calling
ChatLog.getDeliveryStatus()
.- Parameters:
failedMessageId
- a unique identifier of the failed message- Returns:
true
if the failed message has been deleted,false
otherwise
-
resendFailedMessage
boolean resendFailedMessage(java.lang.String failedMessageId)
Re-sends the failed message and updates the local chat state.Make sure to provide a message ID for a failed message. You can figure out if a message has failed by checking
ChatLog.getDeliveryStatus()
.- Parameters:
failedMessageId
- a unique identifier of the failed message- Returns:
true
if the failed message has been resent,false
> otherwise
-
observeChatState
ObservationToken observeChatState(Observer<ChatState> observer)
Registers an observer to be notified when chat state changes.- Parameters:
observer
- the observer to be notified- Returns:
- observation token to cancel the registration
-
-