(function () { if (window.MyAILoaded) return; window.MyAILoaded = true; // DELAY START BY 2 SECONDS setTimeout(() => { const cfg = window.MyAIConfig || {}; console.log(cfg); if (!cfg.plugin) return; const params = new URLSearchParams({ plugin: cfg.plugin, page: cfg.page, site: cfg.site, user: cfg.user, }); const iframe = document.createElement('iframe'); // Initial style: small size to only show the button iframe.style.display = 'none'; iframe.style.opacity = '0'; iframe.style.position = 'fixed'; iframe.style.bottom = '20px'; iframe.style.right = '20px'; iframe.style.width = '100px'; iframe.style.height = '100px'; iframe.style.border = 'none'; iframe.style.zIndex = '999999'; iframe.style.pointerEvents = 'auto'; document.body.appendChild(iframe); let endpoint = (cfg.jwt) ? '{!! $signed_ai_route !!}' : '{!! $signed_guest_route !!}'; // We don't append extra params here because the signature covers them in the signed URL generated by Laravel. // The params are passed from the original widget script call to URL::signedRoute. let iframe_height = (cfg.jwt) ? '830px' : '830px'; fetch(endpoint, { method: 'GET', headers: { 'Authorization': 'Bearer ' + (cfg.jwt || ''), 'Accept': 'text/html' } }) .then(response => { if (!response.ok) throw new Error('Failed to load chat frame'); return response.text(); }) .then(html => { // Inject script to handle iframe resize on button click const resizeScript = `