Skip to content

Commit 07b5951

Browse files
kyle-ssgRobert Norrie
andauthored
docs: kapa ai widget (#5851)
Co-authored-by: Robert Norrie <robert.norrie@flagsmith.com>
1 parent 264ba65 commit 07b5951

5 files changed

Lines changed: 68 additions & 11 deletions

File tree

docs/docusaurus.config.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,13 +302,24 @@ const config: Config = {
302302
],
303303

304304
scripts: [
305-
'/js/crisp-chat.js',
306305
{
307306
src: '//js-eu1.hs-scripts.com/143451822.js',
308307
async: true,
309308
defer: true,
310309
id: 'hs-script-loader',
311310
},
311+
{
312+
src: "https://widget.kapa.ai/kapa-widget.bundle.js",
313+
"data-website-id": "bbb5a478-1363-4c1e-84b5-cdba2c58e5ad",
314+
"data-project-name": "Flagsmith",
315+
"data-project-color": "#6633FF",
316+
"data-project-logo": "http://docs.flagsmith.com/img/logo.svg",
317+
"data-answer-cta-button-enabled": "true",
318+
"data-answer-cta-button-link": "/support/",
319+
"data-answer-cta-button-text": "Still need help? Reach out to our support team",
320+
"data-modal-disclaimer": "Results are AI generated from our product documentation. [Contact Support to speak to a human](/support).",
321+
async: true,
322+
},
312323
],
313324

314325
clientModules: [

docs/src/css/custom.css

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
.hidden {
1010
display: none !important;
1111
}
12-
12+
/*Prevents kapa from immediately showing before crisp on support pages*/
13+
#kapa-widget-container {
14+
display: none;
15+
}
1316
@font-face {
1417
font-family: 'Open Sans Regular';
1518
src: url('/static/fonts/open-sans-regular.woff') format('woff');

docs/src/theme/Layout/crisp.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// src/crisp.js
2+
import { useEffect } from 'react';
3+
import { useLocation } from '@docusaurus/router';
4+
5+
export default function CrispLoader() {
6+
const location = useLocation();
7+
8+
useEffect(() => {
9+
if (typeof window === 'undefined') {
10+
return;
11+
}
12+
13+
window.$crisp = window.$crisp || [];
14+
window.CRISP_WEBSITE_ID = '8857f89e-0eb5-4263-ab49-a293872b6c19';
15+
16+
if (!document.getElementById('crisp-chat-script')) {
17+
const d = document;
18+
const s = d.createElement('script');
19+
s.id = 'crisp-chat-script';
20+
s.src = 'https://client.crisp.chat/l.js';
21+
s.async = 1;
22+
d.head.appendChild(s);
23+
}
24+
25+
const kapaEl = document.getElementById('kapa-widget-container');
26+
27+
if (location.pathname.replace(/\//g, '') === 'support') {
28+
window.$crisp.push(['do', 'chat:show']);
29+
window.$crisp.push(['do', 'chat:open']);
30+
window.__isCrispVisible = true;
31+
if (kapaEl) kapaEl.style.display = 'none';
32+
} else {
33+
window.$crisp.push(['do', 'chat:hide']);
34+
window.__isCrispVisible = false;
35+
if (kapaEl) kapaEl.style.display = 'block';
36+
}
37+
}, [location.pathname]);
38+
39+
return null;
40+
}

docs/src/theme/Layout/index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import React from 'react';
2+
import OriginalLayout from '@theme-original/Layout';
3+
import CrispLoader from './crisp';
4+
5+
export default function Layout(props) {
6+
return (
7+
<>
8+
<CrispLoader />
9+
<OriginalLayout {...props} />
10+
</>
11+
);
12+
}

docs/static/js/crisp-chat.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)