chatbot-widget-sdk 1.0.1 → 1.0.2

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.
Files changed (2) hide show
  1. package/README.md +0 -217
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -142,224 +142,7 @@ const widget = new ChatbotWidget(publicKey: string, options?: WidgetOptions);
142
142
  |--------|------|---------|-------------|
143
143
  | `debug` | `boolean` | `false` | Enable debug logging |
144
144
 
145
- ### Methods
146
145
 
147
- #### `init(): Promise<void>`
148
-
149
- Initialize the widget. Must be called before using other methods.
150
-
151
- ```typescript
152
- await widget.init();
153
- ```
154
-
155
- #### `open(): void`
156
-
157
- Open the chat window.
158
-
159
- ```typescript
160
- widget.open();
161
- ```
162
-
163
- #### `close(): void`
164
-
165
- Close the chat window.
166
-
167
- ```typescript
168
- widget.close();
169
- ```
170
-
171
- #### `toggle(): void`
172
-
173
- Toggle the chat window open/closed state.
174
-
175
- ```typescript
176
- widget.toggle();
177
- ```
178
-
179
- #### `isOpen(): boolean`
180
-
181
- Check if the chat window is open.
182
-
183
- ```typescript
184
- if (widget.isOpen()) {
185
- console.log('Widget is open');
186
- }
187
- ```
188
-
189
- #### `sendMessage(message: string): void`
190
-
191
- Send a message programmatically.
192
-
193
- ```typescript
194
- widget.sendMessage('Hello!');
195
- ```
196
-
197
- #### `clearHistory(): void`
198
-
199
- Clear chat history and start fresh.
200
-
201
- ```typescript
202
- widget.clearHistory();
203
- ```
204
-
205
- #### `show(): void`
206
-
207
- Show the widget (if hidden).
208
-
209
- ```typescript
210
- widget.show();
211
- ```
212
-
213
- #### `hide(): void`
214
-
215
- Hide the widget completely.
216
-
217
- ```typescript
218
- widget.hide();
219
- ```
220
-
221
- #### `destroy(): void`
222
-
223
- Destroy the widget and clean up resources.
224
-
225
- ```typescript
226
- widget.destroy();
227
- ```
228
-
229
- #### `reconnect(): void`
230
-
231
- Reconnect the WebSocket connection.
232
-
233
- ```typescript
234
- widget.reconnect();
235
- ```
236
-
237
- #### `isConnected(): boolean`
238
-
239
- Check if WebSocket is connected.
240
-
241
- ```typescript
242
- if (widget.isConnected()) {
243
- console.log('Connected');
244
- }
245
- ```
246
-
247
- #### `getConfig(): WidgetConfig | null`
248
-
249
- Get the current configuration.
250
-
251
- ```typescript
252
- const config = widget.getConfig();
253
- console.log(config?.content.title);
254
- ```
255
-
256
- ### Events
257
-
258
- #### `on(event: string, callback: Function): () => void`
259
-
260
- Subscribe to an event. Returns an unsubscribe function.
261
-
262
- ```typescript
263
- const unsubscribe = widget.on('message:received', (message) => {
264
- console.log('Received:', message);
265
- });
266
-
267
- // Later, to unsubscribe:
268
- unsubscribe();
269
- ```
270
-
271
- #### `once(event: string, callback: Function): () => void`
272
-
273
- Subscribe to an event once.
274
-
275
- ```typescript
276
- widget.once('open', () => {
277
- console.log('Widget opened for the first time');
278
- });
279
- ```
280
-
281
- #### `off(event: string, callback: Function): void`
282
-
283
- Unsubscribe from an event.
284
-
285
- ```typescript
286
- const handler = (message) => console.log(message);
287
- widget.on('message:received', handler);
288
- widget.off('message:received', handler);
289
- ```
290
-
291
- ### Available Events
292
-
293
- | Event | Data | Description |
294
- |-------|------|-------------|
295
- | `open` | - | Chat window opened |
296
- | `close` | - | Chat window closed |
297
- | `message:sent` | `ChatMessage` | User sent a message |
298
- | `message:received` | `ChatMessage` | Bot message received |
299
- | `session:created` | `SessionData` | New session created |
300
- | `session:restored` | `SessionData` | Existing session restored |
301
- | `connection:open` | - | WebSocket connected |
302
- | `connection:close` | `{ code, reason }` | WebSocket disconnected |
303
- | `connection:error` | `Event` | WebSocket error |
304
- | `config:loaded` | `WidgetConfig` | Configuration loaded |
305
- | `error` | `{ type, error }` | Error occurred |
306
-
307
- ## Development
308
-
309
- ### Prerequisites
310
-
311
- - Node.js 18+
312
- - npm or yarn
313
-
314
- ### Setup
315
-
316
- ```bash
317
- # Install dependencies
318
- npm install
319
-
320
- # Build for production
321
- npm run build
322
-
323
- # Build and watch for changes
324
- npm run build:watch
325
-
326
- # Type check
327
- npm run typecheck
328
- ```
329
-
330
- ### Project Structure
331
-
332
- ```
333
- widget-sdk/
334
- ├── dist/ # Built files
335
- │ ├── chatbot-widget.min.js # IIFE bundle (CDN)
336
- │ └── chatbot-widget.esm.js # ES module bundle
337
- ├── src/
338
- │ ├── index.ts # Entry point & public API
339
- │ ├── ChatbotWidget.ts # Main widget class
340
- │ ├── core/
341
- │ │ ├── ConfigManager.ts # Fetch & apply config
342
- │ │ ├── SessionManager.ts # Session persistence
343
- │ │ ├── WebSocketClient.ts # WS connection
344
- │ │ └── EventEmitter.ts # Event system
345
- │ ├── ui/
346
- │ │ ├── WidgetUI.ts # Main UI orchestrator
347
- │ │ ├── Launcher.ts # Floating button
348
- │ │ ├── ChatWindow.ts # Chat container
349
- │ │ ├── Header.ts # Window header
350
- │ │ ├── MessageList.ts # Message area
351
- │ │ └── InputArea.ts # Input with send
352
- │ ├── styles/
353
- │ │ └── StyleManager.ts # Dynamic CSS from config
354
- │ ├── utils/
355
- │ │ ├── dom.ts # DOM helpers
356
- │ │ └── storage.ts # localStorage wrapper
357
- │ └── types/
358
- │ └── index.ts # TypeScript interfaces
359
- ├── package.json
360
- ├── tsconfig.json
361
- └── rollup.config.js
362
- ```
363
146
 
364
147
  ## Browser Support
365
148
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chatbot-widget-sdk",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "type": "module",
5
5
  "description": "Config-driven embeddable chat widget SDK",
6
6
  "main": "dist/chatbot-widget.min.js",