Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React bot integration example #4

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
23 changes: 23 additions & 0 deletions scenarios/ReactExamples/SingupExample/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from "react";
import {loadHaptikSdk} from "./loadHaptikSDK"

class LoadSDK extends React.Component {
constructor(props) {
super(props);
this.state = {
"bot_details": {
"business-id": YOUR_BUSINESS_ID,
"client-id": "YOUR_CLIENT_ID",
"base-url": "BASE_URL"
}
};
}
componentDidMount() {
loadHaptikSdk(this.state.bot_details);
}
render() {
return (<h1>This is your website...</h1>);
}
}

export default LoadSDK;
27 changes: 27 additions & 0 deletions scenarios/ReactExamples/SingupExample/loadHaptikSDK.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const loadHaptikSdk = (botDetails) => {
const existingScript = document.getElementById('my_haptik_script');
if(!existingScript){
window.haptikInitSettings = botDetails;
const script = document.createElement('script');
script.src = "https://toolassets.haptikapi.com/platform/javascript-xdk/production/loader.js";
document.body.appendChild(script);

document.addEventListener('haptik_sdk', function () {
// signup example can be removed if signup is not used
window.HaptikSDK.signup(
{
"auth_id": "YOUR_AUTH_ID",
"auth_code": "YOUR_AUTH_CODE",
'signup-type': 'third_party'
},function(status){
if(status){
console.log("Singup API call success");
}else{
console.log("Singup API call failed");
}
}
);
});
}
}
module.exports.loadHaptikSdk = loadHaptikSdk;