Skip to content

Commit

Permalink
Test Inkeep AI
Browse files Browse the repository at this point in the history
  • Loading branch information
npentrel committed Nov 19, 2024
1 parent 87883bd commit 8384925
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 165 deletions.
160 changes: 99 additions & 61 deletions assets/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,71 +68,109 @@ if(main && scrollBtn) {
observer.observe(main);
}

function handleSearch(inputSelector) {
const searchConfig = {
inputSelector: inputSelector,
typesenseCollectionName: 'docsearch',
typesenseServerConfig: {
nodes: [{
host: 'cgnvrk0xwyj9576lp-1.a1.typesense.net',
port: '443',
protocol: 'https'
}],
apiKey: 'GHQK6od8KfpvTEh4YpA113gUc2dU5fGR'
},
typesenseSearchParams: {
query_by: 'hierarchy.lvl0,hierarchy.lvl1,url_without_anchor',
query_by_weight: '100,50,1',
sort_by: "_text_match:desc,item_priority:desc",
prioritize_token_position: true,
group_by: "url_without_anchor",
group_limit: 1
},
autocompleteOptions: {
autoselect: false,
debug: false,
hint: false
}
};
// Inkeep START

const search = docsearch(searchConfig);
const INKEEP_API_KEY = "b17e5b4e252d7ce29b48a48a3dcba6fcfdc045680e8ea576";
const INKEEP_INTEGRATION_ID = "cm3ogfzp4003f29brrf16r6gm";
const INKEEP_ORGANIZATION_ID = "org_yjUXfeVC1tTVMIoY";

let opened = false;
search.autocomplete.on('autocomplete:shown', (e, a, b, c) => {
opened = true;
});
search.autocomplete.on('autocomplete:closed', () => {
opened = false;
});
let cursorUsed = false;
// we can't detect the cursor changing to an empty auto complete entry,
// so the only case where getting to search results via Enter will work is
// text typed followed by Enter.
search.autocomplete.on('autocomplete:cursorchanged', (event, suggestion) => {
cursorUsed = true;
});
// search.autocomplete.on('keydown', (e) => {
// if (opened && !cursorUsed && e.key === 'Enter' && search.input[0].value !== '') {
// const query = encodeURIComponent(search.input[0].value);
// window.location = `${window.location.origin}/search?query=${query}`;
// }
// });
}
// Embed the widget using the `Inkeep.embed()` function.
const inkeepWidget = Inkeep().embed({
componentType: "ChatButton",
properties: {
chatButtonType: "PILL",
baseSettings: {
apiKey: INKEEP_API_KEY,
integrationId: INKEEP_INTEGRATION_ID,
organizationId: INKEEP_ORGANIZATION_ID,
primaryBrandColor: "#000000", // your brand color, widget color scheme is derived from this
organizationDisplayName: "Viam",
// ...optional settings
},
modalSettings: {
// optional settings
},
searchSettings: {
// optional settings
},
aiChatSettings: {
// optional settings
botAvatarSrcUrl: "/img/logo.svg", // use your own bot avatar
quickQuestions: [
"Example question 1?",
"Example question 2?",
"Example question 3?",
],
},
},
});

handleSearch('.navbar-nav .td-search-input');
handleSearch('.td-sidebar__search .td-search-input');
// Create an HTML element that the Inkeep widget will be inserted into.
const nav = document.querySelector("nav");
const sidebar = document.getElementById("td-sidebar-menu");

