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.void
getAccount(<any> callback)
Gets the current state of theAccount
.ChatState
getChatState()
Gets the current chat state.ObservationToken
observeAccount(Observer<Account> observer)
Observes changes to theAccount
in real-time.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
sendChatComment(java.lang.String chatComment, <any> callback)
Sends the visitor's comment on the chat experience.void
sendChatRating(ChatRating chatRating, <any> callback)
Sends the visitor's rating on the chat experience.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
sendOfflineForm(OfflineForm offlineForm, <any> callback)
Sends an offline form to contact the business when agents are offline.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.
-
sendChatRating
void sendChatRating(ChatRating chatRating, <any> callback)
Sends the visitor's rating on the chat experience.- Parameters:
chatRating
- Chat ratingcallback
- Optional callback for success and error handling
-
sendChatComment
void sendChatComment(java.lang.String chatComment, <any> callback)
Sends the visitor's comment on the chat experience.- Parameters:
chatComment
- Visitor's commentcallback
- Optional callback for success and error handling
-
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
-
sendOfflineForm
void sendOfflineForm(OfflineForm offlineForm, <any> callback)
Sends an offline form to contact the business when agents are offline.Note that this method should only be used when the
Account
orDepartment
status isStatus.OFFLINE
.Each invocation of this method creates a past chat with a single message from the visitor and the following information:
- Visitor Name
- Visitor Email Address
- Visitor Phone Number
- Selected Department
Configuring the above information and sending the offline message looks like this:
You can also change the visitor information, select a department and send the form, all at once:VisitorInfo visitorInfo = VisitorInfo.builder() .withName("Bob") .withEmail("bob@zendesk.com") .withPhoneNumber("8886704887) .build()); OfflineForm offlineForm = OfflineForm.builder("this is an offline message").build(); profileProvider.setVisitorInfo(visitorInfo); chatProvider.setDepartment(department.getId(), null) chatProvider.sendOfflineForm(offlineForm, null)
OfflineForm offlineForm = OfflineForm.builder("offline message) .withDepartment(department.getId()) .withVisitorInfo(visitorInfo) .build(); chatProvider.sendOfflineForm(offlineForm, null)
- Parameters:
offlineForm
- Offline form to be sentcallback
- An optional callback functions to be called when sending completes or fails
-
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
-
getAccount
void getAccount(<any> callback)
Gets the current state of theAccount
.- Parameters:
callback
- The callback to invoke which will return anAccount
or anErrorResponse
-
observeAccount
ObservationToken observeAccount(Observer<Account> observer)
Observes changes to theAccount
in real-time.- Parameters:
observer
- The observer to be notified whenAccount
data changes- Returns:
- The observation token to cancel the registration and clear the references
-
-