Package zendesk.chat

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 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 rating
        callback - 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 comment
        callback - 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 department
        callback - 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 or Department status is Status.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
        If ticket creation is enabled in your Chat account settings, a Support ticket will also be automatically created for each offline form.

        Configuring the above information and sending the offline message looks like this:

        
              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)
         
        You can also change the visitor information, select a department and send the form, all at once:
        
              OfflineForm offlineForm = OfflineForm.builder("offline message)
                  .withDepartment(department.getId())
                  .withVisitorInfo(visitorInfo)
                  .build();
        
              chatProvider.sendOfflineForm(offlineForm, null)
         
        Parameters:
        offlineForm - Offline form to be sent
        callback - 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 sent
        fileUploadListener - 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 failed ChatLog
        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 failed ChatLog
        fileUploadListener - an optional listener to inform the current file upload progress
        Returns:
        true if the failed file 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
      • getChatState

        ChatState getChatState()
        Gets the current chat state.
        Returns:
        ChatState or null
      • getAccount

        void getAccount(<any> callback)
        Gets the current state of the Account.
        Parameters:
        callback - The callback to invoke which will return an Account or an ErrorResponse
      • observeAccount

        ObservationToken observeAccount(Observer<Account> observer)
        Observes changes to the Account in real-time.
        Parameters:
        observer - The observer to be notified when Account data changes
        Returns:
        The observation token to cancel the registration and clear the references