embeddedaichatux 1.0.5 → 1.0.7

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/AIChat.npm.csproj CHANGED
@@ -14,5 +14,16 @@
14
14
  <Copy SourceFiles="@(_CommonWebJsFiles)" DestinationFolder="$(MSBuildProjectDirectory)" SkipUnchangedFiles="true" />
15
15
  </Target>
16
16
 
17
+ <ItemGroup>
18
+ <None Remove="EmbeddedChat.js" />
19
+ </ItemGroup>
20
+
21
+ <ItemGroup>
22
+ <Content Include="EmbeddedChat.js">
23
+ <ExcludeFromSingleFile>true</ExcludeFromSingleFile>
24
+ <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
25
+ </Content>
26
+ </ItemGroup>
27
+
17
28
 
18
29
  </Project>
package/AIChat.npm.sln ADDED
@@ -0,0 +1,25 @@
1
+ 
2
+ Microsoft Visual Studio Solution File, Format Version 12.00
3
+ # Visual Studio Version 17
4
+ VisualStudioVersion = 17.7.34024.191
5
+ MinimumVisualStudioVersion = 10.0.40219.1
6
+ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AIChat.npm", "AIChat.npm.csproj", "{37DB7D9F-39C4-428D-A205-7E78FAB8BB25}"
7
+ EndProject
8
+ Global
9
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
10
+ Debug|Any CPU = Debug|Any CPU
11
+ Release|Any CPU = Release|Any CPU
12
+ EndGlobalSection
13
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
14
+ {37DB7D9F-39C4-428D-A205-7E78FAB8BB25}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15
+ {37DB7D9F-39C4-428D-A205-7E78FAB8BB25}.Debug|Any CPU.Build.0 = Debug|Any CPU
16
+ {37DB7D9F-39C4-428D-A205-7E78FAB8BB25}.Release|Any CPU.ActiveCfg = Release|Any CPU
17
+ {37DB7D9F-39C4-428D-A205-7E78FAB8BB25}.Release|Any CPU.Build.0 = Release|Any CPU
18
+ EndGlobalSection
19
+ GlobalSection(SolutionProperties) = preSolution
20
+ HideSolutionNode = FALSE
21
+ EndGlobalSection
22
+ GlobalSection(ExtensibilityGlobals) = postSolution
23
+ SolutionGuid = {33D9F6CE-532F-4C22-AAAD-2D8B3BB56596}
24
+ EndGlobalSection
25
+ EndGlobal
package/EmbeddedChat.js CHANGED
@@ -10,22 +10,25 @@ class EmbeddedChat {
10
10
  this.isPreview = this.options.isPreview || false;
11
11
  this.previewParam = this.isPreview ? "?isPreview=true" : "";
12
12
  this.serverUrl = this.options.serverUrl || 'https://embedgpt.chat/';
13
- this.positionStyle = this.containerDiv.dataset.position === 'in-place' ? 'width:100%; height:600px' : 'position: fixed; right: 0; bottom: 0; width: 300px; height: 600px';
13
+ 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';
14
+ this.mode = options.mode || 'Chat'; // default to 'chat' if mode isn't provided
15
+ if (this.mode === 'ContactForm') {
16
+ // Adjust position style for contact form if mode is 'ContactForm'
17
+ this.positionStyle = 'width:100%; height:600px';
18
+ this.containerDiv.style.height = '600px';
19
+ }
14
20
  this.init();
15
21
  }
16
22
 
