What are the SDK customization methods available?
- Getting Started
- Bot Building
- Smart Agent Chat
- Conversation Design
-
Developer Guides
Code Step Integration Static Step Integration Shopify Integration SETU Integration Exotel Integration CIBIL integration Freshdesk KMS Integration PayU Integration Zendesk Guide Integration Twilio Integration Razorpay Integration LeadSquared Integration USU(Unymira) Integration Helo(VivaConnect) Integration Salesforce KMS Integration Stripe Integration PayPal Integration CleverTap Integration Fynd Integration HubSpot Integration Magento Integration WooCommerce Integration Microsoft Dynamics 365 Integration
- Deployment
- External Agent Tool Setup
- Analytics & Reporting
- Notifications
- Commerce Plus
- Troubleshooting Guides
- Release Notes
Table of Contents
Client Accessible SDK
When the SDK loads, it exposes a Javascript SDK. This Javascript SDK can then be used to programmatically control some of the behavior of the SDK.
Event Listener
In order for these methods to be accessible, the SDK needs to load first. The SDK emits a custom event to notify any/all subscribers that it has loaded.
document.addEventListener('haptik_sdk', function() {
// HaptikSDK is available now
HaptikSDK.init(...);
});
Note: Using other listeners like window.onload
or document.onload
will lead to inconsistent behavior as the Haptik SDK might not have been initialized yet.
Glossary
init(initSettings)
destroy()
show()
hide()
openLanguagePicker()
signup(authOptions, callback)
logout(callback)
renewSignupToken(newToken, callback)
prompt(title, message)
launchTask(taskId, callback)
launchMessage(message, callback, hidden, hideChatWindow, skipMessage, hideWelcomeMessage)
changeLanguage(languageCode, callback)
syncCustomData(userData, callback)
init(initSettings)
Initialize the SDK and load a particular bot
Params:
-
initSettings <Object>
The client settings comprising of-
client-id: <String>
: Client Identifier (Provided by Haptik) -
base-url: <String>
: Backend Identifier (Provided by Haptik) -
business-id: <Number>
: Business Identifier (Provided by Haptik) -
privacy-policy-url: <String>
: URL to your Privacy Policy (Optional). This is useful if GDPR is enabled. If not provided users will be redirected to Haptik's privacy policy page. -
initialize-language: <String>
*: Code of language you want to open bot with. For egen
,hi
. (Optional). We support ISO_639-1 language codes.
-
destroy()
When there are 2 SDKs (one for guest use and another for logged in user) adding destroy() will clear out all the information and context from the previous instance (guest bot) to load the second bot (logged in bot)
Params:
show()
Opens up the SDK main window. (The same as clicking on the let's chat icon)
Params:
hide()
Closes the SDK main window. (The same as clicking on the cross icon while the window is open)
Params:
openLanguagePicker()
Opens up a language picker. (The same as clicking on the language picker icon in the header)
Params:
signup(authOptions, callback)
Only applicable for custom signup bots. Use this function to make a custom call for passing sign-on information to the SDK. (Refer to the custom signup section for more information)
Params:
-
authOptions <Object>
: The authorization information necessary to securely authenticate the user.-
authId <String>
: The authentication Id
-
-
callback <Function>
The callback executes once the call completes. The callback function is executed withsuccess
boolean flag as a parameter indicating whether the call was completed or failed.
logout(callback)
This method logs out the currently logged in user and clears its data
Params:
-
callback <Function>
The callback executes once the call completes.
renewSignupToken(newToken, callback)
Only applicable for custom signup bots. If the authToken sent above expires, use this function to send the updated token to our backend
Params:
-
newToken <String>
The new token that needs to be synced with our backend -
callback <Function>
The callback executes once the call completes. The callback function is executed withsuccess
the boolean flag as a parameter indicating whether the call was completed or failed.
prompt(title, message)
Creates a bot prompt to catch the user's attention. However, we recommend using dynamic bot prompts configured through the Bot-Builder. See the Bot Prompts section for more details.
Params:
-
title <String>
The text that's displayed on the bot prompt. -
message <String>
The message that's sent if the user taps on the bot prompt.
launchTask(taskId, callback)
Launches the SDK and automatically sends specified taskId as a user message (The same message that would be sent if the user tapped on that task)
Params:
-
taskId <Number>
The task id is specified in the tasks section of the bot builder (business manager) -
callback <Function>
(optional)
The callback executes once the call completes. The callback function is executed withsuccess
a boolean flag as a parameter indicating whether the call completed or failed.
launchMessage(message, callback, hidden, hideChatWindow, skipMessage, hideWelcomeMessage)
Launches the SDK and automatically sends a specific message as a user message. It can optionally be sent as a hidden user message
Params:
-
message <String>
The message that is to be sent -
callback <Function>
(optional)
The callback executes once the call completes. The callback function is executed withsuccess
boolean flag as a parameter indicating whether the call was completed or failed. -
hidden <Boolean>
Whether to send the message as a hidden user message. A hidden message is not visible to the user but can be seen by the agent or bot - hideChatWindow <Boolean> If set to true, the chat window will not get opened on launching the message.
-
skipMessage <Boolean>
If set to true, the SDK will not send a launch message if the last message is a reply to a previous launch message. -
hideWelcomeMessage <Boolean>
If set to true, the Welcome Message will not be shown when the launch message is sent.
changeLanguage(languageCode, callback)
Only applicable to multi-language bots. Changes the current language of the SDK to the language codes specified. Note: This language code must be supported by the bot in order for it to work.
Params:
-
languageCode <String>
The language code to switch to (Ex.en
) -
callback <Function>
(optional)
The callback executes once the language change completes.
updateUserData(userData, callback)
Use this method to update the user details and custom data. Make sure to call this method only after signup. Only email, mobile_no, username, and custom_data, fields are allowed in the userData dictionary.
Examples:
const userData = { email: "test@email.com", mobile_no: "8989898989", username: "User Name", custom_data: { order_id: 12345, date: "01/01/2022" } }; HaptikSDK.updateUserData(userData);
You can omit the fields which are not required to be updated.
const userData = { username: "User Name", custom_data: { order_id: 12345, date: "01/01/2022" } }; HaptikSDK.updateUserData(userData);