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
deleteFailedChatLog(java.lang.String failedChatLogId)
Deletes the failedChatLog
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
resendFailedFile(java.lang.String failedChatLogId, FileUploadListener fileUploadListener)
Re-sends the failed file and updates the local chat logs.boolean
resendFailedMessage(java.lang.String failedChatLogId)
Re-sends the failed message and updates the local chat logs.void
selectDepartment(java.lang.String departmentName, <any> callback)
Sends a request to select a department for chatting.void
sendFile(java.io.File file, FileUploadListener fileUploadListener)
Sends a file and updates the local chat state.void
sendMessage(java.lang.String message)
Sends a new text message and updates the local chat logs.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 logs.- Parameters:
message
- new text message from the visitor
-
sendFile
void sendFile(java.io.File file, FileUploadListener fileUploadListener)
Sends a file and updates the local chat state.- Parameters:
file
- the file to be sentfileUploadListener
- an optional listener to inform the current file upload progress- See Also:
ChatProvider.observeChatState(Observer)
-
resendFailedMessage
boolean resendFailedMessage(java.lang.String failedChatLogId)
Re-sends the failed message and updates the local chat logs.- Parameters:
failedChatLogId
- the identifier of the failedChatLog
- Returns:
true> if the failed message has been resent,
false
> otherwise
-
resendFailedFile
boolean resendFailedFile(java.lang.String failedChatLogId, FileUploadListener fileUploadListener)
Re-sends the failed file and updates the local chat logs.- Parameters:
failedChatLogId
- the identifier of the failedChatLog
fileUploadListener
- an optional listener to inform the current file upload progress- Returns:
true> if the failed file has been resent,
false> otherwise
-
deleteFailedChatLog
boolean deleteFailedChatLog(java.lang.String failedChatLogId)
Deletes the failedChatLog
from the local chat state.You can obtain the identifier of the failed
ChatLog
by observing theChatState
, accessing the logs and checking their DeliveryStatus.Only a failed
ChatLog
can be deleted. Calling this method with an identifier of either pending or delivered log has no effect of the chat state and returnsfalse
.- Parameters:
failedChatLogId
- the identifier of the failedChatLog
- Returns:
true> if the
ChatLog
has been deleted,false> otherwise
- See Also:
ChatProvider.observeChatState(Observer)
,ChatState.getChatLogs()
,ChatLog.getDeliveryStatus()
,DeliveryStatus
-
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
-
-