|
| 1 | +/** |
| 2 | + * DocsBot AI Widget initialization |
| 3 | + * |
| 4 | + * This client module initializes the DocsBot AI chat widget |
| 5 | + * after the page loads. |
| 6 | + */ |
| 7 | + |
| 8 | +if (typeof window !== 'undefined') { |
| 9 | + window.DocsBotAI = window.DocsBotAI || {}; |
| 10 | + |
| 11 | + DocsBotAI.init = function(e) { |
| 12 | + return new Promise((t, r) => { |
| 13 | + var n = document.createElement("script"); |
| 14 | + n.type = "text/javascript"; |
| 15 | + n.async = true; |
| 16 | + n.src = "https://widget.docsbot.ai/chat.js"; |
| 17 | + |
| 18 | + let o = document.getElementsByTagName("script")[0]; |
| 19 | + o.parentNode.insertBefore(n, o); |
| 20 | + |
| 21 | + n.addEventListener("load", () => { |
| 22 | + let waitForElement = function(selector) { |
| 23 | + return new Promise(resolve => { |
| 24 | + if (document.querySelector(selector)) { |
| 25 | + return resolve(document.querySelector(selector)); |
| 26 | + } |
| 27 | + let observer = new MutationObserver(mutations => { |
| 28 | + if (document.querySelector(selector)) { |
| 29 | + resolve(document.querySelector(selector)); |
| 30 | + observer.disconnect(); |
| 31 | + } |
| 32 | + }); |
| 33 | + observer.observe(document.body, { childList: true, subtree: true }); |
| 34 | + }); |
| 35 | + }; |
| 36 | + |
| 37 | + Promise.all([ |
| 38 | + new Promise((resolve, reject) => { |
| 39 | + window.DocsBotAI.mount(Object.assign({}, e)).then(resolve).catch(reject); |
| 40 | + }), |
| 41 | + waitForElement("#docsbotai-root"), |
| 42 | + ]).then(() => t()).catch(r); |
| 43 | + }); |
| 44 | + |
| 45 | + n.addEventListener("error", e => { |
| 46 | + r(e.message); |
| 47 | + }); |
| 48 | + }); |
| 49 | + }; |
| 50 | + |
| 51 | + // Initialize DocsBot with your bot ID |
| 52 | + DocsBotAI.init({ |
| 53 | + id: "RSMLmklQeWMQGiTlIFU5/xVUdXNDdPK304IgNgzPT" |
| 54 | + }); |
| 55 | +} |
0 commit comments