open-chat-studio-widget 0.5.3 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/cjs/{index-D8A4RBzq.js → index-CcvroTR_.js} +3 -3
- package/dist/cjs/{index-D8A4RBzq.js.map → index-CcvroTR_.js.map} +1 -1
- package/dist/cjs/loader.cjs.js +2 -2
- package/dist/cjs/open-chat-studio-widget.cjs.entry.js +31 -5
- package/dist/cjs/open-chat-studio-widget.cjs.entry.js.map +1 -1
- package/dist/cjs/open-chat-studio-widget.cjs.js +2 -2
- package/dist/cjs/open-chat-studio-widget.entry.cjs.js.map +1 -1
- package/dist/collection/components/ocs-chat/ocs-chat.js +53 -3
- package/dist/collection/components/ocs-chat/ocs-chat.js.map +1 -1
- package/dist/collection/services/file-attachment-manager.js +2 -1
- package/dist/collection/services/file-attachment-manager.js.map +1 -1
- package/dist/components/open-chat-studio-widget.js +32 -4
- package/dist/components/open-chat-studio-widget.js.map +1 -1
- package/dist/esm/{index-C53whb-B.js → index-BKVXO_5E.js} +3 -3
- package/dist/esm/{index-C53whb-B.js.map → index-BKVXO_5E.js.map} +1 -1
- package/dist/esm/loader.js +3 -3
- package/dist/esm/open-chat-studio-widget.entry.js +31 -5
- package/dist/esm/open-chat-studio-widget.entry.js.map +1 -1
- package/dist/esm/open-chat-studio-widget.js +3 -3
- package/dist/open-chat-studio-widget/open-chat-studio-widget.entry.esm.js.map +1 -1
- package/dist/open-chat-studio-widget/open-chat-studio-widget.esm.js +1 -1
- package/dist/open-chat-studio-widget/{p-C53whb-B.js → p-BKVXO_5E.js} +2 -2
- package/dist/open-chat-studio-widget/{p-C53whb-B.js.map → p-BKVXO_5E.js.map} +1 -1
- package/dist/open-chat-studio-widget/p-a0d04423.entry.js +4 -0
- package/dist/open-chat-studio-widget/p-a0d04423.entry.js.map +1 -0
- package/dist/types/components/ocs-chat/ocs-chat.d.ts +12 -0
- package/dist/types/components.d.ts +8 -0
- package/package.json +1 -1
- package/dist/open-chat-studio-widget/p-b9556259.entry.js +0 -4
- package/dist/open-chat-studio-widget/p-b9556259.entry.js.map +0 -1
|
@@ -224,6 +224,7 @@ export class OcsChat {
|
|
|
224
224
|
}
|
|
225
225
|
this.parseWelcomeMessages();
|
|
226
226
|
this.parseStarterQuestions();
|
|
227
|
+
this.loadInternalPageContext();
|
|
227
228
|
}
|
|
228
229
|
componentDidLoad() {
|
|
229
230
|
const computedStyle = getComputedStyle(this.host);
|
|
@@ -316,6 +317,16 @@ export class OcsChat {
|
|
|
316
317
|
}
|
|
317
318
|
this.translationManager = new TranslationManager(this.language, customTranslationsObj);
|
|
318
319
|
}
|
|
320
|
+
loadInternalPageContext() {
|
|
321
|
+
if (this.pageContext === undefined || this.pageContext === null) {
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
if (typeof this.pageContext !== 'object' || Array.isArray(this.pageContext)) {
|
|
325
|
+
console.error("pageContext is expected to be a plain JavaScript object.");
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
this.internalPageContext = this.pageContext;
|
|
329
|
+
}
|
|
319
330
|
async loadTranslationsFromUrl(url) {
|
|
320
331
|
try {
|
|
321
332
|
const response = await fetch(url);
|
|
@@ -448,10 +459,14 @@ export class OcsChat {
|
|
|
448
459
|
if (this.allowAttachments && attachmentIds.length > 0) {
|
|
449
460
|
requestBody.attachment_ids = attachmentIds;
|
|
450
461
|
}
|
|
462
|
+
if (this.internalPageContext) {
|
|
463
|
+
requestBody.context = this.internalPageContext;
|
|
464
|
+
}
|
|
451
465
|
const data = await this.getChatService().sendMessage(this.sessionId, requestBody);
|
|
452
466
|
if (data.status === 'error') {
|
|
453
467
|
throw new Error(data.error || 'Failed to send message');
|
|
454
468
|
}
|
|
469
|
+
this.internalPageContext = undefined;
|
|
455
470
|
this.startTaskPolling(data.task_id);
|
|
456
471
|
}
|
|
457
472
|
catch (error) {
|
|
@@ -538,6 +553,14 @@ export class OcsChat {
|
|
|
538
553
|
toggleWindowVisibility() {
|
|
539
554
|
this.visible = !this.visible;
|
|
540
555
|
}
|
|
556
|
+
/**
|
|
557
|
+
* Watch for changes to the `pageContext` prop and sync to internal variable.
|
|
558
|
+
*
|
|
559
|
+
* @param pageContext - The new value for the field.
|
|
560
|
+
*/
|
|
561
|
+
pageContextHandler() {
|
|
562
|
+
this.loadInternalPageContext();
|
|
563
|
+
}
|
|
541
564
|
/**
|
|
542
565
|
* Watch for changes to the `visible` attribute and update accordingly.
|
|
543
566
|
*
|
|
@@ -1097,7 +1120,7 @@ export class OcsChat {
|
|
|
1097
1120
|
if (el) {
|
|
1098
1121
|
this.fileInputRef = el;
|
|
1099
1122
|
}
|
|
1100
|
-
}, id: "ocs-file-input", type: "file", multiple: true, accept: OcsChat.SUPPORTED_FILE_EXTENSIONS.join(','), onChange: (e) => this.handleFileSelect(e), class: "hidden" })), this.allowAttachments && (h("button", { class: "file-attachment-button", onClick: () => { var _a; return (_a = this.fileInputRef) === null || _a === void 0 ? void 0 : _a.click(); }, disabled: this.isTyping || this.isUploadingFiles || this.isLoading, title: this.translationManager.get('attach.add'), "aria-label": this.translationManager.get('attach.add') }, h(PaperClipIcon, null))), h("button", { class: `send-button ${!this.isTyping && !this.isLoading && !!this.messageInput.trim()
|
|
1123
|
+
}, id: "ocs-file-input", type: "file", multiple: true, accept: OcsChat.SUPPORTED_FILE_EXTENSIONS.join(',') + ',text/*', onChange: (e) => this.handleFileSelect(e), class: "hidden" })), this.allowAttachments && (h("button", { class: "file-attachment-button", onClick: () => { var _a; return (_a = this.fileInputRef) === null || _a === void 0 ? void 0 : _a.click(); }, disabled: this.isTyping || this.isUploadingFiles || this.isLoading, title: this.translationManager.get('attach.add'), "aria-label": this.translationManager.get('attach.add') }, h(PaperClipIcon, null))), h("button", { class: `send-button ${!this.isTyping && !this.isLoading && !!this.messageInput.trim()
|
|
1101
1124
|
? 'send-button-enabled'
|
|
1102
1125
|
: 'send-button-disabled'}`, onClick: () => this.sendMessage(this.messageInput), disabled: this.isTyping || this.isUploadingFiles || this.isLoading || !this.messageInput.trim() }, this.isUploadingFiles ? `${this.translationManager.get('status.uploading')}...` : this.translationManager.get('composer.send')))), h("div", { class: "flex items-center justify-center text-[0.8em] font-light w-full text-slate-500 py-[2px]" }, h("p", null, this.translationManager.get('branding.poweredBy'), ' ', " ", h("a", { class: "underline", href: "https://www.dimagi.com", target: "_blank" }, "Dimagi"))))))));
|
|
1103
1126
|
}
|
|
@@ -1521,6 +1544,29 @@ export class OcsChat {
|
|
|
1521
1544
|
"getter": false,
|
|
1522
1545
|
"setter": false,
|
|
1523
1546
|
"reflect": false
|
|
1547
|
+
},
|
|
1548
|
+
"pageContext": {
|
|
1549
|
+
"type": "unknown",
|
|
1550
|
+
"attribute": "page-context",
|
|
1551
|
+
"mutable": true,
|
|
1552
|
+
"complexType": {
|
|
1553
|
+
"original": "Record<string, any>",
|
|
1554
|
+
"resolved": "{ [x: string]: any; }",
|
|
1555
|
+
"references": {
|
|
1556
|
+
"Record": {
|
|
1557
|
+
"location": "global",
|
|
1558
|
+
"id": "global::Record"
|
|
1559
|
+
}
|
|
1560
|
+
}
|
|
1561
|
+
},
|
|
1562
|
+
"required": false,
|
|
1563
|
+
"optional": true,
|
|
1564
|
+
"docs": {
|
|
1565
|
+
"tags": [],
|
|
1566
|
+
"text": "Optional context object to send with each message. This provides page-specific context to the bot."
|
|
1567
|
+
},
|
|
1568
|
+
"getter": false,
|
|
1569
|
+
"setter": false
|
|
1524
1570
|
}
|
|
1525
1571
|
};
|
|
1526
1572
|
}
|
|
@@ -1551,6 +1597,9 @@ export class OcsChat {
|
|
|
1551
1597
|
static get elementRef() { return "host"; }
|
|
1552
1598
|
static get watchers() {
|
|
1553
1599
|
return [{
|
|
1600
|
+
"propName": "pageContext",
|
|
1601
|
+
"methodName": "pageContextHandler"
|
|
1602
|
+
}, {
|
|
1554
1603
|
"propName": "visible",
|
|
1555
1604
|
"methodName": "visibilityHandler"
|
|
1556
1605
|
}];
|
|
@@ -1566,6 +1615,7 @@ OcsChat.WINDOW_MARGIN = 20;
|
|
|
1566
1615
|
OcsChat.LOCALSTORAGE_TEST_KEY = '__ocs_test__';
|
|
1567
1616
|
OcsChat.MAX_FILE_SIZE_MB = 50;
|
|
1568
1617
|
OcsChat.MAX_TOTAL_SIZE_MB = 50;
|
|
1569
|
-
OcsChat.SUPPORTED_FILE_EXTENSIONS = ['.txt', '.pdf', '.doc', '.docx', '.xls', '.xlsx', '.csv', '.jpg',
|
|
1570
|
-
'.png', '.gif', '.bmp', '.webp', '.svg', '.mp4', '.mov', '.avi', '.mp3', '.wav'
|
|
1618
|
+
OcsChat.SUPPORTED_FILE_EXTENSIONS = ['.txt', '.pdf', '.doc', '.docx', '.xls', '.xlsx', '.csv', '.jpg',
|
|
1619
|
+
'.jpeg', '.png', '.gif', '.bmp', '.webp', '.svg', '.mp4', '.mov', '.avi', '.mp3', '.wav', '.html', '.htm', '.css',
|
|
1620
|
+
'.js', '.xml', '.md', '.ics', '.vcf', '.rtf', '.tsv', '.yaml', '.yml', '.py', '.c'];
|
|
1571
1621
|
//# sourceMappingURL=ocs-chat.js.map
|