robodialog 0.1.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 +14 -0
- package/dist/index.d.ts +59 -0
- package/dist/index.html +93 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/index.umd.cjs +2 -0
- package/dist/index.umd.cjs.map +1 -0
- package/dist/widget.js +105 -0
- package/dist/widget.js.map +1 -0
- package/package.json +45 -0
package/README.md
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Initializes and injects the RoboDialog chat widget into the page.
|
|
3
|
+
*
|
|
4
|
+
* This function creates a script tag that loads the widget code and appends it to the document body.
|
|
5
|
+
* It returns a cleanup function that removes the widget and the script tag.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { Chat } from 'robodialog';
|
|
10
|
+
*
|
|
11
|
+
* // 1. Basic usage
|
|
12
|
+
* Chat({
|
|
13
|
+
* chatbotId: 'your-chatbot-id'
|
|
14
|
+
* });
|
|
15
|
+
*
|
|
16
|
+
* // 2. With authenticated user data
|
|
17
|
+
* Chat({
|
|
18
|
+
* chatbotId: 'your-chatbot-id',
|
|
19
|
+
* userId: 'user-123',
|
|
20
|
+
* email: 'user@example.com'
|
|
21
|
+
* });
|
|
22
|
+
*
|
|
23
|
+
* // 3. Usage in a React useEffect hook
|
|
24
|
+
* useEffect(() => {
|
|
25
|
+
* const cleanup = Chat({
|
|
26
|
+
* chatbotId: 'your-chatbot-id'
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* // Cleanup on unmount
|
|
30
|
+
* return cleanup;
|
|
31
|
+
* }, []);
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @param options - Configuration options for the chatbot widget.
|
|
35
|
+
* @returns A function that destroys the widget and removes the script tag when called.
|
|
36
|
+
*/
|
|
37
|
+
declare function Chat(options: ChatbotLoaderOptions): () => void;
|
|
38
|
+
export { Chat }
|
|
39
|
+
export default Chat;
|
|
40
|
+
|
|
41
|
+
export declare interface ChatbotLoaderOptions {
|
|
42
|
+
/** The unique identifier for your chatbot. You can find this in your RoboDialog dashboard. */
|
|
43
|
+
chatbotId: string;
|
|
44
|
+
/** Optional: The ID of the currently logged-in user to sync conversation history. */
|
|
45
|
+
userId?: string;
|
|
46
|
+
/** Optional: The email of the user for lead capture or identification. */
|
|
47
|
+
email?: string;
|
|
48
|
+
/** Optional: A bearer token if your API requires needs authentication. */
|
|
49
|
+
bearer?: string;
|
|
50
|
+
/** Optional: Set to true to open the chatbot in full screen mode. */
|
|
51
|
+
fullScreen?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Optional: Override the default widget script URL.
|
|
54
|
+
* Use this to pin a specific version or load from a custom domain.
|
|
55
|
+
*/
|
|
56
|
+
widgetUrl?: string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export { }
|
package/dist/index.html
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title>Preact Widget Demo</title>
|
|
7
|
+
<style>
|
|
8
|
+
body {
|
|
9
|
+
font-family: Arial, sans-serif;
|
|
10
|
+
max-width: 800px;
|
|
11
|
+
margin: 0 auto;
|
|
12
|
+
padding: 20px;
|
|
13
|
+
}
|
|
14
|
+
.widget-container {
|
|
15
|
+
margin: 20px 0;
|
|
16
|
+
padding: 20px;
|
|
17
|
+
border: 1px solid #ddd;
|
|
18
|
+
border-radius: 8px;
|
|
19
|
+
}
|
|
20
|
+
.widget.light {
|
|
21
|
+
background-color: #fff;
|
|
22
|
+
color: #333;
|
|
23
|
+
}
|
|
24
|
+
.widget.dark {
|
|
25
|
+
background-color: #333;
|
|
26
|
+
color: #fff;
|
|
27
|
+
}
|
|
28
|
+
button {
|
|
29
|
+
padding: 8px 16px;
|
|
30
|
+
background-color: #007bff;
|
|
31
|
+
color: white;
|
|
32
|
+
border: none;
|
|
33
|
+
border-radius: 4px;
|
|
34
|
+
cursor: pointer;
|
|
35
|
+
}
|
|
36
|
+
button:hover {
|
|
37
|
+
background-color: #0056b3;
|
|
38
|
+
}
|
|
39
|
+
pre {
|
|
40
|
+
background-color: #f5f5f5;
|
|
41
|
+
padding: 15px;
|
|
42
|
+
border-radius: 4px;
|
|
43
|
+
overflow-x: auto;
|
|
44
|
+
}
|
|
45
|
+
</style>
|
|
46
|
+
</head>
|
|
47
|
+
<body>
|
|
48
|
+
<h1>Preact Widget Demo</h1>
|
|
49
|
+
|
|
50
|
+
<h2>Auto-initialized Widget</h2>
|
|
51
|
+
<div id="widget-1" data-widget data-title="Auto Widget" data-theme="light">
|
|
52
|
+
<!-- Widget will be rendered here -->
|
|
53
|
+
</div>
|
|
54
|
+
|
|
55
|
+
<h2>Programmatic Initialization</h2>
|
|
56
|
+
<div id="widget-2">
|
|
57
|
+
<!-- Widget will be rendered here -->
|
|
58
|
+
</div>
|
|
59
|
+
<button id="init-widget">Initialize Widget</button>
|
|
60
|
+
|
|
61
|
+
<h2>How to use</h2>
|
|
62
|
+
<h3>Auto-initialization</h3>
|
|
63
|
+
<pre><code><div id="my-widget" data-widget data-title="My Widget" data-theme="dark"></div>
|
|
64
|
+
<script src="path/to/my-widget.umd.js"></script></code></pre>
|
|
65
|
+
|
|
66
|
+
<h3>Programmatic Initialization</h3>
|
|
67
|
+
<pre><code><div id="my-widget"></div>
|
|
68
|
+
<script src="path/to/my-widget.umd.js"></script>
|
|
69
|
+
<script>
|
|
70
|
+
window.MyWidget.init({
|
|
71
|
+
container: 'my-widget',
|
|
72
|
+
title: 'My Widget',
|
|
73
|
+
theme: 'light' // or 'dark'
|
|
74
|
+
});
|
|
75
|
+
</script></code></pre>
|
|
76
|
+
|
|
77
|
+
<!-- Load Preact as a peer dependency -->
|
|
78
|
+
<script src="https://unpkg.com/preact@10.19.0/dist/preact.umd.js"></script>
|
|
79
|
+
<!-- Load the widget -->
|
|
80
|
+
<script src="/dist/my-widget.umd.js"></script>
|
|
81
|
+
|
|
82
|
+
<script>
|
|
83
|
+
// Programmatic initialization example
|
|
84
|
+
document.getElementById('init-widget').addEventListener('click', () => {
|
|
85
|
+
window.MyWidget.init({
|
|
86
|
+
container: 'widget-2',
|
|
87
|
+
title: 'Programmatic Widget',
|
|
88
|
+
theme: 'dark'
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
</script>
|
|
92
|
+
</body>
|
|
93
|
+
</html>
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
function d(t) {
|
|
2
|
+
if (!t.chatbotId)
|
|
3
|
+
throw new Error("[RoboDialog] chatbotId is required");
|
|
4
|
+
if (document.getElementById("my-chatbot-root"))
|
|
5
|
+
return console.warn("[RoboDialog] Widget is already loaded. Skipping."), () => {
|
|
6
|
+
};
|
|
7
|
+
const e = document.createElement("script");
|
|
8
|
+
e.src = t.widgetUrl || "https://cdn.jsdelivr.net/npm/robodialog/dist/widget.js", e.dataset.chatbotId = t.chatbotId, t.userId && (e.dataset.userId = t.userId), t.email && (e.dataset.email = t.email), t.bearer && (e.dataset.bearer = t.bearer), t.fullScreen && (e.dataset.fullScreen = "true");
|
|
9
|
+
let r = !1;
|
|
10
|
+
return e.onload = () => {
|
|
11
|
+
r = !0;
|
|
12
|
+
}, e.onerror = () => {
|
|
13
|
+
console.error("[RoboDialog] Failed to load widget from", e.src), e.remove();
|
|
14
|
+
}, document.body.appendChild(e), () => {
|
|
15
|
+
r || (e.onload = null, e.onerror = null), e.remove();
|
|
16
|
+
const o = document.getElementById("my-chatbot-root");
|
|
17
|
+
o && o.remove(), console.log("[RoboDialog] Widget removed");
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
d as Chat,
|
|
22
|
+
d as default
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/index.tsx"],"sourcesContent":["export interface ChatbotLoaderOptions {\r\n /** The unique identifier for your chatbot. You can find this in your RoboDialog dashboard. */\r\n chatbotId: string;\r\n /** Optional: The ID of the currently logged-in user to sync conversation history. */\r\n userId?: string;\r\n /** Optional: The email of the user for lead capture or identification. */\r\n email?: string;\r\n /** Optional: A bearer token if your API requires needs authentication. */\r\n bearer?: string;\r\n /** Optional: Set to true to open the chatbot in full screen mode. */\r\n fullScreen?: boolean;\r\n /** \r\n * Optional: Override the default widget script URL.\r\n * Use this to pin a specific version or load from a custom domain.\r\n */\r\n widgetUrl?: string;\r\n}\r\n\r\n/**\r\n * Initializes and injects the RoboDialog chat widget into the page.\r\n * \r\n * This function creates a script tag that loads the widget code and appends it to the document body.\r\n * It returns a cleanup function that removes the widget and the script tag.\r\n * \r\n * @example\r\n * ```typescript\r\n * import { Chat } from 'robodialog';\r\n * \r\n * // 1. Basic usage\r\n * Chat({\r\n * chatbotId: 'your-chatbot-id'\r\n * });\r\n * \r\n * // 2. With authenticated user data\r\n * Chat({\r\n * chatbotId: 'your-chatbot-id',\r\n * userId: 'user-123',\r\n * email: 'user@example.com'\r\n * });\r\n * \r\n * // 3. Usage in a React useEffect hook\r\n * useEffect(() => {\r\n * const cleanup = Chat({\r\n * chatbotId: 'your-chatbot-id'\r\n * });\r\n * \r\n * // Cleanup on unmount\r\n * return cleanup;\r\n * }, []);\r\n * ```\r\n * \r\n * @param options - Configuration options for the chatbot widget.\r\n * @returns A function that destroys the widget and removes the script tag when called.\r\n */\r\nexport function Chat(options: ChatbotLoaderOptions): () => void {\r\n // Validate required options\r\n if (!options.chatbotId) {\r\n throw new Error('[RoboDialog] chatbotId is required');\r\n }\r\n\r\n // Check if widget is already loaded\r\n const existingContainer = document.getElementById('my-chatbot-root');\r\n if (existingContainer) {\r\n console.warn('[RoboDialog] Widget is already loaded. Skipping.');\r\n return () => {};\r\n }\r\n\r\n // Create script element\r\n const script = document.createElement('script');\r\n \r\n // Set script source with default CDN\r\n script.src = options.widgetUrl || 'https://cdn.jsdelivr.net/npm/robodialog/dist/widget.js';\r\n \r\n // Set required data attribute\r\n script.dataset.chatbotId = options.chatbotId;\r\n \r\n // Set optional data attributes\r\n if (options.userId) {\r\n script.dataset.userId = options.userId;\r\n }\r\n \r\n if (options.email) {\r\n script.dataset.email = options.email;\r\n }\r\n \r\n if (options.bearer) {\r\n script.dataset.bearer = options.bearer;\r\n }\r\n\r\n if (options.fullScreen) {\r\n script.dataset.fullScreen = 'true';\r\n }\r\n\r\n // Add error handling\r\n let isLoaded = false;\r\n script.onload = () => {\r\n isLoaded = true;\r\n };\r\n \r\n script.onerror = () => {\r\n console.error('[RoboDialog] Failed to load widget from', script.src);\r\n script.remove();\r\n };\r\n\r\n // Append to document body\r\n document.body.appendChild(script);\r\n\r\n // Return cleanup function\r\n return () => {\r\n // Remove event listeners if not loaded yet\r\n if (!isLoaded) {\r\n script.onload = null;\r\n script.onerror = null;\r\n }\r\n \r\n // Remove script tag\r\n script.remove();\r\n \r\n // Remove container div created by the widget\r\n const container = document.getElementById('my-chatbot-root');\r\n if (container) {\r\n container.remove();\r\n }\r\n \r\n console.log('[RoboDialog] Widget removed');\r\n };\r\n}\r\n\r\n// Default export for convenience\r\nexport default Chat;"],"names":["Chat","options","script","isLoaded","container"],"mappings":"AAsDO,SAASA,EAAKC,GAA2C;AAE9D,MAAI,CAACA,EAAQ;AACX,UAAM,IAAI,MAAM,oCAAoC;AAKtD,MAD0B,SAAS,eAAe,iBAAiB;AAEjE,mBAAQ,KAAK,kDAAkD,GACxD,MAAM;AAAA,IAAC;AAIhB,QAAMC,IAAS,SAAS,cAAc,QAAQ;AAG9C,EAAAA,EAAO,MAAMD,EAAQ,aAAa,0DAGlCC,EAAO,QAAQ,YAAYD,EAAQ,WAG/BA,EAAQ,WACVC,EAAO,QAAQ,SAASD,EAAQ,SAG9BA,EAAQ,UACVC,EAAO,QAAQ,QAAQD,EAAQ,QAG7BA,EAAQ,WACVC,EAAO,QAAQ,SAASD,EAAQ,SAG9BA,EAAQ,eACVC,EAAO,QAAQ,aAAa;AAI9B,MAAIC,IAAW;AACf,SAAAD,EAAO,SAAS,MAAM;AACpB,IAAAC,IAAW;AAAA,EACb,GAEAD,EAAO,UAAU,MAAM;AACrB,YAAQ,MAAM,2CAA2CA,EAAO,GAAG,GACnEA,EAAO,OAAA;AAAA,EACT,GAGA,SAAS,KAAK,YAAYA,CAAM,GAGzB,MAAM;AAEX,IAAKC,MACHD,EAAO,SAAS,MAChBA,EAAO,UAAU,OAInBA,EAAO,OAAA;AAGP,UAAME,IAAY,SAAS,eAAe,iBAAiB;AAC3D,IAAIA,KACFA,EAAU,OAAA,GAGZ,QAAQ,IAAI,6BAA6B;AAAA,EAC3C;AACF;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
(function(o,r){typeof exports=="object"&&typeof module<"u"?r(exports):typeof define=="function"&&define.amd?define(["exports"],r):(o=typeof globalThis<"u"?globalThis:o||self,r(o.RoboDialog={}))})(this,function(o){"use strict";function r(t){if(!t.chatbotId)throw new Error("[RoboDialog] chatbotId is required");if(document.getElementById("my-chatbot-root"))return console.warn("[RoboDialog] Widget is already loaded. Skipping."),()=>{};const e=document.createElement("script");e.src=t.widgetUrl||"https://cdn.jsdelivr.net/npm/robodialog/dist/widget.js",e.dataset.chatbotId=t.chatbotId,t.userId&&(e.dataset.userId=t.userId),t.email&&(e.dataset.email=t.email),t.bearer&&(e.dataset.bearer=t.bearer),t.fullScreen&&(e.dataset.fullScreen="true");let d=!1;return e.onload=()=>{d=!0},e.onerror=()=>{console.error("[RoboDialog] Failed to load widget from",e.src),e.remove()},document.body.appendChild(e),()=>{d||(e.onload=null,e.onerror=null),e.remove();const a=document.getElementById("my-chatbot-root");a&&a.remove(),console.log("[RoboDialog] Widget removed")}}o.Chat=r,o.default=r,Object.defineProperties(o,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
2
|
+
//# sourceMappingURL=index.umd.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.umd.cjs","sources":["../src/index.tsx"],"sourcesContent":["export interface ChatbotLoaderOptions {\r\n /** The unique identifier for your chatbot. You can find this in your RoboDialog dashboard. */\r\n chatbotId: string;\r\n /** Optional: The ID of the currently logged-in user to sync conversation history. */\r\n userId?: string;\r\n /** Optional: The email of the user for lead capture or identification. */\r\n email?: string;\r\n /** Optional: A bearer token if your API requires needs authentication. */\r\n bearer?: string;\r\n /** Optional: Set to true to open the chatbot in full screen mode. */\r\n fullScreen?: boolean;\r\n /** \r\n * Optional: Override the default widget script URL.\r\n * Use this to pin a specific version or load from a custom domain.\r\n */\r\n widgetUrl?: string;\r\n}\r\n\r\n/**\r\n * Initializes and injects the RoboDialog chat widget into the page.\r\n * \r\n * This function creates a script tag that loads the widget code and appends it to the document body.\r\n * It returns a cleanup function that removes the widget and the script tag.\r\n * \r\n * @example\r\n * ```typescript\r\n * import { Chat } from 'robodialog';\r\n * \r\n * // 1. Basic usage\r\n * Chat({\r\n * chatbotId: 'your-chatbot-id'\r\n * });\r\n * \r\n * // 2. With authenticated user data\r\n * Chat({\r\n * chatbotId: 'your-chatbot-id',\r\n * userId: 'user-123',\r\n * email: 'user@example.com'\r\n * });\r\n * \r\n * // 3. Usage in a React useEffect hook\r\n * useEffect(() => {\r\n * const cleanup = Chat({\r\n * chatbotId: 'your-chatbot-id'\r\n * });\r\n * \r\n * // Cleanup on unmount\r\n * return cleanup;\r\n * }, []);\r\n * ```\r\n * \r\n * @param options - Configuration options for the chatbot widget.\r\n * @returns A function that destroys the widget and removes the script tag when called.\r\n */\r\nexport function Chat(options: ChatbotLoaderOptions): () => void {\r\n // Validate required options\r\n if (!options.chatbotId) {\r\n throw new Error('[RoboDialog] chatbotId is required');\r\n }\r\n\r\n // Check if widget is already loaded\r\n const existingContainer = document.getElementById('my-chatbot-root');\r\n if (existingContainer) {\r\n console.warn('[RoboDialog] Widget is already loaded. Skipping.');\r\n return () => {};\r\n }\r\n\r\n // Create script element\r\n const script = document.createElement('script');\r\n \r\n // Set script source with default CDN\r\n script.src = options.widgetUrl || 'https://cdn.jsdelivr.net/npm/robodialog/dist/widget.js';\r\n \r\n // Set required data attribute\r\n script.dataset.chatbotId = options.chatbotId;\r\n \r\n // Set optional data attributes\r\n if (options.userId) {\r\n script.dataset.userId = options.userId;\r\n }\r\n \r\n if (options.email) {\r\n script.dataset.email = options.email;\r\n }\r\n \r\n if (options.bearer) {\r\n script.dataset.bearer = options.bearer;\r\n }\r\n\r\n if (options.fullScreen) {\r\n script.dataset.fullScreen = 'true';\r\n }\r\n\r\n // Add error handling\r\n let isLoaded = false;\r\n script.onload = () => {\r\n isLoaded = true;\r\n };\r\n \r\n script.onerror = () => {\r\n console.error('[RoboDialog] Failed to load widget from', script.src);\r\n script.remove();\r\n };\r\n\r\n // Append to document body\r\n document.body.appendChild(script);\r\n\r\n // Return cleanup function\r\n return () => {\r\n // Remove event listeners if not loaded yet\r\n if (!isLoaded) {\r\n script.onload = null;\r\n script.onerror = null;\r\n }\r\n \r\n // Remove script tag\r\n script.remove();\r\n \r\n // Remove container div created by the widget\r\n const container = document.getElementById('my-chatbot-root');\r\n if (container) {\r\n container.remove();\r\n }\r\n \r\n console.log('[RoboDialog] Widget removed');\r\n };\r\n}\r\n\r\n// Default export for convenience\r\nexport default Chat;"],"names":["Chat","options","script","isLoaded","container"],"mappings":"kOAsDO,SAASA,EAAKC,EAA2C,CAE9D,GAAI,CAACA,EAAQ,UACX,MAAM,IAAI,MAAM,oCAAoC,EAKtD,GAD0B,SAAS,eAAe,iBAAiB,EAEjE,eAAQ,KAAK,kDAAkD,EACxD,IAAM,CAAC,EAIhB,MAAMC,EAAS,SAAS,cAAc,QAAQ,EAG9CA,EAAO,IAAMD,EAAQ,WAAa,yDAGlCC,EAAO,QAAQ,UAAYD,EAAQ,UAG/BA,EAAQ,SACVC,EAAO,QAAQ,OAASD,EAAQ,QAG9BA,EAAQ,QACVC,EAAO,QAAQ,MAAQD,EAAQ,OAG7BA,EAAQ,SACVC,EAAO,QAAQ,OAASD,EAAQ,QAG9BA,EAAQ,aACVC,EAAO,QAAQ,WAAa,QAI9B,IAAIC,EAAW,GACf,OAAAD,EAAO,OAAS,IAAM,CACpBC,EAAW,EACb,EAEAD,EAAO,QAAU,IAAM,CACrB,QAAQ,MAAM,0CAA2CA,EAAO,GAAG,EACnEA,EAAO,OAAA,CACT,EAGA,SAAS,KAAK,YAAYA,CAAM,EAGzB,IAAM,CAENC,IACHD,EAAO,OAAS,KAChBA,EAAO,QAAU,MAInBA,EAAO,OAAA,EAGP,MAAME,EAAY,SAAS,eAAe,iBAAiB,EACvDA,GACFA,EAAU,OAAA,EAGZ,QAAQ,IAAI,6BAA6B,CAC3C,CACF"}
|