<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>FreshChat example</title>
</head>
<body>
<h2>Hello Fresh Chat guys!!</h2>
<hr>
<p>Try these steps and look how widget is affected after every step</p>
<p> - Step 1: <a href="" onclick="step1()">Login as Miguel</a> Expected: Miguel</p>
<p> - Step 2: <a href="" onclick="step2()">Logout</a> Expected: empty conversation, annonymous</p>
<p> - Step 3: <a href="" onclick="step3()">Login as Ana</a> Expected: Ana</p>
<script src="https://wchat.freshchat.com/js/widget.js"></script>
<script>
window.fcConfig = {
token: "d757c7ec-d7e9-4055-a33e-487ac9d29e26",
host: "https://wchat.freshchat.com"
};
window.fcWidget.init(fcConfig);
</script>
<script>
var step1 = () => {
window.fcWidget.setExternalId(1);
window.fcWidget.user.setProperties({
externalId: 1,
firstName: 'Miguel',
lastName: 'Romero',
email: 'mromero@test.com'
});
alert("Step 1 finished. The current user should be Miguel");
}
var step2 = () => {
window.fcWidget.user.clear().then(() => {
window.fcWidget.destroy();
window.fcWidget.init({
token: "d757c7ec-d7e9-4055-a33e-487ac9d29e26",
host: "https://wchat.freshchat.com"
});
});
alert("Step 2 finished. The current user should be annonymous and chatbox should be empty");
}
var step3 = () => {
window.fcWidget.setExternalId(2);
window.fcWidget.user.setProperties({
externalId: 2,
firstName: 'Ana',
lastName: 'Barranco',
email: 'abarranco@test.com'
});
alert("Step 3 finished. The current user should be Ana");
}
</script>
</body>
</html>