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 failedChatLogId)
Deletes the failedChatLog
with given ID from the local chat state.void
endChat(<any> callback)
Sends a request to end the chat session.void
getChatInfo(<any> callback)
Gets information about the state of the current chat for the current visitor.ChatState
getChatState()
Gets an immutable snapshot of the current chat state.void
observeChatState(ObservationScope observationScope, <any> 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.ChatLog.AttachmentMessage
resendFailedFile(java.lang.String failedChatLogId, FileUploadListener fileUploadListener)
Re-sends the failed file and updates the local chat logs.ChatLog.Message
resendFailedMessage(java.lang.String failedChatLogId)
Re-sends the failed message and updates the local chat logs.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
sendEmailTranscript(java.lang.String email, <any> callback)
Schedules an email containing the chat transcript to be sent when the chat has ended.ChatLog.AttachmentMessage
sendFile(java.io.File file, FileUploadListener fileUploadListener)
Sends a file and updates the local chat state.ChatLog.Message
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
setDepartment(long departmentId, <any> callback)
Sends a request to set a department for chatting.void
setDepartment(java.lang.String departmentName, <any> callback)
Sends a request to set a department for chatting.void
setTyping(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
-
sendEmailTranscript
void sendEmailTranscript(java.lang.String email, <any> callback)
Schedules an email containing the chat transcript to be sent when the chat has ended.This method should only be called when the visitor is chatting, See
ChatState#isChatting()
- Parameters:
email
- the email address a transcript should be sent tocallback
- optional callback for success and error handling
-
setDepartment
void setDepartment(java.lang.String departmentName, <any> callback)
Sends a request to set 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
-
setDepartment
void setDepartment(long departmentId, <any> callback)
Sends a request to set 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:
departmentId
- the unique identifier 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. The session will not be terminated on the back end, however a new session will be created locally and the old session cannot be restored.Once the chat ends, disconnects from the Zendesk Chat.
- Parameters:
callback
- an optional callback for success and error handling
-
setTyping
void setTyping(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 is 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
ChatLog.Message sendMessage(java.lang.String message)
Sends a new text message and updates the local chat logs.- Parameters:
message
- The message to be sent- Returns:
- A newly created message log entry
-
sendFile
ChatLog.AttachmentMessage 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- Returns:
- A newly created attachment message log entry
- See Also:
#observeChatState(ObservationScope, Observer)
-
resendFailedMessage
ChatLog.Message resendFailedMessage(java.lang.String failedChatLogId)
Re-sends the failed message and updates the local chat logs.- Parameters:
failedChatLogId
- the identifier of the failedChatLog
- Returns:
- A newly created attachment message log entry or
null
if resending failed
-
resendFailedFile
ChatLog.AttachmentMessage 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:
- A newly created message log entry or
null
if resending failed
-
deleteFailedMessage
boolean deleteFailedMessage(java.lang.String failedChatLogId)
Deletes the failedChatLog
with given ID 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:
#observeChatState(ObservationScope, Observer)
,ChatState#getChatLogs()
,ChatLog#getDeliveryStatus()
,DeliveryStatus
-
observeChatState
void observeChatState(ObservationScope observationScope, <any> observer)
Registers an observer to be notified when chat state changes.- Parameters:
observationScope
- the lifespan of the observationobserver
- the observer to be notified
-
getChatState
ChatState getChatState()
Gets an immutable snapshot of the current chat state.- Returns:
- The current
ChatState
ornull
if there is no cached value
-
-