Haptik SDK supports two types of user authentication:
1. Guest Signup
SDK creates a new user, without any specific details.
Kotlin Code:
fun launchGuestConversation() {
HaptikSDK.loadGuestConversation(callback = {
if (it.status) {
Toast.makeText(context, "Launch successful", Toast.LENGTH_LONG).show()
} else {
Toast.makeText(context, "Failure : ${it.message}", Toast.LENGTH_LONG).show()
}
})
}Parameter:
- callback(Optional): This callback will notify you if the conversation was launched successfully or not. You will receive the status(boolean) and message(String) in the callback response parameter.
Java Code:
Public void launchGuestConversation(){
HaptikSDK.INSTANCE.loadGuestConversation(callback -> {
if (callback.getStatus()) {
Toast.makeText(context, "Launch successful", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(context, "Failure : " + callback.getMessage(), Toast.LENGTH_LONG).show();
}
});
}Parameter:
- callback(Optional): This callback will notify you if the conversation was launched successfully or not. You will receive the status(boolean) and message(String) in the callback response parameter.
2. Custom signup
For cases when the client/parent application already has a signup flow in place and wants to link the same user to the SDK. Prepare SignupData object with required data and pass it to Haptik SDK.
Kotlin Code:
fun launchCustomSignupConversation() {
val signupData = SignupData().apply {
authCode = "YOUR_AUTH_CODE"
authId = "YOUR_AUTH_ID"
signupType = "third_party"
customData = JSONObject().apply {
put("custom-data-one", "date-one")
put("custom-data-two", "data-two")
}
}
HaptikSDK.loadConversation(signupData, callback = {
if (it.status) {
Toast.makeText(context, "Launch successful", Toast.LENGTH_LONG).show()
} else {
Toast.makeText(context, "Failure : ${it.message}", Toast.LENGTH_LONG).show()
}
})
}- callback(Optional): This callback will notify you if the conversation was launched successfully or not. You will receive the status(boolean) and message(String) in the callback response parameter.
Java Code:
public void launchCustomSignUpConversation(){
SignupData signupData = new SignupData();
signupData.setAuthCode("YOUR_AUTH_CODE");
signupData.setAuthId("YOUR_AUTH_ID");
signupData.setSignupType("third_party");
JSONObject jsonObject = new JSONObject();
jsonObject.put("custom-data-wrapper-one", "data-one");
jsonObject.put("custom-data-wrapper-two", "data-two");
signupData.setCustomData(jsonObject);
HaptikSDK.INSTANCE.loadConversation(signupData, callback -> {
if (callback.getStatus()) {
Toast.makeText(context, "Launch successful", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(context, "Failure : " + callback.getMessage(), Toast.LENGTH_LONG).show();
}
});
}- callback(Optional): This callback will notify you if the conversation was launched successfully or not. You will receive the status(boolean) and message(String) in the callback response parameter.
SignupData Options:
- authId <String> : User Identifier [Mandatory]
- authCode <String> : Authorisation Token [Mandatory]
- signupType <String>: Type of singup. Please connect with your Haptik SPOC for this[Mandatory]
- username <String> : The name of the signed in user[Optional]
- email <String> : Email id of signed in user[Optional]
- mobileNo <String> : Mobile number of signed in user[Optional]
- customData <Object> : Arbitrary key value data that the client needs to send[Optional]
Points to note:
1. You have to call:
HaptikSDK.loadGuestConversation() or HaptikSDK.loadConversation(signupData) every time you want to take users to the conversation screen. If the user is not logged in, HaptikSDK will perform the signup and open the conversation screen. If the user is already logged in, HaptikSDK will simply open the conversation screen.
2. Check if the Verification Endpoint has been added. Click here for better understanding.