{ if (window.wpAiWorkflowsChat && window.wpAiWorkflowsChat.initChat) { chatAppReady = true; clearInterval(checkForChatApp); if (pendingConfig) { initializeChat(pendingConfig); } } }, 100); function initializeChat(config) { const container = document.getElementById('chat-preview-container'); if (!container) return; container.innerHTML = ''; container.className = 'wp-ai-workflows-chat-container'; container.dataset.workflowId = config.workflow_id; container.dataset.config = btoa(JSON.stringify(config)); if (window.wpAiWorkflowsChat && window.wpAiWorkflowsChat.initChat) { try { window.wpAiWorkflowsChat.initChat('chat-preview-container'); } catch (error) { console.error('[Preview] Error initializing chat:', error); } } } window.addEventListener('message', function(event) { if (event.origin !== window.location.origin) return; if (event.data && event.data.type === 'INIT_CHAT') { if (chatAppReady) { initializeChat(event.data.config); } else { pendingConfig = event.data.config; } } if (event.data && event.data.type === 'UPDATE_CHAT_CONFIG') { const container = document.getElementById('chat-preview-container'); if (container && event.data.config) { container.dataset.config = btoa(JSON.stringify(event.data.config)); if (window.wpAiWorkflowsChat && window.wpAiWorkflowsChat.initChat) { container.innerHTML = ''; window.wpAiWorkflowsChat.initChat('chat-preview-container'); } } } }); window.addEventListener('load', function() { if (window.parent !== window) { window.parent.postMessage({ type: 'PREVIEW_READY' }, '*'); } }); "; wp_add_inline_script( 'wp-ai-workflows-chat-preview-js', $inline_js, 'before' ); } ?> Chat Preview
Loading chat preview...