shopify-chatbot-widget 0.4.3 → 0.4.5

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.
@@ -0,0 +1,93 @@
1
+ (() => {
2
+ // ----- Read config from attributes -----
3
+ const currentScript = document.currentScript || document.querySelector('script[data-company][src*="jaweb-chatbot"]');
4
+ if (!currentScript) return console.warn('[Jaweb] install script not found');
5
+ const company = (currentScript.getAttribute('data-company') || '').trim();
6
+ if (!company) return console.error('[Jaweb] data-company is required');
7
+
8
+ const apiBase = currentScript.getAttribute('data-src') || 'https://jawebcrm.onrender.com/api/proxy/iframe';
9
+ const corner = currentScript.getAttribute('data-corner') || 'right'; // 'right' | 'left'
10
+ const openWidth = currentScript.getAttribute('data-open-width') || '400px';
11
+ const openHeight = currentScript.getAttribute('data-open-height') || '95%';
12
+ const mobileSheetVh = currentScript.getAttribute('data-mobile-vh') || '100%'; // leave some page visible
13
+
14
+ // ----- Make styles -----
15
+ const style = document.createElement('style');
16
+ style.textContent = `
17
+ #jaweb-chatbot-iframe {
18
+ position: fixed;
19
+ ${corner === 'left' ? 'left' : 'right'}: 16px;
20
+ bottom: 16px;
21
+ z-index: 2147483647;
22
+ border: 0;
23
+ transition: width .2s, height .2s, border-radius .2s, inset .2s, box-shadow .2s;
24
+ overflow: hidden;
25
+ background: transparent;
26
+ }
27
+
28
+ #jaweb-chatbot-iframe.is-open {
29
+ width: ${openWidth}; height: ${openHeight};
30
+ border-radius: 16px;
31
+ box-shadow: 0 10px 30px rgba(0,0,0,.15);
32
+ }
33
+ @media (max-width: 768px) {
34
+ #jaweb-chatbot-iframe.is-open {
35
+ left: 0; right: 0; bottom: 0; top: auto;
36
+ width: 100%; height: ${mobileSheetVh};
37
+ border-radius: 16px 16px 0 0;
38
+ box-shadow: 0 -10px 30px rgba(0,0,0,.15);
39
+ }
40
+
41
+ }
42
+ `;
43
+ document.head.appendChild(style);
44
+
45
+ // ----- Build iframe src -----
46
+ const params = new URLSearchParams({ company_username: company });
47
+ try {
48
+ const trackId = localStorage.getItem('track_id');
49
+ if (trackId) params.set('track_id', trackId);
50
+ localStorage.setItem('company_username', company);
51
+ } catch (_) {}
52
+
53
+ // ----- Create iframe -----
54
+ if (document.getElementById('jaweb-chatbot-iframe')) return;
55
+ const iframe = document.createElement('iframe');
56
+ iframe.id = 'jaweb-chatbot-iframe';
57
+ iframe.className = 'is-closed'; // start as bubble
58
+ iframe.src = `${apiBase}?${params.toString()}`;
59
+ iframe.allow = 'microphone; camera; autoplay; clipboard-write';
60
+ document.body.appendChild(iframe);
61
+
62
+ // Optional: ensure outside page stays scrollable
63
+ const unlockScroll = () => {
64
+ document.documentElement.style.overflow = '';
65
+ document.body.style.overflow = '';
66
+ document.body.style.position = '';
67
+ document.body.style.top = '';
68
+ ['modal-open','no-scroll','overflow-hidden','lock-scroll','js-focus-lock'].forEach(c => {
69
+ document.documentElement.classList.remove(c);
70
+ document.body.classList.remove(c);
71
+ });
72
+ };
73
+ requestAnimationFrame(unlockScroll);
74
+
75
+ // ----- Handshake with child -----
76
+ window.addEventListener('message', (e) => {
77
+ const msg = e.data || {};
78
+ if (msg.type !== 'JAWEB_CHAT') return;
79
+
80
+ if (msg.action === 'open') {
81
+ iframe.classList.remove('is-closed');
82
+ iframe.classList.add('is-open');
83
+ unlockScroll();
84
+ iframe.contentWindow?.postMessage({ type: 'JAWEB_CHAT', action: 'open-ready' }, '*');
85
+ } else if (msg.action === 'close') {
86
+ iframe.classList.remove('is-open');
87
+ iframe.classList.add('is-closed');
88
+ unlockScroll();
89
+ iframe.contentWindow?.postMessage({ type: 'JAWEB_CHAT', action: 'closed' }, '*');
90
+ }
91
+ });
92
+ })();
93
+
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "shopify-chatbot-widget",
3
3
  "private": false,
