Skip to content

Commit dd023fa

Browse files
committed
AV-74351 Chatbot (Improving) - integration
* Work with @improving-sean * #175 from @mojavelinux * #176 from @ericgimproving
1 parent 3e112ca commit dd023fa

File tree

8 files changed

+151
-5
lines changed

8 files changed

+151
-5
lines changed

gulp.d/tasks/build.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ module.exports = (src, dest, preview) => () => {
3030
.reduce((accum, { file: depPath, type }) => (type === 'dependency' ? accum.concat(depPath) : accum), [])
3131
.map((importedPath) => fs.stat(importedPath).then(({ mtime }) => mtime))
3232
).then((mtimes) => {
33-
const newestMtime = mtimes.reduce((max, curr) => (!max || curr > max ? curr : max))
33+
const newestMtime = mtimes.reduce((max, curr) =>
34+
(!max || curr > max ? curr : max), 0)
3435
if (newestMtime > file.stat.mtime) file.stat.mtimeMs = +(file.stat.mtime = newestMtime)
3536
}),
3637
postcssUrl([
@@ -60,7 +61,7 @@ module.exports = (src, dest, preview) => () => {
6061
// NOTE concat already uses stat from newest combined file
6162
.pipe(concat('js/site.js')),
6263
vfs
63-
.src('js/vendor/*.js', { ...opts, read: false })
64+
.src('js/vendor/+([^.])?(.bundle).js', { ...opts, read: false })
6465
.pipe(
6566
// see https://gulpjs.org/recipes/browserify-multiple-destination.html
6667
map((file, enc, next) => {
@@ -74,7 +75,7 @@ module.exports = (src, dest, preview) => () => {
7475
})
7576
.bundle((bundleError, bundleBuffer) =>
7677
Promise.all(mtimePromises).then((mtimes) => {
77-
const newestMtime = mtimes.reduce((max, curr) => (!max || curr > max ? curr : max))
78+
const newestMtime = mtimes.reduce((max, curr) => (!max || curr > max ? curr : max), 0)
7879
if (newestMtime > file.stat.mtime) file.stat.mtimeMs = +(file.stat.mtime = newestMtime)
7980
if (bundleBuffer !== undefined) file.contents = bundleBuffer
8081
file.path = file.path.slice(0, file.path.length - 10) + '.js'
@@ -91,6 +92,9 @@ module.exports = (src, dest, preview) => () => {
9192
)
9293
.pipe(buffer())
9394
.pipe(uglify({ output: { comments: /^!/ } })),
95+
vfs
96+
.src('js/vendor/*.min.js', opts)
97+
.pipe(map((file, enc, next) => next(null, Object.assign(file, { extname: '' }, { extname: '.js' })))),
9498
vfs.src(require.resolve('jquery/dist/jquery.min.js'), opts).pipe(concat('js/vendor/jquery.js')),
9599
vfs
96100
.src(['css/site.css', 'css/vendor/docsearch.css'], { ...opts, sourcemaps })

gulpfile.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const task = require('./gulp.d/tasks')
2121
const glob = {
2222
all: [srcDir, previewSrcDir],
2323
css: `${srcDir}/css/**/*.css`,
24-
js: ['gulpfile.js', 'gulp.d/**/*.js', `${srcDir}/{helpers,js}/**/*.js`],
24+
js: ['gulpfile.js', 'gulp.d/**/*.js', `${srcDir}/helpers/**/*.js`, `${srcDir}/js/**/+([^.])?(.bundle).js`],
2525
}
2626

2727
const cleanTask = createTask({

src/css/chatbot.css

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
.lex-web-ui-iframe {
2+
bottom: 1.5rem;
3+
display: none; /* hidden by default changed once iframe is loaded */
4+
margin-bottom: 0;
5+
margin-left: 2px;
6+
margin-right: 3vw;
7+
margin-top: 2px;
8+
max-width: 27vw;
9+
height: 80vh; /* dynamically changed on iframe maximize/minimize */
10+
min-width: calc(30vw - 3vw); /* half viewport width minus margin right */
11+
position: fixed;
12+
right: 0;
13+
z-index: 2147483637; /* max z-index (2147483647) - 10 */
14+
}
15+
16+
.lex-web-ui-iframe iframe {
17+
border-radius: 8px 8px 10px 10px;
18+
overflow: hidden;
19+
width: 100%;
20+
height: 100%;
21+
}
22+
23+
.lex-web-ui-iframe--show {
24+
display: flex;
25+
}
26+
27+
.lex-web-ui-iframe--minimize {
28+
max-width: 230px !important;
29+
max-height: 185px !important;
30+
border-radius: 85px !important;
31+
min-width: 230px !important;
32+
}
33+
34+
.lex-web-ui-iframe--maximize {
35+
max-width: 55vw !important;
36+
height: 90vh; /* dynamically changed on iframe maximize/minimize */
37+
min-width: calc(55vw - 3vw) !important;
38+
}
39+
40+
/* disable box shadow when minimized */
41+
.lex-web-ui-iframe.lex-web-ui-iframe--minimize iframe {
42+
box-shadow: none;
43+
border-radius: none;
44+
}
45+
46+
/* hide on very small resolutions */
47+
@media only screen and (max-width: 240px), only screen and (max-height: 256px) {
48+
.lex-web-ui-iframe {
49+
display: none !important;
50+
}
51+
52+
.lex-web-ui-iframe--minimize {
53+
max-width: 300px !important;
54+
max-height: 185px !important;
55+
}
56+
}
57+
58+
/* take most space on small resolutions (smart phones) */
59+
@media only screen and (min-width: 241px) and (max-width: 480px) {
60+
.lex-web-ui-iframe {
61+
min-width: 85vw !important;
62+
height: 84vh;
63+
margin-right: 2vw;
64+
align-self: center;
65+
}
66+
67+
.lex-web-ui-iframe--maximize {
68+
max-width: 96vw !important;
69+
height: 90vh; /* dynamically changed on iframe maximize/minimize */
70+
min-width: 96vw !important;
71+
}
72+
}
73+
74+
/* adjust down on medium resolutions */
75+
@media only screen and (min-width: 481px) and (max-width: 960px) {
76+
.lex-web-ui-iframe {
77+
max-width: 55vw;
78+
height: 80vh; /* dynamically changed on iframe maximize/minimize */
79+
min-width: calc(55vw - 3vw); /* half viewport width minus margin right */
80+
}
81+
82+
.lex-web-ui-iframe--maximize {
83+
max-width: 90vw !important;
84+
height: 90vh; /* dynamically changed on iframe maximize/minimize */
85+
min-width: 90vw !important;
86+
}
87+
88+
.lex-web-ui-iframe.lex-web-ui-iframe--show.lex-web-ui-iframe--minimize {
89+
max-width: 300px !important;
90+
max-height: 185px !important;
91+
border-radius: 85px !important;
92+
min-width: 230px !important;
93+
}
94+
}

src/css/site.css

+1
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@
3535
@import "disable-callouts.css";
3636
@import "asciidoctor-external-callout.css";
3737
@import "info-banner.css";
38+
@import "chatbot.css";

src/js/12-chatbox.js

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
;(function () {
2+
var iframeLoader = new window.ChatBotUiLoader.IframeLoader()
3+
4+
const origin = window.parent.origin
5+
var chatbotUiconfig = {
6+
ui: {
7+
parentOrigin: origin,
8+
toolbarTitle: 'Couchbase',
9+
toolbarLogo: 'https://www.couchbase.com/wp-content/uploads/sites/3/2023/10/SDKs_Ottoman.svg',
10+
positiveFeedbackIntent: 'Thumbs up',
11+
negativeFeedbackIntent: 'Thumbs down',
12+
helpIntent: 'Help',
13+
enableLogin: false,
14+
forceLogin: false,
15+
AllowSuperDangerousHTMLInMessage: true,
16+
shouldDisplayResponseCardTitle: false,
17+
saveHistory: false,
18+
minButtonContent: '',
19+
hideInputFieldsForButtonResponse: false,
20+
pushInitialTextOnRestart: false,
21+
directFocusToBotInput: false,
22+
showDialogStateIcon: false,
23+
backButton: false,
24+
messageMenu: true,
25+
hideButtonMessageBubble: false,
26+
enableLiveChat: false,
27+
},
28+
iframe: {
29+
iframeOrigin: 'https://d2sozpdiqok6m4.cloudfront.net',
30+
shouldLoadIframeMinimized: true,
31+
iframeSrcPath: '/#/?lexWebUiEmbed=true&parentOrigin=' + origin,
32+
},
33+
}
34+
35+
// load the iframe
36+
iframeLoader
37+
.load(chatbotUiconfig)
38+
.then(function () {
39+
iframeLoader.api.ping()
40+
// perform actions on the parent dependent on the chatbot loading.
41+
// document.getElementById('send-intent').setAttribute('disabled', false)
42+
})
43+
.catch(function (error) {
44+
console.error('chatbot UI failed to load', error)
45+
})
46+
})()

src/js/vendor/chatbox-ui.min.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/partials/footer-scripts.hbs

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<template id="run-code-panel">
1111
{{> terminal}}
1212
</template>
13+
<script id="site-script" src="{{{uiRootPath}}}/js/vendor/chatbox-ui.js"></script>
1314
<script id="site-script" src="{{{uiRootPath}}}/js/site.js"></script>
1415
<script async src="{{{uiRootPath}}}/js/vendor/tabs.js" data-sync-storage-key="preferred-tab"></script>
1516
{{#with page.attributes.content-scripts}}

src/partials/header-content.hbs

-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@
6868
Start Free Trial
6969
<i class="far fa-cloud fa-fw"></i>
7070
</a>
71-
7271
</div>
7372

7473
</nav>

0 commit comments

Comments
 (0)