wineater-bot 1.1.2 → 1.1.3
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/dist/wineater-chatbot.mjs +39 -37
- package/dist/wineater-chatbot.umd.js +3 -3
- package/index.html +3 -1
- package/package.json +1 -1
- package/src/js/api.js +6 -1
|
@@ -245,45 +245,47 @@ function p() {
|
|
|
245
245
|
document.addEventListener("DOMContentLoaded", () => {
|
|
246
246
|
setupCloseButton(), setupOutsideClick();
|
|
247
247
|
});
|
|
248
|
-
|
|
248
|
+
const g = ["climats", "telckel", "biobio"];
|
|
249
|
+
class h {
|
|
249
250
|
constructor(n) {
|
|
250
|
-
this.apiEndpoint = n || "https://api.wineater.com/dish/recommendations";
|
|
251
|
+
this.apiEndpoint = n || "https://api.wineater.com/dish/recommendations", this.store = g.find((e) => window.location.href.includes(e)), console.log(this.store);
|
|
251
252
|
}
|
|
252
253
|
async getWineRecommendations(n) {
|
|
254
|
+
console.log(window.location.href);
|
|
253
255
|
try {
|
|
254
|
-
const
|
|
256
|
+
const e = await fetch(this.apiEndpoint, {
|
|
255
257
|
method: "POST",
|
|
256
258
|
headers: {
|
|
257
259
|
"Content-Type": "application/json"
|
|
258
260
|
},
|
|
259
|
-
body: JSON.stringify({ text: n })
|
|
260
|
-
}),
|
|
261
|
-
if (!
|
|
262
|
-
throw new Error(`API call failed with status ${
|
|
263
|
-
return
|
|
264
|
-
} catch (
|
|
265
|
-
throw console.error("Fetching wine recommendations failed:",
|
|
261
|
+
body: JSON.stringify({ text: n, store: this.store ? this.store.toString().charAt(0).toUpperCase() + this.store.slice(1) : void 0 })
|
|
262
|
+
}), t = await e.json();
|
|
263
|
+
if (!e.ok)
|
|
264
|
+
throw new Error(`API call failed with status ${e.status}: ${t.message || "No additional error information"}`);
|
|
265
|
+
return t;
|
|
266
|
+
} catch (e) {
|
|
267
|
+
throw console.error("Fetching wine recommendations failed:", e.message), new Error(`Error in getWineRecommendations: ${e.message}`);
|
|
266
268
|
}
|
|
267
269
|
}
|
|
268
270
|
}
|
|
269
|
-
class
|
|
271
|
+
class u {
|
|
270
272
|
constructor() {
|
|
271
|
-
this.api = new
|
|
273
|
+
this.api = new h();
|
|
272
274
|
}
|
|
273
275
|
initialize() {
|
|
274
|
-
document.getElementById("send-button").addEventListener("click", () => this.handleUserInput()), document.getElementById("user-input").addEventListener("keypress", (
|
|
275
|
-
|
|
276
|
+
document.getElementById("send-button").addEventListener("click", () => this.handleUserInput()), document.getElementById("user-input").addEventListener("keypress", (t) => {
|
|
277
|
+
t.key === "Enter" && this.handleUserInput();
|
|
276
278
|
});
|
|
277
279
|
}
|
|
278
280
|
async handleUserInput() {
|
|
279
|
-
const n = document.getElementById("user-input"),
|
|
280
|
-
if (
|
|
281
|
-
this.displayMessage(
|
|
281
|
+
const n = document.getElementById("user-input"), e = n.value.trim();
|
|
282
|
+
if (e) {
|
|
283
|
+
this.displayMessage(e, "user"), n.value = "", this.showTypingIndicator();
|
|
282
284
|
try {
|
|
283
|
-
const
|
|
284
|
-
this.hideTypingIndicator(),
|
|
285
|
-
} catch (
|
|
286
|
-
this.hideTypingIndicator(), console.error("Error fetching wine recommendations:",
|
|
285
|
+
const t = await this.api.getWineRecommendations(e);
|
|
286
|
+
this.hideTypingIndicator(), t && t.length ? this.displayResults(t) : this.displayMessage("No results found.", "api");
|
|
287
|
+
} catch (t) {
|
|
288
|
+
this.hideTypingIndicator(), console.error("Error fetching wine recommendations:", t), this.displayMessage("Sorry, something went wrong.", "api");
|
|
287
289
|
}
|
|
288
290
|
}
|
|
289
291
|
}
|
|
@@ -293,26 +295,26 @@ class h {
|
|
|
293
295
|
hideTypingIndicator() {
|
|
294
296
|
document.getElementById("typing-indicator").classList.remove("visible");
|
|
295
297
|
}
|
|
296
|
-
displayMessage(n,
|
|
297
|
-
const
|
|
298
|
-
o.textContent = n, o.className = "message " +
|
|
298
|
+
displayMessage(n, e) {
|
|
299
|
+
const t = document.getElementById("message-container"), o = document.createElement("div");
|
|
300
|
+
o.textContent = n, o.className = "message " + e, t.appendChild(o), t.scrollTop = t.scrollHeight;
|
|
299
301
|
}
|
|
300
302
|
displayResults(n) {
|
|
301
|
-
const
|
|
302
|
-
n.forEach((
|
|
303
|
+
const e = document.getElementById("message-container");
|
|
304
|
+
n.forEach((t) => {
|
|
303
305
|
const o = document.createElement("div");
|
|
304
306
|
o.className = "wine-item";
|
|
305
|
-
const
|
|
306
|
-
|
|
307
|
-
const
|
|
308
|
-
|
|
309
|
-
}),
|
|
307
|
+
const s = document.createElement("img");
|
|
308
|
+
s.src = t.Image, o.appendChild(s);
|
|
309
|
+
const a = document.createElement("div");
|
|
310
|
+
a.innerHTML = `<strong>${t.Title}</strong><br>Price: ${t.Price}<br>Region: ${t.Region}<br>Type: ${t.Type}<br><a href="${t.Url}" target="_blank">More Info</a>`, o.appendChild(a), e.appendChild(o);
|
|
311
|
+
}), e.scrollTop = e.scrollHeight;
|
|
310
312
|
}
|
|
311
313
|
}
|
|
312
314
|
document.addEventListener("DOMContentLoaded", () => {
|
|
313
315
|
window.toggleChatWindow = d, window.closeChatWindow = l, window.openChatWindow = p;
|
|
314
316
|
});
|
|
315
|
-
function
|
|
317
|
+
function m() {
|
|
316
318
|
document.body.insertAdjacentHTML("beforeend", `
|
|
317
319
|
<div id="chatbot-container">
|
|
318
320
|
<div id="chat-icon" onclick="toggleChatWindow()">
|
|
@@ -336,17 +338,17 @@ function u() {
|
|
|
336
338
|
</div>
|
|
337
339
|
`);
|
|
338
340
|
}
|
|
339
|
-
function
|
|
341
|
+
function b() {
|
|
340
342
|
document.getElementById("close-btn").addEventListener("click", d);
|
|
341
343
|
}
|
|
342
|
-
function
|
|
344
|
+
function f() {
|
|
343
345
|
window.addEventListener("click", function(i) {
|
|
344
|
-
const n = document.getElementById("chat-window"),
|
|
345
|
-
!n.contains(i.target) && !
|
|
346
|
+
const n = document.getElementById("chat-window"), e = document.getElementById("chat-icon");
|
|
347
|
+
!n.contains(i.target) && !e.contains(i.target) && n.classList.remove("visible");
|
|
346
348
|
});
|
|
347
349
|
}
|
|
348
350
|
typeof window < "u" && window.addEventListener("DOMContentLoaded", () => {
|
|
349
|
-
|
|
351
|
+
m(), b(), f(), new u().initialize();
|
|
350
352
|
});
|
|
351
353
|
export {
|
|
352
354
|
l as closeChatWindow,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(o,
|
|
1
|
+
(function(o,a){typeof exports=="object"&&typeof module<"u"?a(exports):typeof define=="function"&&define.amd?define(["exports"],a):(o=typeof globalThis<"u"?globalThis:o||self,a(o.WineaterChatbot={}))})(this,function(o){"use strict";const a=`
|
|
2
2
|
@font-face {
|
|
3
3
|
font-family: 'Poppins';
|
|
4
4
|
src: url('https://fonts.googleapis.com/css2?family=Poppins:wght@400&display=swap');
|
|
@@ -230,7 +230,7 @@
|
|
|
230
230
|
overflow-y: auto;
|
|
231
231
|
height: 300px; /* adjust based on your UI needs */
|
|
232
232
|
padding: 10px;
|
|
233
|
-
}`,
|
|
233
|
+
}`,d=document.createElement("style");d.textContent=a,document.head.appendChild(d);function r(){document.getElementById("chat-window").classList.toggle("visible")}function c(){document.getElementById("chat-window").classList.remove("visible")}function l(){document.getElementById("chat-window").classList.add("visible")}document.addEventListener("DOMContentLoaded",()=>{setupCloseButton(),setupOutsideClick()});const g=["climats","telckel","biobio"];class u{constructor(n){this.apiEndpoint=n||"https://api.wineater.com/dish/recommendations",this.store=g.find(e=>window.location.href.includes(e)),console.log(this.store)}async getWineRecommendations(n){console.log(window.location.href);try{const e=await fetch(this.apiEndpoint,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:n,store:this.store?this.store.toString().charAt(0).toUpperCase()+this.store.slice(1):void 0})}),t=await e.json();if(!e.ok)throw new Error(`API call failed with status ${e.status}: ${t.message||"No additional error information"}`);return t}catch(e){throw console.error("Fetching wine recommendations failed:",e.message),new Error(`Error in getWineRecommendations: ${e.message}`)}}}class m{constructor(){this.api=new u}initialize(){document.getElementById("send-button").addEventListener("click",()=>this.handleUserInput()),document.getElementById("user-input").addEventListener("keypress",t=>{t.key==="Enter"&&this.handleUserInput()})}async handleUserInput(){const n=document.getElementById("user-input"),e=n.value.trim();if(e){this.displayMessage(e,"user"),n.value="",this.showTypingIndicator();try{const t=await this.api.getWineRecommendations(e);this.hideTypingIndicator(),t&&t.length?this.displayResults(t):this.displayMessage("No results found.","api")}catch(t){this.hideTypingIndicator(),console.error("Error fetching wine recommendations:",t),this.displayMessage("Sorry, something went wrong.","api")}}}showTypingIndicator(){document.getElementById("typing-indicator").classList.add("visible")}hideTypingIndicator(){document.getElementById("typing-indicator").classList.remove("visible")}displayMessage(n,e){const t=document.getElementById("message-container"),s=document.createElement("div");s.textContent=n,s.className="message "+e,t.appendChild(s),t.scrollTop=t.scrollHeight}displayResults(n){const e=document.getElementById("message-container");n.forEach(t=>{const s=document.createElement("div");s.className="wine-item";const p=document.createElement("img");p.src=t.Image,s.appendChild(p);const h=document.createElement("div");h.innerHTML=`<strong>${t.Title}</strong><br>Price: ${t.Price}<br>Region: ${t.Region}<br>Type: ${t.Type}<br><a href="${t.Url}" target="_blank">More Info</a>`,s.appendChild(h),e.appendChild(s)}),e.scrollTop=e.scrollHeight}}document.addEventListener("DOMContentLoaded",()=>{window.toggleChatWindow=r,window.closeChatWindow=c,window.openChatWindow=l});function b(){document.body.insertAdjacentHTML("beforeend",`
|
|
234
234
|
<div id="chatbot-container">
|
|
235
235
|
<div id="chat-icon" onclick="toggleChatWindow()">
|
|
236
236
|
<img src="https://landing-static.s3.eu-central-1.amazonaws.com/images/chat-icon.svg" alt="Chat Icon">
|
|
@@ -251,4 +251,4 @@
|
|
|
251
251
|
</div>
|
|
252
252
|
</div>
|
|
253
253
|
</div>
|
|
254
|
-
`)}function
|
|
254
|
+
`)}function f(){document.getElementById("close-btn").addEventListener("click",r)}function y(){window.addEventListener("click",function(i){const n=document.getElementById("chat-window"),e=document.getElementById("chat-icon");!n.contains(i.target)&&!e.contains(i.target)&&n.classList.remove("visible")})}typeof window<"u"&&window.addEventListener("DOMContentLoaded",()=>{b(),f(),y(),new m().initialize()}),o.closeChatWindow=c,o.openChatWindow=l,o.toggleChatWindow=r,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});
|
package/index.html
CHANGED
|
@@ -4,7 +4,9 @@
|
|
|
4
4
|
<meta charset="UTF-8">
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
6
|
<title>Chatbot</title>
|
|
7
|
-
<script src="https://unpkg.com/wineater-bot@
|
|
7
|
+
<!-- <script type="module" src="https://unpkg.com/wineater-bot@1.0.0/dist/wineater-chatbot.umd.js"></script> -->
|
|
8
|
+
<script type="module" src="./src/index.js"></script>
|
|
9
|
+
|
|
8
10
|
</head>
|
|
9
11
|
<body>
|
|
10
12
|
</body>
|
package/package.json
CHANGED
package/src/js/api.js
CHANGED
|
@@ -1,19 +1,24 @@
|
|
|
1
1
|
// api.js
|
|
2
2
|
|
|
3
|
+
const stores = ['climats', 'telckel', 'biobio'];
|
|
4
|
+
|
|
3
5
|
export class Api {
|
|
4
6
|
constructor(apiEndpoint) {
|
|
5
7
|
// Allow users of the library to specify their own endpoint if needed
|
|
6
8
|
this.apiEndpoint = apiEndpoint || 'https://api.wineater.com/dish/recommendations';
|
|
9
|
+
this.store = stores.find(value => window.location.href.includes(value));
|
|
10
|
+
console.log(this.store);
|
|
7
11
|
}
|
|
8
12
|
|
|
9
13
|
async getWineRecommendations(text) {
|
|
14
|
+
console.log(window.location.href);
|
|
10
15
|
try {
|
|
11
16
|
const response = await fetch(this.apiEndpoint, {
|
|
12
17
|
method: 'POST',
|
|
13
18
|
headers: {
|
|
14
19
|
'Content-Type': 'application/json'
|
|
15
20
|
},
|
|
16
|
-
body: JSON.stringify({ text: text })
|
|
21
|
+
body: JSON.stringify({ text: text, store: this.store ? (this.store.toString().charAt(0).toUpperCase() + this.store.slice(1)) : undefined})
|
|
17
22
|
});
|
|
18
23
|
|
|
19
24
|
const data = await response.json();
|