Skip to content

Instantly share code, notes, and snippets.

@grantmiller
Last active August 29, 2015 14:00
Show Gist options
  • Save grantmiller/191fa5834b38723eaf09 to your computer and use it in GitHub Desktop.
Save grantmiller/191fa5834b38723eaf09 to your computer and use it in GitHub Desktop.

#LPMobile Android Library Advanced Implementation

###Connect the delegate The following code is an example of how to connect the delegate inside an activity:

final Activity activity = this;
delegateAPI = new LPMobileDelegateAPIImp(){
    @Override
    public boolean shouldUseCustomActionForChatNotAnswered() {
        return true;
    }
};

ChatServiceFactory.getInstance().setDelegateAPI(delegateAPI);

###Implement any of the optional methods:

    /**
    * Called whenever there is a change in the agents’ availability status
    * @param agentAvailability - the new value
    */
    public void onAgentAvailabilityChanged(boolean agentAvailability);

    /**
    * Called when LP mobile hides its own control "Live Chat" tab/button
    */
    public void onHideChatButton();

    /**
    * Called when LP mobile shows its own control "Live Chat" tab/button
    */
    public void onShowChatButton();

    /**
    * Called when a live chat session has ended.
    * @param byVisitor - who end the chat visitor or agent
    */
    public void onEndChat(boolean byVisitor);

    /**
    * Indicate that an custom action need to replace the default offline survey.
    * @return - Set to true if you wold like to use a custom action instead of the offline survey.
    */
    public boolean shouldUseCustomActionForChatNotAnswered();

    /**
    * Replacing the offline survey with custom action.
    * Will be run when a user starts a chat, but no agents are available,
    * instead of the default action of displaying an offline survey
    * If shouldUseCustomActionForChatNotAnswered return true - you have to implement this method
    */
    public void customActionForChatNotAnswered();

###Call LivePerson functions

####void init(Activity) void init(Activity activity)
This function must be called to initialize the LPMobile library. Pass in the current activity as the only parameter. It is safe to call this function more than once.

####void init(Activity, boolean) void init(Activity activity, boolean enableChat)
This function extend the init(Activity) and allow you to set the chat enable\disable during the initialize process.

####void open(Activity) void open(Activity activity)
This function will open chat session (If there is an active chat, it will resume it).

####void setCustomVariables(Map<String, Object>) void setCustomVariables(Map<String, Object> vars)
This function will add or update multiple custom variables in the session. The Map is a collection of variable name, variable value. All of the Object values will be transferred as the toString() representation.

####void setCustomVariable(String, Object) void setCustomVariable(String name, Object val) This function will add or update a single custom variable in the session. The val will be transferred as the toString() representation.

####void setSkill(String) void setSkill(String skill)
This function will change the current skill of the library. This may cause an availability change which will be reported in the delegate.

####void setChatEnabled() void setChatEnabled()
This function will prevent the invitations from being hidden. This does not force an invitation to be shown. When chat is enabled, invitation state is taken from the other parameters (availability, skills, etc). Changing this may trigger an availability change which will be reported in the delegate.

####void setChatDisabled() void setChatDisabled() This function will prevent the invitations from being shown. This will override any attempt by the server to show an invitation. Changing this may trigger an availability change which will be reported in the delegate.

####void setInvitationShown() void setInvitationShown()
This function should be called when a custom invitation is shown in the app. Calling this adds the state to the button funnel report.

####void endChatSession(LPMobileEndChatCallback) void endChatSession(LPMobileEndChatCallback callback)
This function can be called when the developer wishes to programatically end any running chat session. It's safe to call when there is no chat running, and it's safe to call multiple times. This function is not thread safe and should not be called concurrently.

###LPMobileEndChatCallback LPMobileEndChatCallback is an interface the developer can implement and pass as the parameter to the endChatSession function. There are 2 functions to implement in this callback:

public abstract void onSuccess();
This will be called when the chat session is confirmed to end. If there is no chat session running, this will be called immediately.

public abstract void onFailed();
This will be called if there is a problem ending the chat session. After 2 seconds, if there's no conformation that the chat session ended successfully, the library will execute this function. If the device isn't connected to the internet, this function will be called when calling endChatSession.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment