How to set up a launch message on my website bot?
- 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
Table of Contents
launchTask(taskId, callback)launchMessage(message, callback, hidden)Sample snippetYou can launch the Bot with a task or message on behalf of the user. Haptik provides the following methods for doing so.
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
the boolean flag as a parameter indicating whether the call was completed or failed.
launchMessage(message, callback, hidden)
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
Sample snippet
The following snippet is an example of how the launch message is sent to the bot. There needs to be a start step created on the bot which will get triggered once the launch message is sent.
The example is for an eCommerce bot, here "Track my order" is the default message that is sent to the bot. "Track my order" should trigger a start step on the bot to start a new conversation.
<html> <head> <title>Haptik JS SDK Integration Demo</title> <meta charset="UTF-8" /> <meta content="width=device-width; initial-scale=1.0;" name="viewport" /> </head> <body> ...Some HTML Code Snippet... <script type="text/javascript" charset="UTF-8" src="https://toolassets.haptikapi.com/platform/javascript-xdk/production/loader.js" ></script> <script> window.haptikInitSettings = { "business-id": <View Credentials>, ##Click on "View Credentials" and get the required values "client-id": <View Credentials>, ##Make sure to have the client-id in double quotes as its a string "base-url": "https://staging.hellohaptik.com/", }; document.addEventListener('haptik_sdk', function () { HaptikSDK.launchMessage("Track My Order",callbackFunction(),false); function callbackFunction(){ }}); </script> </body> </html>
When the launch message is sent every time when the user clicks on the Lets chat button -
Declare a boolean global variable "isMessageSent" and add an if condition that only if the variable value is false, the launch message method will be called and then set the variable value as true. This way for a particular session, we can send the launch message just once.