post_enrollment_app/web/index.html

377 lines
12 KiB
HTML
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="">
<head>
<base href="$FLUTTER_BASE_HREF">
<meta charset="UTF-8">
<meta content="IE=Edge" http-equiv="X-UA-Compatible">
<meta name="description" content="Nhance App Flutter">
<!-- iOS meta tags & icons -->
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-title" content="nhance_app_pwa">
<link rel="apple-touch-icon" href="icons/Icon-192.png">
<!-- Favicon -->
<link rel="icon" type="image/png" href="favicon.png"/>
<title>Nhance</title>
<link rel="manifest" href="manifest.json">
<style>
#botmanWidgetRoot {
display: none !important;
}
#botmanWidgetRoot .desktop-closed-message-avatar{
box-shadow: none !important;
}
body.show-botman #botmanWidgetRoot {
display: block !important;
}
#botmanWidgetRoot > div{
bottom: 80px !important;
right: 10px !important;
z-index: 9999 !important;
min-width: 80px !important;
min-height: 100px !important;
}
.content {
width: 10%;
height: 10vh;
display: flex;
justify-content: center;
align-items: center;
text-align: center;
}
.overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: #FFFCE5; /* Overlay background color with opacity */
display: flex;
justify-content: center;
align-items: center;
}
/* Styles for the loading indicator */
.indicator {
width: 5vw;
}
</style>
<script>
// This script runs before the Flutter app initializes.
// Check if the current URL has the unwanted fragment
if (window.location.hash === '#login') {
// Construct the clean URL (origin + path)
const cleanUrl = window.location.origin + window.location.pathname;
// Replace the current history state to clear the fragment and
// immediately navigate to the target URL (https://app.nhanceindia.in/app)
// without creating an extra history entry.
window.location.replace(cleanUrl);
}
</script>
<script>
const hiddenRoutes = ['/#login'];
function toggleBotmanVisibility() {
const currentHash = window.location.hash;
const shouldShow = hiddenRoutes.includes(currentHash);
document.body.classList.toggle('show-botman', shouldShow);
console.log('Current hash:', currentHash, '| Botman visible:', shouldShow);
}
// Initial check after load
setTimeout(toggleBotmanVisibility, 500);
// React to route changes (Flutter uses hash-based routing)
window.addEventListener('hashchange', () => {
setTimeout(toggleBotmanVisibility, 300);
});
</script>
<!-- This script adds the flutter initialization JS code -->
<script src="flutter.js" defer></script>
<script src='https://cdn.jsdelivr.net/npm/botman-web-widget@0/build/js/widget.js'></script>
</head>
<body style="overflow:hidden">
<div id="loading_indicator" class="container overlay">
<img class="indicator" src="assets/nhance-loader.gif" alt="">
</div>
<script src="https://www.gstatic.com/firebasejs/10.7.0/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/10.7.0/firebase-auth.js"></script>
<script type="module">
// Import the functions you need from the SDKs you need
import { initializeApp } from "https://www.gstatic.com/firebasejs/10.12.4/firebase-app.js";
const firebaseConfig = {
apiKey: "AIzaSyC4yHbCX4mQu0jO81pJrDwxKLQlTQWofrc",
authDomain: "nhance-ee8d1.firebaseapp.com",
projectId: "nhance-ee8d1",
storageBucket: "nhance-ee8d1.firebasestorage.app",
messagingSenderId: "1084115316849",
appId: "1:1084115316849:web:8fc3b1c886349ae86c6bd0"
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
</script>
<script>
window.addEventListener('load', function(ev) {
// Download main.dart.js
_flutter.loader.loadEntrypoint({
onEntrypointLoaded: function(engineInitializer) {
engineInitializer.initializeEngine().then(function(appRunner) {
appRunner.runApp();
});
}
});
});
</script>
<script>
window.onLoad = function(){
setTimeout(function () {
var loadingIndicator = document.getElementById("loading_indicator");
if(loadingIndicator){
loadingIndicator.remove();
}
});
};
</script>
<script>
function generateSessionId(length = 15) {
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
let sessionId = '';
for (let i = 0; i < length; i++) {
sessionId += characters.charAt(Math.floor(Math.random() * characters.length));
}
return sessionId;
}
function getUpdatedParameters() {
return {
employee_id: localStorage.getItem('empPrimaryId') || '',
session_id: generateSessionId(15),
origin: "mobile",
emp_code: localStorage.getItem('empCode') || '',
client_id: localStorage.getItem('client_id') || '',
client_branch_id: localStorage.getItem('empClientBranchId') || ''
};
}
function initializeBotman() {
console.log("Initializing Botman Chat");
window.botmanWidget = {
chatServer: 'https://app.nhanceindia.in/zenith/chat',
frameEndpoint: 'https://app.nhanceindia.in/zenith/widget',
title: "Ask ILA",
introMessage: "",
bubbleBackground: "#179a9f",
mainColor: "#179a9f",
bubbleAvatarUrl:"https://botman.io/img/logo.png",
placeholderText: "Type your message here...",
aboutText: "Press Enter to send the message",
enableAttachments: false,
parameters: getUpdatedParameters()
};
setTimeout(() => {
watchBotmanState();
}, 2000);
}
function repositionBotmanWidget() {
const widget = document.querySelector('#botmanWidgetRoot > div');
if (widget) {
widget.style.bottom = "80px";
widget.style.right = "10px";
widget.style.minWidth = "90px";
widget.style.minHeight = "120px";
widget.style.zIndex = "9999";
widget.style.pointerEvents = "auto";
}
}
function watchBotmanState() {
const interval = setInterval(() => {
const chatFrame = document.querySelector('iframe.botman-widget-frame');
const widget = document.querySelector('#botmanWidgetRoot > div');
if (widget && chatFrame) {
// Reposition on load (chat open)
chatFrame.addEventListener('load', () => {
setTimeout(repositionBotmanWidget, 300);
});
// Observe DOM changes (chat close or resize)
const observer = new MutationObserver(() => {
repositionBotmanWidget();
});
observer.observe(widget, {
attributes: true,
childList: true,
subtree: true,
});
repositionBotmanWidget(); // Also call initially
clearInterval(interval);
}
}, 500);
}
function updateBotmanParameters() {
console.log("Updating Botman parameters...");
const updatedParams = getUpdatedParameters();
// Update Botman parameters
if (window.botmanWidget) {
window.botmanWidget.parameters = updatedParams;
}
// Reload the Botman iframe with new parameters
const chatFrame = document.querySelector('iframe.botman-widget-frame');
if (chatFrame) {
console.log("Reloading Botman iframe with new parameters...");
chatFrame.src = `https://venbait.in/nhance/dev/widget?employee_id=${updatedParams.employee_id}&session_id=${updatedParams.session_id}&origin=mobile&emp_code=${updatedParams.emp_code}&client_id=${updatedParams.client_id}&client_branch_id=${updatedParams.client_branch_id}`;
}
}
function openBotmanChat() {
const hiddenRoutes = ['/#login'];
function toggleBotmanVisibility() {
const currentHash = window.location.hash;
const shouldShow = !hiddenRoutes.includes(currentHash);
document.body.classList.toggle('show-botman', shouldShow);
console.log('Current hash:', currentHash, '| Botman visible:', shouldShow);
}
// Initial check after load
setTimeout(toggleBotmanVisibility, 500);
// React to route changes (Flutter uses hash-based routing)
window.addEventListener('hashchange', () => {
setTimeout(toggleBotmanVisibility, 300);
});
console.log("Opening chat...");
// First, update Botman parameters with new values from localStorage
updateBotmanParameters();
var checkBotman = setInterval(function () {
if (typeof botmanChatWidget !== "undefined" && botmanChatWidget.open) {
clearInterval(checkBotman);
const widget = document.getElementById('botmanWidgetRoot');
if (widget) {
widget.style.pointerEvents = 'auto'; // ✅ Enable interaction now
}
botmanChatWidget.open();
setTimeout(function () {
const emp_name = localStorage.getItem('gpaEmpName') || 'User';
botmanChatWidget.sayAsBot(`Hi ${emp_name}, This is ILA, your Insurance Assistant. Please choose the following options.`);
botmanChatWidget.whisper('Hi');
}, 2000);
} else {
console.log("Waiting for Botman to initialize...");
}
}, 500);
}
// Initialize Botman on first load
initializeBotman();
// Optional: expose reposition function to Flutter
window.repositionBotmanWidget = repositionBotmanWidget;
</script>
<script>
(function () {
// ✅ Set your background image here
const IMAGE_URL = "$FLUTTER_BASE_HREFassets/chat-bg.jpg";
// Heuristic to find the BotMan iframe (works with default /botman/chat).
// If you use a custom frameEndpoint, change the selector to match it.
const iframeSelector = 'iframe[src*="/botman/chat"], iframe[src*="botman/chat"], iframe[src*="frameEndpoint"]';
// Apply styles inside the iframe
function applyBackground(iframe) {
try {
const doc = iframe.contentDocument || iframe.contentWindow.document;
if (!doc || !doc.head) return;
// Inject a <style> so it survives rerenders
const style = doc.createElement('style');
style.textContent = `
html, body {
background-image: url("${IMAGE_URL}") !important;
background-size: cover !important;
background-position: center !important;
background-repeat: no-repeat !important;
}
/* Make common containers transparent so the image shows through.
(Covers BotMans typical containers; harmless if some dont exist.) */
.chat, .chat-container, .bm-container, .bm-content, .messages, .message-container,
.header, .footer {
background: transparent !important;
}
`;
doc.head.appendChild(style);
} catch (e) {
// Likely cross-origin; use Solution B instead.
console.warn("Couldn't style BotMan iframe (cross-origin?). Use Solution B.", e);
}
}
// Observe DOM for when the iframe is inserted/replaced
const mo = new MutationObserver(() => {
const iframe = document.querySelector(iframeSelector);
if (!iframe) return;
// If iframe already loaded, apply now; also re-apply on every 'load'
const maybeApply = () => applyBackground(iframe);
if (iframe.contentDocument?.readyState === 'complete') {
maybeApply();
console.log("maybeApply");
}
iframe.addEventListener('load', maybeApply, { once: false });
});
// Start observing the whole document (BotMan injects the iframe dynamically)
mo.observe(document.documentElement, { childList: true, subtree: true });
// In case the iframe is already there by the time this runs
const existing = document.querySelector(iframeSelector);
if (existing) {
if (existing.contentDocument?.readyState === 'complete') {
applyBackground(existing);
} else {
existing.addEventListener('load', () => applyBackground(existing), { once: true });
}
}
})();
</script>
</body>
</html>