@schmitech/chatbot-widget 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 ADDED
@@ -0,0 +1,266 @@
1
+ # Chatbot Widget
2
+
3
+ A reusable chatbot widget that can be easily integrated into any website.
4
+
5
+ ## Features
6
+
7
+ - Easy to integrate with a single JavaScript snippet
8
+ - Responsive design with mobile support
9
+ - Customizable appearance
10
+ - Markdown support for rich text responses
11
+ - Link detection and formatting
12
+ - Scrollable chat interface with "scroll to top" button
13
+ - Clear conversation functionality
14
+
15
+ ## Building the Widget
16
+
17
+ ### Prerequisites
18
+
19
+ - Node.js 18+ and npm
20
+
21
+ ### Build Steps
22
+
23
+ 1. Clone the repository:
24
+ ```bash
25
+ git clone <repository-url>
26
+ cd qa-chatbot-server
27
+ ```
28
+
29
+ 2. Install dependencies for the API:
30
+ ```bash
31
+ cd api
32
+ npm install
33
+ npm run build
34
+ ```
35
+
36
+ 3. Build the widget:
37
+ ```bash
38
+ cd ../widget
39
+ npm install
40
+ npm run build
41
+ npm run build:bundle
42
+ ```
43
+
44
+ 4. The built files will be in the `widget/dist` directory:
45
+ - `chatbot-widget.bundle.js` - Single file containing both JS and CSS (recommended for direct usage)
46
+ - `chatbot-widget.umd.js` - UMD module (if you need the JS separately)
47
+ - `chatbot-widget.css` - Styles (if you need the CSS separately)
48
+
49
+ ## Usage
50
+
51
+ ### Using direct script tags
52
+
53
+ Add the following code to your website's HTML:
54
+
55
+ ```html
56
+ <!-- Include React and ReactDOM first -->
57
+ <script src="https://unpkg.com/react@18/umd/react.production.min.js" crossorigin></script>
58
+ <script src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js" crossorigin></script>
59
+ <!-- Include the bundled widget -->
60
+ <script src="path/to/chatbot-widget.bundle.js"></script>
61
+
62
+ <script>
63
+ // Initialize the widget when the page loads
64
+ window.addEventListener('load', function() {
65
+ window.initChatbotWidget({
66
+ apiUrl: 'https://your-api-server.com'
67
+ });
68
+ });
69
+ </script>
70
+ ```
71
+
72
+ ### Using npm
73
+
74
+ 1. Install the package:
75
+ ```bash
76
+ npm install chatbot-widget
77
+ ```
78
+
79
+ 2. Import in your application:
80
+ ```javascript
81
+ import { ChatWidget } from 'chatbot-widget';
82
+
83
+ // Use in your React component
84
+ function App() {
85
+ return (
86
+ <div className="App">
87
+ <ChatWidget />
88
+ </div>
89
+ );
90
+ }
91
+
92
+ // Set API URL via the exposed function
93
+ window.ChatbotWidget.setApiUrl('https://your-api-server.com');
94
+ ```
95
+
96
+ ### Advanced Usage
97
+
98
+ You can customize the widget by specifying a container:
99
+
100
+ ```html
101
+ <div id="my-chat-container"></div>
102
+
103
+ <script>
104
+ window.addEventListener('load', function() {
105
+ window.initChatbotWidget({
106
+ apiUrl: 'https://your-api-server.com',
107
+ containerSelector: '#my-chat-container'
108
+ });
109
+ });
110
+ </script>
111
+ ```
112
+
113
+ ## Customizing the Widget
114
+ Check file demo.html containing an working example on how to customize the widget.
115
+
116
+ To run the example:
117
+
118
+ ```python
119
+ python3 -m http.server 8080
120
+ ```
121
+
122
+ ## Deployment
123
+
124
+ 1. Host the bundled file (`chatbot-widget.bundle.js`) on a CDN or your web server
125
+ 2. Update the script tag in your HTML to point to the hosted file
126
+ 3. Make sure your chatbot API server is accessible at the URL you provide to `initChatbotWidget`
127
+
128
+ ## API Reference
129
+
130
+ ### initChatbotWidget(config)
131
+
132
+ Initializes the chatbot widget with the given configuration.
133
+
134
+ #### Parameters
135
+
136
+ - `config` (object):
137
+ - `apiUrl` (string, required): The URL of your chatbot API server
138
+ - `containerSelector` (string, optional): CSS selector for the container where the widget should be rendered. If not specified, the widget will be appended to the body.
139
+
140
+ ## Development
141
+
142
+ ```bash
143
+ # Start development server
144
+ npm run dev
145
+
146
+ # Run linting
147
+ npm run lint
148
+
149
+ # Build for production
150
+ npm run build
151
+ npm run build:bundle
152
+
153
+ # Preview build
154
+ npm run preview
155
+ ```
156
+
157
+ ## Publishing to npm
158
+
159
+ ### Option 1: Using npm link (for local development)
160
+
161
+ To use this widget in other projects on your local machine during development:
162
+
163
+ 1. In this widget directory, run:
164
+ ```bash
165
+ npm run build
166
+ npm run build:bundle
167
+ npm link
168
+ ```
169
+
170
+ 2. In your project directory, run:
171
+ ```bash
172
+ npm link chatbot-widget
173
+ ```
174
+
175
+ 3. Now you can import and use the widget in your project:
176
+ ```javascript
177
+ import { ChatWidget } from 'chatbot-widget';
178
+ ```
179
+
180
+ ### Option 2: Installing from a local directory
181
+
182
+ You can also install the package directly from the local directory:
183
+
184
+ 1. In this widget directory, run:
185
+ ```bash
186
+ npm run build
187
+ npm run build:bundle
188
+ ```
189
+
190
+ 2. In your project directory, run:
191
+ ```bash
192
+ npm install /path/to/qa-chatbot-server/widget
193
+ ```
194
+
195
+ 3. Now you can import and use the widget in your project:
196
+ ```javascript
197
+ import { ChatWidget } from 'chatbot-widget';
198
+ ```
199
+
200
+ ### Option 3: Publishing to npm (for production)
201
+
202
+ To make this widget available to anyone via npm:
203
+
204
+ 1. Build the widget and create the bundle:
205
+ ```bash
206
+ npm run build
207
+ npm run build:bundle
208
+ ```
209
+
210
+ 2. Login to npm with your account:
211
+ ```bash
212
+ npm login
213
+ ```
214
+
215
+ 3. Publish the package (if you're publishing for the first time, or updating the version):
216
+ ```bash
217
+ npm publish --access public
218
+ ```
219
+
220
+ 4. To update an existing package, first update the version in package.json, then run:
221
+ ```bash
222
+ npm version patch # or minor or major
223
+ npm publish --access public
224
+ ```
225
+
226
+ ### Importing the Bundled Version
227
+
228
+ After publishing, users can import your bundled widget in different ways:
229
+
230
+ ```html
231
+ <!-- HTML - Using the full bundle (JS + CSS combined) -->
232
+ <script src="https://unpkg.com/@schmitech/chatbot-widget/dist/chatbot-widget.bundle.js"></script>
233
+
234
+ <!-- Using UMD version + separate CSS -->
235
+ <script src="https://unpkg.com/@schmitech/chatbot-widget"></script>
236
+ <link rel="stylesheet" href="https://unpkg.com/@schmitech/chatbot-widget/dist/chatbot-widget.css" />
237
+ ```
238
+
239
+ ```javascript
240
+ // ES Module - Using direct import from node_modules
241
+ import { ChatWidget } from '@schmitech/chatbot-widget';
242
+ // For the bundled version (if you're using a bundler like webpack)
243
+ import '@schmitech/chatbot-widget/bundle';
244
+ ```
245
+
246
+ ### Known Limitations and Troubleshooting
247
+
248
+ #### Scrolling Behavior
249
+
250
+ The chat widget has a maximum height of 500px by default. When the conversation exceeds this height:
251
+ - A scrollbar appears to navigate through the conversation
252
+ - A "scroll to top" button appears when scrolled down more than 200px
253
+ - The widget automatically scrolls to the bottom when new messages are added
254
+ - You can clear the entire conversation by clicking the "Clear" button in the header
255
+
256
+ If you need to customize the chat container height, you can modify it using CSS variables:
257
+
258
+ ```css
259
+ :root {
260
+ --chat-container-height: 600px; /* Increase maximum height */
261
+ }
262
+ ```
263
+
264
+ ## License
265
+
266
+ Apache 2.0 (See LICENSE in project folder).