|
1 | 1 | ;(function () { |
2 | 2 | var iframeLoader = new window.ChatBotUiLoader.IframeLoader() |
3 | 3 |
|
4 | | - const iframeOrigin = document.head.querySelector( |
5 | | - 'meta[name="page-chatbot-origin"]')?.content || |
| 4 | + const qs = (q) => document.head.querySelector(q)?.content |
| 5 | + |
| 6 | + const iframeOrigin = qs('meta[name="page-chatbot-origin"]') || |
6 | 7 | 'https://d2sozpdiqok6m4.cloudfront.net' |
7 | 8 |
|
8 | 9 | const origin = window.parent.origin |
|
36 | 37 | }, |
37 | 38 | } |
38 | 39 |
|
| 40 | + const clientContext = { |
| 41 | + product: { |
| 42 | + value: qs('meta[name="docsearch:component_title"]'), |
| 43 | + description: 'The specific product the user is reading about', |
| 44 | + }, |
| 45 | + surface: { |
| 46 | + value: 'docs', |
| 47 | + description: 'The user is reading the Couchbase Docs', |
| 48 | + }, |
| 49 | + service: { |
| 50 | + value: qs('meta[name="docsearch:component_title"]'), |
| 51 | + description: 'The specific product the user is reading about.', |
| 52 | + }, |
| 53 | + page: { |
| 54 | + route: { |
| 55 | + value: qs('meta[name="page-url"]'), |
| 56 | + description: 'The URL of the current page the user is reading', |
| 57 | + }, |
| 58 | + breadcrumbs: { |
| 59 | + value: qs('meta[name="docsearch:breadcrumbs"]'), |
| 60 | + description: 'The navigation path to the current page', |
| 61 | + }, |
| 62 | + title: { |
| 63 | + value: document.head.querySelector('title')?.innerHTML, |
| 64 | + description: 'The title of the current page the user is reading', |
| 65 | + }, |
| 66 | + description: 'The specific page the user is on, which can give context for their query', |
| 67 | + }, |
| 68 | + component: { |
| 69 | + id: { |
| 70 | + value: qs('meta[name="docsearch:component_title"]'), |
| 71 | + description: 'The component that the user is reading about', |
| 72 | + }, |
| 73 | + edition: { |
| 74 | + value: qs('meta[name="docsearch:edition"]'), |
| 75 | + description: 'The edition (e.g. Enterprise or Community) of the product the user is reading about', |
| 76 | + }, |
| 77 | + version: { |
| 78 | + value: qs('meta[name="docsearch:cversion"]'), |
| 79 | + description: 'The version of the product the user is reading about', |
| 80 | + }, |
| 81 | + description: 'The component that the user is reading about', |
| 82 | + }, |
| 83 | + } |
| 84 | + |
39 | 85 | // load the iframe |
40 | 86 | iframeLoader |
41 | 87 | .load(chatbotUiconfig) |
42 | 88 | .then(function () { |
43 | 89 | iframeLoader.api.ping() |
| 90 | + |
44 | 91 | // perform actions on the parent dependent on the chatbot loading. |
| 92 | + iframeLoader.api.setClientContext(clientContext) |
| 93 | + |
45 | 94 | // document.getElementById('send-intent').setAttribute('disabled', false) |
46 | 95 | }) |
47 | 96 | .catch(function (error) { |
|
0 commit comments