17
- init() {
18
- const cleanedServerUrl = this.serverUrl.endsWith('/') ? this.serverUrl.slice(0, -1) : this.serverUrl;
19
- const baseIframeUrl = `${cleanedServerUrl}/ChatUX/${this.chatId}`;
20
- const previewQueryString = this.isPreview ? "?isPreview=true" : "";
21
- const minimizedQueryString = this.isPreview ? "&isMinimized=true" : "?isMinimized=true";
22
-
23
- const minimizedPositionStyle = 'position: fixed; right: 0; bottom: 0; width: 300px; height: 70px;';
23
+ init() {
24
+ const cleanedServerUrl = this.serverUrl.endsWith('/') ? this.serverUrl.slice(0, -1) : this.serverUrl;
25
+ const baseIframeUrl = `${cleanedServerUrl}/ChatUX/${this.chatId}`;
26
+ const minimizedPositionStyle = 'position: fixed; right: 0; bottom: 0; width: 300px; height: 70px; z-index: 100000';
24
27
 
25
- const iframeHtml = `
26
- <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="${baseIframeUrl}${previewQueryString}"></iframe>
27
- <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="${baseIframeUrl}${previewQueryString}${minimizedQueryString}"></iframe>
28
- `;
28
+ const iframeHtml = `
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>
31
+ `;
29
32
 
30
33
  this.containerDiv.innerHTML = iframeHtml;
31
34
  this.iframe = this.containerDiv.querySelector("#embedded-chat");
@@ -33,18 +36,25 @@ class EmbeddedChat {
33
36
 
34
37
  window.addEventListener("message", (e) => {
35
38
  // Check if the data is an object and has a message property
36
- if (typeof e.data === "object" && e.data.message) {
39
+ if (typeof e.data === "object" && e.data.message && (!e.data.chatId || e.data.chatId === this.chatId)) {
37
40
  if (e.data.message === "minimize") {
38
- this.iframe.style.display = "none";
39
- this.minimizedIframe.style.display = "block";
41
+ if (this.mode !== 'ContactForm') {
42
+ // No minimize support for ContactForm
43
+ this.iframe.style.display = "none";
44
+ this.minimizedIframe.style.display = "block";
45
+ }
40
46
  } else if (e.data.message === "show" || e.data.message === "maximize") {
41
47
  this.iframe.style.display = "block";
42
48
  this.minimizedIframe.style.display = "none";
43
49
  // Check if the data has a scale property
44
50
  if (e.data.scale) {
45
- // Resize the iframe according to the scale factor
46
- this.iframe.style.transform = `scale(${e.data.scale})`;
47
- this.iframe.style.transformOrigin = "bottom right";
51
+ if (this.mode !== 'ContactForm') {
52
+ // No scaling support for ContactForm
53
+
54
+ // Resize the iframe according to the scale factor
55
+ this.iframe.style.transform = `scale(${e.data.scale})`;
56
+ this.iframe.style.transformOrigin = "bottom right";
57
+ }
48
58
  }
49
59
  }
50
60
  }
@@ -70,8 +80,35 @@ class EmbeddedChat {
70
80
  document.body.appendChild(chatContainer);
71
81
  return chatContainer;
72
82
  }
83
+
84
+ buildIframeUrl(baseIframeUrl, params = {}) {
85
+ const urlParams = new URLSearchParams(params);
86
+
87
+ // Add parameters as needed, based on values in the params object
88
+ if (params.isPreview) {
89
+ urlParams.set('isPreview', 'true');
90
+ }
91
+
92
+ if (params.mode === 'ContactForm') {
93
+ urlParams.set('mode', 'ContactForm');
94
+ }
95
+
96
+ // Handle other parameters directly from the params object
97
+ for (const [key, value] of Object.entries(params)) {
98
+ if (key !== 'mode' && key !== 'isPreview') { // Avoid duplicates
99
+ urlParams.set(key, value);
100
+ }
101
+ }
102
+
103
+ return `${baseIframeUrl}?${urlParams.toString()}`;
104
+ }
73
105
  }
74
106
 
75
107
  export function initEmbeddedChat(containerDiv, chatId, options) {
76
108
  return new EmbeddedChat(containerDiv, chatId, options);
77
109
  }
110
+
111
+ export function initContactForm(containerDiv, chatId, options) {
112
+ const clonedOptions = { ...options, mode: 'ContactForm' }; // Clone with spread syntax
113
+ return new EmbeddedChat(containerDiv, chatId, clonedOptions);
114
+ }
@@ -0,0 +1,77 @@
1
+ // embeddedChat.js
2
+ class EmbeddedChat {
3
+ constructor(containerDiv, chatId, options) {
4
+ if (!containerDiv) {
5
+ containerDiv = this.createChatContainer();
6
+ }
7
+ this.containerDiv = containerDiv;
8
+ this.chatId = chatId;
9
+ this.options = options || {};
10
+ this.isPreview = this.options.isPreview || false;
11
+ this.previewParam = this.isPreview ? "?isPreview=true" : "";
12
+ this.serverUrl = this.options.serverUrl || 'https://embedgpt.chat/';
13
+ this.positionStyle = this.containerDiv.dataset.position === 'in-place' ? 'width:100%; height:600px' : 'position: fixed; right: 0; bottom: 0; width: 300px; height: 600px';
14
+ this.init();
15
+ }
16
+
17
+ init() {
18
+ const cleanedServerUrl = this.serverUrl.endsWith('/') ? this.serverUrl.slice(0, -1) : this.serverUrl;
19
+ const baseIframeUrl = `${cleanedServerUrl}/ChatUX/${this.chatId}`;
20
+ const previewQueryString = this.isPreview ? "?isPreview=true" : "";
21
+ const minimizedQueryString = this.isPreview ? "&isMinimized=true" : "?isMinimized=true";
22
+
23
+ const minimizedPositionStyle = 'position: fixed; right: 0; bottom: 0; width: 300px; height: 70px;';
24
+
25
+ const iframeHtml = `
26
+ <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="${baseIframeUrl}${previewQueryString}"></iframe>
27
+ <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="${baseIframeUrl}${previewQueryString}${minimizedQueryString}"></iframe>
28
+ `;
29
+
30
+ this.containerDiv.innerHTML = iframeHtml;
31
+ this.iframe = this.containerDiv.querySelector("#embedded-chat");
32
+ this.minimizedIframe = this.containerDiv.querySelector("#embedded-chat-minimized");
33
+
34
+ window.addEventListener("message", (e) => {
35
+ // Check if the data is an object and has a message property
36
+ if (typeof e.data === "object" && e.data.message && (!e.data.chatId || e.data.chatId === this.chatId)) {
37
+ if (e.data.message === "minimize") {
38
+ this.iframe.style.display = "none";
39
+ this.minimizedIframe.style.display = "block";
40
+ } else if (e.data.message === "show" || e.data.message === "maximize") {
41
+ this.iframe.style.display = "block";
42
+ this.minimizedIframe.style.display = "none";
43
+ // Check if the data has a scale property
44
+ if (e.data.scale) {
45
+ // Resize the iframe according to the scale factor
46
+ this.iframe.style.transform = `scale(${e.data.scale})`;
47
+ this.iframe.style.transformOrigin = "bottom right";
48
+ }
49
+ }
50
+ }
51
+ // For backward compatibility, handle the case when the data is a string
52
+ else if (typeof e.data === "string") {
53
+ if (e.data === "minimize") {
54
+ this.iframe.style.display = "none";
55
+ this.minimizedIframe.style.display = "block";
56
+ } else if (e.data === "show" || e.data === "maximize") {
57
+ this.iframe.style.display = "block";
58
+ this.minimizedIframe.style.display = "none";
59
+ }
60
+ }
61
+ });
62
+ }
63
+
64
+
65
+
66
+ createChatContainer() {
67
+ const chatContainer = document.createElement('div');
68
+ chatContainer.className = 'embedded-chat-container';
69
+ chatContainer.style.position = 'relative';
70
+ document.body.appendChild(chatContainer);
71
+ return chatContainer;
72
+ }
73
+ }
74
+
75
+ export function initEmbeddedChat(containerDiv, chatId, options) {
76
+ return new EmbeddedChat(containerDiv, chatId, options);
77
+ }
@@ -1 +1 @@
1
- 2a2fbdc06e3060ecc072244ebc14fc81cb280367
1
+ 071cf2c6734c65e7e6f8a119ed2e7a843e5a8ba7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "embeddedaichatux",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
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": {
package/Program.cs DELETED
@@ -1,25 +0,0 @@
1
- var builder = WebApplication.CreateBuilder(args);
2
-
3
- // Add services to the container.
4
- builder.Services.AddRazorPages();
5
-
6
- var app = builder.Build();
7
-
8
- // Configure the HTTP request pipeline.
9
- if (!app.Environment.IsDevelopment())
10
- {
11
- app.UseExceptionHandler("/Error");
12
- // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
13
- app.UseHsts();
14
- }
15
-
16
- app.UseHttpsRedirection();
17
- app.UseStaticFiles();
18
-
19
- app.UseRouting();
20
-
21
- app.UseAuthorization();
22
-
23
- app.MapRazorPages();
24
-
25
- app.Run();
package/README.md DELETED
@@ -1,14 +0,0 @@
1
- # EmbeddedChat
2
-
3
- A lightweight and customizable embedded chat UI component that seamlessly integrates into web applications, offering minimized and expanded views, with iframe-based content rendering.
4
-
5
- ## Installation
6
-
7
- To update
8
- 1. Modify the version in package.json
9
- 1. NPM login
10
- 1. npm publish
11
-
12
- NPM: https://www.npmjs.com/settings/aichatepicenter/packages
13
-
14
-
@@ -1,9 +0,0 @@
1
- {
2
- "DetailedErrors": true,
3
- "Logging": {
4
- "LogLevel": {
5
- "Default": "Information",
6
- "Microsoft.AspNetCore": "Warning"
7
- }
8
- }
9
- }
package/appsettings.json DELETED
@@ -1,9 +0,0 @@
1
- {
2
- "Logging": {
3
- "LogLevel": {
4
- "Default": "Information",
5
- "Microsoft.AspNetCore": "Warning"
6
- }
7
- },
8
- "AllowedHosts": "*"
9
- }