// Userflow START
!function(){var e="undefined"==typeof window?{}:window,r=e.userflow;if(!r){var t="https://js.userflow.com/",n=null;r=e.userflow={_stubbed:!0,load:function(){return n||(n=new Promise((function(r,o){var s=document.createElement("script");s.async=!0;var a=e.USERFLOWJS_ENV_VARS||{};"es2020"===(a.USERFLOWJS_BROWSER_TARGET||function(e){for(var r=[[/Edg\//,/Edg\/(\d+)/,80],[/OPR\//,/OPR\/(\d+)/,67],[/Chrome\//,/Chrome\/(\d+)/,80],[/Safari\//,/Version\/(\d+)/,14],[/Firefox\//,/Firefox\/(\d+)/,74]],t=0;t<r.length;t++){var n=r[t],o=n[0],s=n[1],a=n[2];if(e.match(o)){var u=e.match(new RegExp(s));if(u&&parseInt(u[1],10)>=a)return"es2020";break}}return"legacy"}(navigator.userAgent))?(s.type="module",s.src=a.USERFLOWJS_ES2020_URL||t+"es2020/userflow.js"):s.src=a.USERFLOWJS_LEGACY_URL||t+"legacy/userflow.js",s.onload=function(){r()},s.onerror=function(){document.head.removeChild(s),n=null;var e=new Error("Could not load Userflow.js");console.error(e.message),o(e)},document.head.appendChild(s)}))),n}};var o=e.USERFLOWJS_QUEUE=e.USERFLOWJS_QUEUE||[],s=function(e){r[e]=function(){var t=Array.prototype.slice.call(arguments);r.load(),o.push([e,null,t])}},a=function(e){r[e]=function(){var t,n=Array.prototype.slice.call(arguments);r.load();var s=new Promise((function(e,r){t={resolve:e,reject:r}}));return o.push([e,t,n]),s}},u=function(e,t){r[e]=function(){return t}};s("_setTargetEnv"),s("closeResourceCenter"),s("init"),s("off"),s("on"),s("prepareAudio"),s("registerCustomInput"),s("remount"),s("reset"),s("setBaseZIndex"),s("setCustomInputSelector"),s("setCustomNavigate"),s("setCustomScrollIntoView"),s("setInferenceAttributeFilter"),s("setInferenceAttributeNames"),s("setInferenceClassNameFilter"),s("setResourceCenterLauncherHidden"),s("setScrollPadding"),s("setShadowDomEnabled"),s("setPageTrackingDisabled"),s("setUrlFilter"),s("openResourceCenter"),s("toggleResourceCenter"),a("endAll"),a("endAllFlows"),a("endChecklist"),a("group"),a("identify"),a("identifyAnonymous"),a("start"),a("startFlow"),a("startWalk"),a("track"),a("updateGroup"),a("updateUser"),u("getResourceCenterState",null),u("isIdentified",!1)}}();
const inkeepNavDiv = document.createElement("div");
inkeepNavDiv.id = "navSearchBar";
nav.appendChild(inkeepNavDiv);

userflow.init("ct_dybdwc2fkna4lmih2zyqb6eune");
userflow.setResourceCenterLauncherHidden(true);
const inkeepSidebarDiv = document.createElement("div");
inkeepSidebarDiv.id = "sideSearchBar";
sidebar && sidebar.prepend(inkeepSidebarDiv);

async function initAndClick() {
// unclear why it needs to be called twice but otherwise you need to click the button twice.
await userflow.identifyAnonymous({});
await userflow.identifyAnonymous({});
userflow.openResourceCenter()
}
// Function for initializating the widget.
const addInkeepWidget = ({
targetElement,
stylesheetUrls,
isShortcutKeyEnabled,
}) => {
// Embed the widget using the `Inkeep.embed()` function.
const inkeepWidget = Inkeep().embed({
componentType: "SearchBar",
targetElement,
properties: {
baseSettings: {
apiKey: INKEEP_API_KEY,
integrationId: INKEEP_INTEGRATION_ID,
organizationId: INKEEP_ORGANIZATION_ID,
primaryBrandColor: "#000000", // your brand color, widget color scheme is derived from this
organizationDisplayName: "Inkeep",
// ...optional settings
theme: {
stylesheetUrls,
// ...optional settings
},
},
modalSettings: {
// optional settings
isShortcutKeyEnabled,
},
searchSettings: {
// optional settings
},
aiChatSettings: {
// optional settings
botAvatarSrcUrl: "/img/logo.svg", // use your own bot avatar
quickQuestions: [
"Example question 1?",
"Example question 2?",
"Example question 3?",
],
},
},
});
};

sidebar &&
addInkeepWidget({
targetElement: document.getElementById("sideSearchBar"),
stylesheetUrls: ['/path/to/stylesheets'], // optional
isShortcutKeyEnabled: false,
});

addInkeepWidget({
targetElement: document.getElementById("navSearchBar"),
stylesheetUrls: ['/path/to/stylesheets'], // optional
isShortcutKeyEnabled: true,
});

// Userflow END
// Inkeep END
72 changes: 0 additions & 72 deletions assets/js/search-results.js

This file was deleted.

26 changes: 0 additions & 26 deletions assets/js/search.js

This file was deleted.

5 changes: 3 additions & 2 deletions layouts/docs/baseof.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@
</main>
{{ $img := resources.GetMatch "/icons/learn-viam-robot-icon-ai.svg" }}
</div>
<button onclick="initAndClick()" class="docsbutton" id="chatButton" title="Chatbot and support">

<!-- <button onclick="initAndClick()" class="docsbutton" id="chatButton" title="Chatbot and support">
<span id="chatButtonContent">
<i style="font-size:x-large;" class="fas fa-comments"></i>
<span>Ask AI</span>
</span>
</button>
</button> -->
<button onclick="toTop()" class="docsbutton" id="scrollButton" title="Go to top" style="visibility: hidden;">
<i style="font-size:x-large;" class="fas fa-chevron-up"></i>
</button>
Expand Down
4 changes: 0 additions & 4 deletions layouts/docs/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,5 @@ <h1>{{ .Title }}</h1>

<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>

{{ $jsSearchResults := resources.Get "js/search-results.js" }}
{{ $jsSearchResults := $jsSearchResults | minify }}
<script type="text/javascript" src="{{ $jsSearchResults.RelPermalink }}" crossorigin="anonymous"></script>

</body>
</html>
6 changes: 6 additions & 0 deletions layouts/partials/scripts.html
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@
{{ end }}
<script src="https://cdn.jsdelivr.net/npm/typesense-docsearch.js@1/dist/cdn/docsearch.min.js"></script>

<script
src="https://unpkg.com/@inkeep/[email protected]/dist/embed.js"
type="module"
defer
></script>

{{ $jsIndex := resources.Get "js/index.js" }}
{{ $jsPrismViam := resources.Get "js/prism.js" }}
{{ $jsToc := resources.Get "js/toc.js" }}
Expand Down

0 comments on commit 8384925

Please sign in to comment.