embeddedaichatux 1.3.1 → 1.3.2
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/EmbeddedChat.js +36 -7
- package/package.json +1 -1
package/EmbeddedChat.js
CHANGED
|
@@ -8,6 +8,7 @@ class EmbeddedChat {
|
|
|
8
8
|
this.chatId = chatId;
|
|
9
9
|
this.options = options || {};
|
|
10
10
|
this.isPreview = this.options.isPreview || false;
|
|
11
|
+
this.locale = options.locale || 'en';
|
|
11
12
|
this.previewParam = this.isPreview ? "?isPreview=true" : "";
|
|
12
13
|
this.serverUrl = this.options.serverUrl || 'https://embedgpt.chat/';
|
|
13
14
|
this.positionStyle = this.containerDiv.dataset.position === 'in-place' ? 'width:100%; height:600px' : 'position: fixed; right: 0; bottom: 0; width: 300px; height: 600px; z-index: 100000';
|
|
@@ -17,17 +18,18 @@ class EmbeddedChat {
|
|
|
17
18
|
this.positionStyle = 'width:100%; height:600px';
|
|
18
19
|
this.containerDiv.style.height = '600px';
|
|
19
20
|
}
|
|
21
|
+
this.sessionInfo = options.sessionInfo || null;
|
|
20
22
|
this.init();
|
|
21
23
|
}
|
|
22
24
|
|
|
23
|
-
init() {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
init() {
|
|
26
|
+
const cleanedServerUrl = this.serverUrl.endsWith('/') ? this.serverUrl.slice(0, -1) : this.serverUrl;
|
|
27
|
+
const baseIframeUrl = `${cleanedServerUrl}/ChatUX/${this.chatId}`;
|
|
28
|
+
const minimizedPositionStyle = 'position: fixed; right: 0; bottom: 0; width: 300px; height: 70px; z-index: 100000';
|
|
27
29
|
|
|
28
|
-
|
|
29
|
-
<iframe id="embedded-chat" style="${this.positionStyle}; display: none; border:none; overflow:hidden;" frameborder="0" sandbox="allow-same-origin allow-scripts allow-popups allow-forms" src="${this.buildIframeUrl(baseIframeUrl, { isPreview: this.isPreview, mode: this.mode })}"></iframe>
|
|
30
|
-
<iframe id="embedded-chat-minimized" style="${minimizedPositionStyle}; display: none; border:none; overflow:hidden;" frameborder="0" sandbox="allow-same-origin allow-scripts allow-popups allow-forms" src="${this.buildIframeUrl(baseIframeUrl, { isPreview: this.isPreview, isMinimized: true })}"></iframe>
|
|
30
|
+
const iframeHtml = `
|
|
31
|
+
<iframe id="embedded-chat" style="${this.positionStyle}; display: none; border:none; overflow:hidden;" frameborder="0" sandbox="allow-same-origin allow-scripts allow-popups allow-forms" src="${this.buildIframeUrl(baseIframeUrl, { isPreview: this.isPreview, mode: this.mode, locale: this.locale })}"></iframe>
|
|
32
|
+
<iframe id="embedded-chat-minimized" style="${minimizedPositionStyle}; display: none; border:none; overflow:hidden;" frameborder="0" sandbox="allow-same-origin allow-scripts allow-popups allow-forms" src="${this.buildIframeUrl(baseIframeUrl, { isPreview: this.isPreview, isMinimized: true, locale: this.locale })}"></iframe>
|
|
31
33
|
`;
|
|
32
34
|
|
|
33
35
|
this.containerDiv.innerHTML = iframeHtml;
|
|
@@ -56,6 +58,10 @@ init() {
|
|
|
56
58
|
this.iframe.style.transformOrigin = "bottom right";
|
|
57
59
|
}
|
|
58
60
|
}
|
|
61
|
+
// Send sessionInfo if available
|
|
62
|
+
if (this.sessionInfo !== null) {
|
|
63
|
+
this.setSessionInfo(this.sessionInfo);
|
|
64
|
+
}
|
|
59
65
|
}
|
|
60
66
|
}
|
|
61
67
|
// For backward compatibility, handle the case when the data is a string
|
|
@@ -71,7 +77,26 @@ init() {
|
|
|
71
77
|
});
|
|
72
78
|
}
|
|
73
79
|
|
|
80
|
+
setSessionInfo(sessionInfo) {
|
|
81
|
+
console.log('setSessionInfo called with sessionInfo:', sessionInfo);
|
|
82
|
+
|
|
83
|
+
// Store the new sessionInfo
|
|
84
|
+
this.sessionInfo = sessionInfo;
|
|
85
|
+
|
|
86
|
+
// Obtain the iframe element
|
|
87
|
+
const iframe = this.containerDiv.querySelector("#embedded-chat");
|
|
88
|
+
|
|
89
|
+
// Function to post the message with a structured object
|
|
90
|
+
const postMessage = () => {
|
|
91
|
+
console.log('Posting message to iframe:', { type: 'setSessionInfo', sessionInfo: sessionInfo });
|
|
92
|
+
iframe.contentWindow.postMessage({ type: 'setSessionInfo', sessionInfo: sessionInfo }, "*");
|
|
93
|
+
};
|
|
74
94
|
|
|
95
|
+
// If the iframe is visible, post the message
|
|
96
|
+
if (iframe.style.display !== "none") {
|
|
97
|
+
postMessage();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
75
100
|
|
|
76
101
|
createChatContainer() {
|
|
77
102
|
const chatContainer = document.createElement('div');
|
|
@@ -93,6 +118,10 @@ init() {
|
|
|
93
118
|
urlParams.set('mode', 'ContactForm');
|
|
94
119
|
}
|
|
95
120
|
|
|
121
|
+
if (params.locale) {
|
|
122
|
+
urlParams.set('locale', params.locale);
|
|
123
|
+
}
|
|
124
|
+
|
|
96
125
|
// Handle other parameters directly from the params object
|
|
97
126
|
for (const [key, value] of Object.entries(params)) {
|
|
98
127
|
if (key !== 'mode' && key !== 'isPreview') { // Avoid duplicates
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "embeddedaichatux",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.2",
|
|
4
4
|
"description": "A lightweight and customizable embedded AI chat UI component that seamlessly integrates into web applications, offering minimized and expanded views, with iframe-based content rendering.",
|
|
5
5
|
"main": "EmbeddedChat.js",
|
|
6
6
|
"scripts": {
|