4
- "version": "0.4.3",
4
+ "version": "0.4.5",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "dev": "vite",
package/xx.html CHANGED
@@ -2,60 +2,55 @@
2
2
  <html lang="en">
3
3
  <head>
4
4
  <meta charset="UTF-8" />
5
- <title>Jaweb Chatbot Iframe Demo</title>
6
- <meta name="viewport" content="width=device-width, initial-scale=1" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <title>Jaweb Chatbot Test</title>
7
+ <style>
8
+ body {
9
+ font-family: Arial, sans-serif;
10
+ margin: 0;
11
+ padding: 0;
12
+ height: 200vh; /* make page scrollable */
13
+ background: linear-gradient(180deg, #f0f4ff 0%, #ffffff 100%);
14
+ }
15
+ header {
16
+ padding: 20px;
17
+ background: #7f28f8;
18
+ color: white;
19
+ text-align: center;
20
+ }
21
+ main {
22
+ padding: 20px;
23
+ max-width: 700px;
24
+ margin: 0 auto;
25
+ }
26
+ </style>
7
27
  </head>
8
28
  <body>
9
- <h1>Test page for Jaweb Chatbot</h1>
10
- <p>This page shows how your chatbot iframe will be injected, like Intercom.</p>
29
+ <header>
30
+ <h1>Jaweb Chatbot Integration Test</h1>
31
+ </header>
11
32
 
12
- <!-- Just load your script -->
13
- <script>
14
- (function () {
15
- // Configuration that you (or your users) can set
16
- const config = {
17
- shop: "your-shop.myshopify.com",
18
- widgetId: "YOUR_WIDGET_ID",
19
- apiBase: "https://api.your-domain.com",
20
- themeColor: "#7F28F8",
21
- position: "bottom-right",
22
- language: "en",
23
- };
33
+ <main>
34
+ <p>
35
+ Scroll this page up and down to make sure background scrolling still works
36
+ while the chatbot bubble is showing.
37
+ </p>
38
+ <p>
39
+ The bubble should appear at the bottom-right corner. Click it, and the
40
+ chatbot iframe should expand.
41
+ </p>
42
+ <p>
43
+ Replace <code>YOUR_COMPANY_USERNAME</code> below with a real one to test a
44
+ live bot session.
45
+ </p>
46
+ </main>
24
47
 
25
- // Create iframe
26
- const iframe = document.createElement("iframe");
27
- iframe.src =
28
- "../dist/iframe.html";
29
- iframe.style.position = "fixed";
30
- iframe.style.bottom = "20px";
31
- iframe.style.right = "20px";
32
- iframe.style.width = "400px";
33
- iframe.style.height = "600px";
34
- iframe.style.zIndex = "999999";
35
- iframe.style.borderRadius = "16px";
36
- iframe.style.border="none"
37
- iframe.id = "jaweb-chatbot-iframe";
48
+ <!-- Jaweb chatbot embed (script one-liner) -->
49
+ <script
50
+ src="https://cdn.jsdelivr.net/npm/shopify-chatbot-widget@0.4.5/dist/jawebDirect.js"
51
+ data-company="jaweb"
52
+ async
53
+ ></script>
38
54
 
39
- document.body.appendChild(iframe);
40
-
41
- // Pass config into iframe (postMessage)
42
- iframe.onload = function () {
43
- iframe.contentWindow.postMessage(
44
- { type: "jaweb:init", payload: config },
45
- "*"
46
- );
47
- };
48
-
49
- // (Optional) handle messages back from chatbot
50
- window.addEventListener("message", (e) => {
51
- if (e.data.type === "jaweb:ready") {
52
- console.log("Jaweb chatbot is ready!");
53
- }
54
- if (e.data.type === "jaweb:event") {
55
- console.log("Chatbot event:", e.data.payload);
56
- }
57
- });
58
- })();
59
- </script>
60
55
  </body>
61
56
  </html>