Skip to content

Commit e60d0c9

Browse files
committed
feat: Add DocsBot AI chat widget
Integrate DocsBot AI widget as a client module that loads on every page. Provides AI-powered chat assistance for developer documentation.
1 parent 365d954 commit e60d0c9

2 files changed

Lines changed: 60 additions & 0 deletions

File tree

docusaurus.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,11 @@ const config = {
255255
tagline: 'Comprehensive documentation for all GravityKit products',
256256
favicon: 'img/favicon-192.png',
257257

258+
// Client modules - runs on every page load
259+
clientModules: [
260+
'./src/clientModules/docsbot.js',
261+
],
262+
258263
// Set the production url of your site here
259264
url: site_url,
260265
// Set the /<baseUrl>/ pathname under which your site is served

src/clientModules/docsbot.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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

Comments
 (0)