@weldsuite/helpdesk-widget-sdk 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.
- package/LICENSE +21 -0
- package/README.md +824 -0
- package/dist/angular.d.ts +764 -0
- package/dist/angular.esm.js +2768 -0
- package/dist/angular.esm.js.map +1 -0
- package/dist/angular.js +2775 -0
- package/dist/angular.js.map +1 -0
- package/dist/index.d.ts +1428 -0
- package/dist/index.esm.js +2577 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +2620 -0
- package/dist/index.js.map +1 -0
- package/dist/index.umd.js +2626 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/react.d.ts +666 -0
- package/dist/react.esm.js +2479 -0
- package/dist/react.esm.js.map +1 -0
- package/dist/react.js +2489 -0
- package/dist/react.js.map +1 -0
- package/dist/vue-composables.esm.js +2442 -0
- package/dist/vue-composables.esm.js.map +1 -0
- package/dist/vue-composables.js +2445 -0
- package/dist/vue-composables.js.map +1 -0
- package/frameworks/svelte/HelpdeskWidget.svelte +101 -0
- package/frameworks/svelte/index.ts +46 -0
- package/frameworks/svelte/shims-svelte.d.ts +4 -0
- package/frameworks/vue/HelpdeskWidget.vue +46 -0
- package/frameworks/vue/index.ts +47 -0
- package/frameworks/vue/shims-vue.d.ts +5 -0
- package/frameworks/vue/useHelpdeskWidget.ts +90 -0
- package/package.json +102 -0
package/README.md
ADDED
|
@@ -0,0 +1,824 @@
|
|
|
1
|
+
# @weldsuite/helpdesk-widget
|
|
2
|
+
|
|
3
|
+
> Easiest way to add a helpdesk widget to your website. Just provide your `widgetId` - all styling and configuration is managed in your backoffice!
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@weldsuite/helpdesk-widget)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
|
|
8
|
+
## Features
|
|
9
|
+
|
|
10
|
+
- 🎯 **One Parameter** - Just pass your `widgetId`, that's it!
|
|
11
|
+
- ⚙️ **Backoffice Configuration** - Control colors, position, pages, and behavior from your admin panel
|
|
12
|
+
- 🔒 **Secure** - Loads in an isolated iframe with secure communication
|
|
13
|
+
- 📱 **Responsive** - Automatically adapts to all screen sizes
|
|
14
|
+
- 💪 **TypeScript** - Full TypeScript support included
|
|
15
|
+
- 🎯 **Framework Components** - Pre-built components for React, Vue, Angular, and Svelte
|
|
16
|
+
- 🎨 **Event System** - Type-safe event handlers for widget lifecycle
|
|
17
|
+
- 🌍 **Environment Support** - Easy dev/staging/production configuration
|
|
18
|
+
- 🌐 **Zero Dependencies** - Lightweight core with no external dependencies
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install @weldsuite/helpdesk-widget-sdk
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
or
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
yarn add @weldsuite/helpdesk-widget-sdk
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
or
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pnpm add @weldsuite/helpdesk-widget-sdk
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Quick Start
|
|
39
|
+
|
|
40
|
+
### The Simplest Way
|
|
41
|
+
|
|
42
|
+
```javascript
|
|
43
|
+
import { initHelpdeskWidget } from '@weldsuite/helpdesk-widget';
|
|
44
|
+
|
|
45
|
+
initHelpdeskWidget({ widgetId: 'your-widget-id' });
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
That's it! 🎉
|
|
49
|
+
|
|
50
|
+
The widget will automatically:
|
|
51
|
+
- Load with your configured theme colors
|
|
52
|
+
- Position itself as you set in the backoffice
|
|
53
|
+
- Display the pages you enabled
|
|
54
|
+
- Apply all your custom settings
|
|
55
|
+
|
|
56
|
+
## Configuration
|
|
57
|
+
|
|
58
|
+
### Required Parameter
|
|
59
|
+
|
|
60
|
+
| Parameter | Type | Description |
|
|
61
|
+
|-----------|------|-------------|
|
|
62
|
+
| `widgetId` | `string` | **Required.** Your unique widget identifier from the backoffice |
|
|
63
|
+
|
|
64
|
+
That's the only parameter you need!
|
|
65
|
+
|
|
66
|
+
### Where to Configure Everything Else?
|
|
67
|
+
|
|
68
|
+
**All widget settings are managed in your backoffice:**
|
|
69
|
+
- 🎨 Theme colors (primary, button, launcher, accent)
|
|
70
|
+
- 📍 Position (bottom-right, bottom-left, top-right, top-left)
|
|
71
|
+
- 📄 Enabled pages (home, chat, help, status, etc.)
|
|
72
|
+
- 🚀 Auto-open behavior
|
|
73
|
+
- 🏠 Starting page
|
|
74
|
+
- 💬 Welcome message
|
|
75
|
+
- And much more!
|
|
76
|
+
|
|
77
|
+
This centralized approach means:
|
|
78
|
+
- ✅ No code changes needed to update widget appearance
|
|
79
|
+
- ✅ Consistent styling across all your sites
|
|
80
|
+
- ✅ Easy A/B testing from the backoffice
|
|
81
|
+
- ✅ Instant updates without redeploying your app
|
|
82
|
+
|
|
83
|
+
## Usage Examples
|
|
84
|
+
|
|
85
|
+
### Vanilla JavaScript / HTML
|
|
86
|
+
|
|
87
|
+
```html
|
|
88
|
+
<!DOCTYPE html>
|
|
89
|
+
<html>
|
|
90
|
+
<head>
|
|
91
|
+
<title>My Website</title>
|
|
92
|
+
</head>
|
|
93
|
+
<body>
|
|
94
|
+
<h1>Welcome to my website</h1>
|
|
95
|
+
|
|
96
|
+
<!-- Load from CDN -->
|
|
97
|
+
<script src="https://unpkg.com/@weldsuite/helpdesk-widget@latest/dist/index.umd.js"></script>
|
|
98
|
+
|
|
99
|
+
<script>
|
|
100
|
+
HelpdeskWidget.initHelpdeskWidget({
|
|
101
|
+
widgetId: 'your-widget-id'
|
|
102
|
+
});
|
|
103
|
+
</script>
|
|
104
|
+
</body>
|
|
105
|
+
</html>
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### React
|
|
109
|
+
|
|
110
|
+
#### Using the Component (Easiest)
|
|
111
|
+
|
|
112
|
+
```tsx
|
|
113
|
+
import { HelpdeskWidgetReact } from '@weldsuite/helpdesk-widget-sdk/react';
|
|
114
|
+
|
|
115
|
+
function App() {
|
|
116
|
+
return (
|
|
117
|
+
<div className="App">
|
|
118
|
+
<h1>My App</h1>
|
|
119
|
+
<HelpdeskWidgetReact widgetId="your-widget-id" />
|
|
120
|
+
</div>
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
#### Using the Hook
|
|
126
|
+
|
|
127
|
+
```tsx
|
|
128
|
+
import { useHelpdeskWidget } from '@weldsuite/helpdesk-widget-sdk/react';
|
|
129
|
+
|
|
130
|
+
function App() {
|
|
131
|
+
const widget = useHelpdeskWidget({ widgetId: 'your-widget-id' });
|
|
132
|
+
|
|
133
|
+
return (
|
|
134
|
+
<div>
|
|
135
|
+
<button onClick={() => widget?.show()}>Show Support</button>
|
|
136
|
+
</div>
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
#### Using the Controls Hook
|
|
142
|
+
|
|
143
|
+
```tsx
|
|
144
|
+
import { useHelpdeskWidgetControls } from '@weldsuite/helpdesk-widget-sdk/react';
|
|
145
|
+
|
|
146
|
+
function App() {
|
|
147
|
+
const { show, hide, toggle } = useHelpdeskWidgetControls({
|
|
148
|
+
widgetId: 'your-widget-id'
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
return (
|
|
152
|
+
<div>
|
|
153
|
+
<button onClick={show}>Show Support</button>
|
|
154
|
+
<button onClick={hide}>Hide Support</button>
|
|
155
|
+
<button onClick={toggle}>Toggle Support</button>
|
|
156
|
+
</div>
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
#### With Event Handlers
|
|
162
|
+
|
|
163
|
+
```tsx
|
|
164
|
+
import { HelpdeskWidgetReact } from '@weldsuite/helpdesk-widget-sdk/react';
|
|
165
|
+
|
|
166
|
+
function App() {
|
|
167
|
+
return (
|
|
168
|
+
<HelpdeskWidgetReact
|
|
169
|
+
widgetId="your-widget-id"
|
|
170
|
+
onReady={(event) => console.log('Widget ready!', event)}
|
|
171
|
+
onOpened={(event) => console.log('Widget opened!', event)}
|
|
172
|
+
onClosed={(event) => console.log('Widget closed!', event)}
|
|
173
|
+
/>
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### Next.js
|
|
179
|
+
|
|
180
|
+
#### App Router (Client Component)
|
|
181
|
+
|
|
182
|
+
```tsx
|
|
183
|
+
// components/WidgetProvider.tsx
|
|
184
|
+
'use client';
|
|
185
|
+
|
|
186
|
+
import { HelpdeskWidgetReact } from '@weldsuite/helpdesk-widget-sdk/react';
|
|
187
|
+
|
|
188
|
+
export default function WidgetProvider() {
|
|
189
|
+
return (
|
|
190
|
+
<HelpdeskWidgetReact
|
|
191
|
+
widgetId={process.env.NEXT_PUBLIC_WIDGET_ID!}
|
|
192
|
+
/>
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
Then add to your layout:
|
|
198
|
+
|
|
199
|
+
```tsx
|
|
200
|
+
// app/layout.tsx
|
|
201
|
+
import WidgetProvider from './components/WidgetProvider';
|
|
202
|
+
|
|
203
|
+
export default function RootLayout({ children }) {
|
|
204
|
+
return (
|
|
205
|
+
<html>
|
|
206
|
+
<body>
|
|
207
|
+
{children}
|
|
208
|
+
<WidgetProvider />
|
|
209
|
+
</body>
|
|
210
|
+
</html>
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
### Vue 3
|
|
216
|
+
|
|
217
|
+
#### Using the Component (Easiest)
|
|
218
|
+
|
|
219
|
+
```vue
|
|
220
|
+
<script setup lang="ts">
|
|
221
|
+
import { HelpdeskWidget } from '@weldsuite/helpdesk-widget-sdk/vue';
|
|
222
|
+
</script>
|
|
223
|
+
|
|
224
|
+
<template>
|
|
225
|
+
<div>
|
|
226
|
+
<h1>My App</h1>
|
|
227
|
+
<HelpdeskWidget widget-id="your-widget-id" />
|
|
228
|
+
</div>
|
|
229
|
+
</template>
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
#### Using the Composable
|
|
233
|
+
|
|
234
|
+
```vue
|
|
235
|
+
<script setup lang="ts">
|
|
236
|
+
import { useHelpdeskWidget } from '@weldsuite/helpdesk-widget-sdk/vue';
|
|
237
|
+
|
|
238
|
+
const widget = useHelpdeskWidget({ widgetId: 'your-widget-id' });
|
|
239
|
+
</script>
|
|
240
|
+
|
|
241
|
+
<template>
|
|
242
|
+
<div>
|
|
243
|
+
<button @click="widget?.show()">Show Support</button>
|
|
244
|
+
</div>
|
|
245
|
+
</template>
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
#### Using the Controls Composable
|
|
249
|
+
|
|
250
|
+
```vue
|
|
251
|
+
<script setup lang="ts">
|
|
252
|
+
import { useHelpdeskWidgetControls } from '@weldsuite/helpdesk-widget-sdk/vue';
|
|
253
|
+
|
|
254
|
+
const { show, hide, toggle } = useHelpdeskWidgetControls({
|
|
255
|
+
widgetId: 'your-widget-id'
|
|
256
|
+
});
|
|
257
|
+
</script>
|
|
258
|
+
|
|
259
|
+
<template>
|
|
260
|
+
<div>
|
|
261
|
+
<button @click="show">Show Support</button>
|
|
262
|
+
<button @click="hide">Hide Support</button>
|
|
263
|
+
<button @click="toggle">Toggle Support</button>
|
|
264
|
+
</div>
|
|
265
|
+
</template>
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
#### With Event Handlers
|
|
269
|
+
|
|
270
|
+
```vue
|
|
271
|
+
<script setup lang="ts">
|
|
272
|
+
import { HelpdeskWidget } from '@weldsuite/helpdesk-widget-sdk/vue';
|
|
273
|
+
|
|
274
|
+
const handleReady = (event) => console.log('Ready!', event);
|
|
275
|
+
const handleOpened = (event) => console.log('Opened!', event);
|
|
276
|
+
</script>
|
|
277
|
+
|
|
278
|
+
<template>
|
|
279
|
+
<HelpdeskWidget
|
|
280
|
+
widget-id="your-widget-id"
|
|
281
|
+
:on-ready="handleReady"
|
|
282
|
+
:on-opened="handleOpened"
|
|
283
|
+
/>
|
|
284
|
+
</template>
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
### Angular
|
|
288
|
+
|
|
289
|
+
#### Using the Standalone Component (Angular 14+)
|
|
290
|
+
|
|
291
|
+
```typescript
|
|
292
|
+
// app.component.ts
|
|
293
|
+
import { Component } from '@angular/core';
|
|
294
|
+
import { HelpdeskWidgetComponent } from '@weldsuite/helpdesk-widget-sdk/angular';
|
|
295
|
+
|
|
296
|
+
@Component({
|
|
297
|
+
selector: 'app-root',
|
|
298
|
+
standalone: true,
|
|
299
|
+
imports: [HelpdeskWidgetComponent],
|
|
300
|
+
template: `
|
|
301
|
+
<h1>My App</h1>
|
|
302
|
+
<helpdesk-widget [widgetId]="'your-widget-id'"></helpdesk-widget>
|
|
303
|
+
`
|
|
304
|
+
})
|
|
305
|
+
export class AppComponent {}
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
#### Using the Module (Pre-Angular 14)
|
|
309
|
+
|
|
310
|
+
```typescript
|
|
311
|
+
// app.module.ts
|
|
312
|
+
import { NgModule } from '@angular/core';
|
|
313
|
+
import { BrowserModule } from '@angular/platform-browser';
|
|
314
|
+
import { HelpdeskWidgetModule } from '@weldsuite/helpdesk-widget-sdk/angular';
|
|
315
|
+
import { AppComponent } from './app.component';
|
|
316
|
+
|
|
317
|
+
@NgModule({
|
|
318
|
+
declarations: [AppComponent],
|
|
319
|
+
imports: [
|
|
320
|
+
BrowserModule,
|
|
321
|
+
HelpdeskWidgetModule
|
|
322
|
+
],
|
|
323
|
+
bootstrap: [AppComponent]
|
|
324
|
+
})
|
|
325
|
+
export class AppModule {}
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
```typescript
|
|
329
|
+
// app.component.ts
|
|
330
|
+
import { Component } from '@angular/core';
|
|
331
|
+
|
|
332
|
+
@Component({
|
|
333
|
+
selector: 'app-root',
|
|
334
|
+
template: `
|
|
335
|
+
<h1>My App</h1>
|
|
336
|
+
<helpdesk-widget [widgetId]="'your-widget-id'"></helpdesk-widget>
|
|
337
|
+
`
|
|
338
|
+
})
|
|
339
|
+
export class AppComponent {}
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
#### Using the Service
|
|
343
|
+
|
|
344
|
+
```typescript
|
|
345
|
+
// app.component.ts
|
|
346
|
+
import { Component } from '@angular/core';
|
|
347
|
+
import { HelpdeskWidgetService } from '@weldsuite/helpdesk-widget-sdk/angular';
|
|
348
|
+
|
|
349
|
+
@Component({
|
|
350
|
+
selector: 'app-root',
|
|
351
|
+
template: `
|
|
352
|
+
<h1>My App</h1>
|
|
353
|
+
<button (click)="showSupport()">Show Support</button>
|
|
354
|
+
`
|
|
355
|
+
})
|
|
356
|
+
export class AppComponent {
|
|
357
|
+
constructor(private helpdeskService: HelpdeskWidgetService) {
|
|
358
|
+
this.helpdeskService.initialize({ widgetId: 'your-widget-id' });
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
showSupport() {
|
|
362
|
+
this.helpdeskService.show();
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
#### With Event Handlers
|
|
368
|
+
|
|
369
|
+
```typescript
|
|
370
|
+
// app.component.ts
|
|
371
|
+
import { Component } from '@angular/core';
|
|
372
|
+
import { HelpdeskWidgetComponent } from '@weldsuite/helpdesk-widget-sdk/angular';
|
|
373
|
+
|
|
374
|
+
@Component({
|
|
375
|
+
selector: 'app-root',
|
|
376
|
+
standalone: true,
|
|
377
|
+
imports: [HelpdeskWidgetComponent],
|
|
378
|
+
template: `
|
|
379
|
+
<helpdesk-widget
|
|
380
|
+
[widgetId]="'your-widget-id'"
|
|
381
|
+
[onReady]="handleReady"
|
|
382
|
+
[onOpened]="handleOpened">
|
|
383
|
+
</helpdesk-widget>
|
|
384
|
+
`
|
|
385
|
+
})
|
|
386
|
+
export class AppComponent {
|
|
387
|
+
handleReady = (event: any) => {
|
|
388
|
+
console.log('Widget ready', event);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
handleOpened = (event: any) => {
|
|
392
|
+
console.log('Widget opened', event);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
### Svelte
|
|
398
|
+
|
|
399
|
+
#### Using the Component
|
|
400
|
+
|
|
401
|
+
```svelte
|
|
402
|
+
<script lang="ts">
|
|
403
|
+
import { HelpdeskWidget } from '@weldsuite/helpdesk-widget-sdk/svelte';
|
|
404
|
+
</script>
|
|
405
|
+
|
|
406
|
+
<h1>My App</h1>
|
|
407
|
+
<HelpdeskWidget widgetId="your-widget-id" />
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
#### With Programmatic Control
|
|
411
|
+
|
|
412
|
+
```svelte
|
|
413
|
+
<script lang="ts">
|
|
414
|
+
import { HelpdeskWidget } from '@weldsuite/helpdesk-widget-sdk/svelte';
|
|
415
|
+
|
|
416
|
+
let widgetComponent;
|
|
417
|
+
|
|
418
|
+
const showSupport = () => {
|
|
419
|
+
widgetComponent?.show();
|
|
420
|
+
};
|
|
421
|
+
</script>
|
|
422
|
+
|
|
423
|
+
<button on:click={showSupport}>Show Support</button>
|
|
424
|
+
<HelpdeskWidget bind:this={widgetComponent} widgetId="your-widget-id" />
|
|
425
|
+
```
|
|
426
|
+
|
|
427
|
+
#### With Event Handlers
|
|
428
|
+
|
|
429
|
+
```svelte
|
|
430
|
+
<script lang="ts">
|
|
431
|
+
import { HelpdeskWidget } from '@weldsuite/helpdesk-widget-sdk/svelte';
|
|
432
|
+
|
|
433
|
+
const handleReady = (event) => {
|
|
434
|
+
console.log('Widget ready', event);
|
|
435
|
+
};
|
|
436
|
+
|
|
437
|
+
const handleOpened = (event) => {
|
|
438
|
+
console.log('Widget opened', event);
|
|
439
|
+
};
|
|
440
|
+
</script>
|
|
441
|
+
|
|
442
|
+
<HelpdeskWidget
|
|
443
|
+
widgetId="your-widget-id"
|
|
444
|
+
onReady={handleReady}
|
|
445
|
+
onOpened={handleOpened}
|
|
446
|
+
/>
|
|
447
|
+
```
|
|
448
|
+
|
|
449
|
+
## Environment Configuration
|
|
450
|
+
|
|
451
|
+
The SDK supports different environments with easy configuration:
|
|
452
|
+
|
|
453
|
+
### Production (Default)
|
|
454
|
+
|
|
455
|
+
```typescript
|
|
456
|
+
import { initHelpdeskWidget } from '@weldsuite/helpdesk-widget-sdk';
|
|
457
|
+
|
|
458
|
+
// Automatically uses https://widget.welddesk.com
|
|
459
|
+
initHelpdeskWidget({ widgetId: 'your-widget-id' });
|
|
460
|
+
```
|
|
461
|
+
|
|
462
|
+
### Development
|
|
463
|
+
|
|
464
|
+
```typescript
|
|
465
|
+
import { initHelpdeskWidget, DEV_CONFIG } from '@weldsuite/helpdesk-widget-sdk';
|
|
466
|
+
|
|
467
|
+
// Uses http://localhost:3100
|
|
468
|
+
initHelpdeskWidget({
|
|
469
|
+
widgetId: 'your-widget-id',
|
|
470
|
+
baseUrl: DEV_CONFIG.baseUrl
|
|
471
|
+
});
|
|
472
|
+
```
|
|
473
|
+
|
|
474
|
+
### Staging
|
|
475
|
+
|
|
476
|
+
```typescript
|
|
477
|
+
import { initHelpdeskWidget, STAGING_CONFIG } from '@weldsuite/helpdesk-widget-sdk';
|
|
478
|
+
|
|
479
|
+
// Uses https://widget-staging.welddesk.com
|
|
480
|
+
initHelpdeskWidget({
|
|
481
|
+
widgetId: 'your-widget-id',
|
|
482
|
+
baseUrl: STAGING_CONFIG.baseUrl
|
|
483
|
+
});
|
|
484
|
+
```
|
|
485
|
+
|
|
486
|
+
### Custom URL
|
|
487
|
+
|
|
488
|
+
```typescript
|
|
489
|
+
import { initHelpdeskWidget } from '@weldsuite/helpdesk-widget-sdk';
|
|
490
|
+
|
|
491
|
+
initHelpdeskWidget({
|
|
492
|
+
widgetId: 'your-widget-id',
|
|
493
|
+
baseUrl: 'https://your-custom-domain.com'
|
|
494
|
+
});
|
|
495
|
+
```
|
|
496
|
+
|
|
497
|
+
## Event Handling
|
|
498
|
+
|
|
499
|
+
The SDK provides type-safe event handlers for widget lifecycle events:
|
|
500
|
+
|
|
501
|
+
### Available Events
|
|
502
|
+
|
|
503
|
+
- `widget:ready` - Widget iframe has loaded and is ready
|
|
504
|
+
- `widget:opened` - Widget panel has been opened
|
|
505
|
+
- `widget:closed` - Widget panel has been closed
|
|
506
|
+
- `widget:error` - An error occurred in the widget
|
|
507
|
+
|
|
508
|
+
### Using Event Handlers
|
|
509
|
+
|
|
510
|
+
#### Via Configuration
|
|
511
|
+
|
|
512
|
+
```typescript
|
|
513
|
+
import { initHelpdeskWidget } from '@weldsuite/helpdesk-widget-sdk';
|
|
514
|
+
|
|
515
|
+
const widget = initHelpdeskWidget({
|
|
516
|
+
widgetId: 'your-widget-id',
|
|
517
|
+
onReady: (event) => {
|
|
518
|
+
console.log('Widget is ready!', event);
|
|
519
|
+
},
|
|
520
|
+
onOpened: (event) => {
|
|
521
|
+
console.log('Widget opened!', event);
|
|
522
|
+
// Track analytics, etc.
|
|
523
|
+
},
|
|
524
|
+
onClosed: (event) => {
|
|
525
|
+
console.log('Widget closed!', event);
|
|
526
|
+
},
|
|
527
|
+
onError: (event) => {
|
|
528
|
+
console.error('Widget error:', event.data);
|
|
529
|
+
}
|
|
530
|
+
});
|
|
531
|
+
```
|
|
532
|
+
|
|
533
|
+
#### Using on() Method
|
|
534
|
+
|
|
535
|
+
```typescript
|
|
536
|
+
import { HelpdeskWidget } from '@weldsuite/helpdesk-widget-sdk';
|
|
537
|
+
|
|
538
|
+
const widget = new HelpdeskWidget({ widgetId: 'your-widget-id' });
|
|
539
|
+
|
|
540
|
+
// Register event handlers
|
|
541
|
+
widget.on('widget:ready', (event) => {
|
|
542
|
+
console.log('Ready!', event);
|
|
543
|
+
});
|
|
544
|
+
|
|
545
|
+
widget.on('widget:opened', (event) => {
|
|
546
|
+
console.log('Opened!', event);
|
|
547
|
+
});
|
|
548
|
+
|
|
549
|
+
widget.init();
|
|
550
|
+
```
|
|
551
|
+
|
|
552
|
+
#### Removing Event Handlers
|
|
553
|
+
|
|
554
|
+
```typescript
|
|
555
|
+
const handleReady = (event) => {
|
|
556
|
+
console.log('Ready!', event);
|
|
557
|
+
};
|
|
558
|
+
|
|
559
|
+
// Add handler
|
|
560
|
+
widget.on('widget:ready', handleReady);
|
|
561
|
+
|
|
562
|
+
// Remove handler
|
|
563
|
+
widget.off('widget:ready', handleReady);
|
|
564
|
+
```
|
|
565
|
+
|
|
566
|
+
## API Reference
|
|
567
|
+
|
|
568
|
+
### `initHelpdeskWidget(config)`
|
|
569
|
+
|
|
570
|
+
Convenience function that creates and initializes the widget in one call.
|
|
571
|
+
|
|
572
|
+
**Parameters:**
|
|
573
|
+
- `config.widgetId` (string, required) - Your widget ID
|
|
574
|
+
|
|
575
|
+
**Returns:** `HelpdeskWidget` instance
|
|
576
|
+
|
|
577
|
+
**Example:**
|
|
578
|
+
```javascript
|
|
579
|
+
const widget = initHelpdeskWidget({ widgetId: 'your-widget-id' });
|
|
580
|
+
```
|
|
581
|
+
|
|
582
|
+
### Class: `HelpdeskWidget`
|
|
583
|
+
|
|
584
|
+
#### Constructor
|
|
585
|
+
|
|
586
|
+
```typescript
|
|
587
|
+
new HelpdeskWidget(config: { widgetId: string })
|
|
588
|
+
```
|
|
589
|
+
|
|
590
|
+
#### Methods
|
|
591
|
+
|
|
592
|
+
##### `init(): void`
|
|
593
|
+
|
|
594
|
+
Initialize and mount the widget to the page.
|
|
595
|
+
|
|
596
|
+
```javascript
|
|
597
|
+
const widget = new HelpdeskWidget({ widgetId: 'your-widget-id' });
|
|
598
|
+
widget.init();
|
|
599
|
+
```
|
|
600
|
+
|
|
601
|
+
##### `destroy(): void`
|
|
602
|
+
|
|
603
|
+
Remove the widget from the page and clean up resources.
|
|
604
|
+
|
|
605
|
+
```javascript
|
|
606
|
+
widget.destroy();
|
|
607
|
+
```
|
|
608
|
+
|
|
609
|
+
##### `show(): void`
|
|
610
|
+
|
|
611
|
+
Show the widget.
|
|
612
|
+
|
|
613
|
+
```javascript
|
|
614
|
+
widget.show();
|
|
615
|
+
```
|
|
616
|
+
|
|
617
|
+
##### `hide(): void`
|
|
618
|
+
|
|
619
|
+
Hide the widget.
|
|
620
|
+
|
|
621
|
+
```javascript
|
|
622
|
+
widget.hide();
|
|
623
|
+
```
|
|
624
|
+
|
|
625
|
+
##### `toggle(): void`
|
|
626
|
+
|
|
627
|
+
Toggle widget visibility.
|
|
628
|
+
|
|
629
|
+
```javascript
|
|
630
|
+
widget.toggle();
|
|
631
|
+
```
|
|
632
|
+
|
|
633
|
+
##### `sendMessage(message: any): void`
|
|
634
|
+
|
|
635
|
+
Send a custom message to the widget (for advanced integrations).
|
|
636
|
+
|
|
637
|
+
```javascript
|
|
638
|
+
widget.sendMessage({ type: 'custom-event', data: { foo: 'bar' } });
|
|
639
|
+
```
|
|
640
|
+
|
|
641
|
+
## Programmatic Control
|
|
642
|
+
|
|
643
|
+
```javascript
|
|
644
|
+
const widget = initHelpdeskWidget({ widgetId: 'your-widget-id' });
|
|
645
|
+
|
|
646
|
+
// Show widget programmatically
|
|
647
|
+
document.getElementById('help-btn').addEventListener('click', () => {
|
|
648
|
+
widget.show();
|
|
649
|
+
});
|
|
650
|
+
|
|
651
|
+
// Hide widget
|
|
652
|
+
document.getElementById('close-btn').addEventListener('click', () => {
|
|
653
|
+
widget.hide();
|
|
654
|
+
});
|
|
655
|
+
|
|
656
|
+
// Toggle widget
|
|
657
|
+
document.getElementById('toggle-btn').addEventListener('click', () => {
|
|
658
|
+
widget.toggle();
|
|
659
|
+
});
|
|
660
|
+
```
|
|
661
|
+
|
|
662
|
+
## Environment Variables
|
|
663
|
+
|
|
664
|
+
Store your widget ID in environment variables:
|
|
665
|
+
|
|
666
|
+
```bash
|
|
667
|
+
# .env
|
|
668
|
+
NEXT_PUBLIC_WIDGET_ID=your-widget-id
|
|
669
|
+
VITE_WIDGET_ID=your-widget-id
|
|
670
|
+
REACT_APP_WIDGET_ID=your-widget-id
|
|
671
|
+
```
|
|
672
|
+
|
|
673
|
+
Then use it:
|
|
674
|
+
|
|
675
|
+
```javascript
|
|
676
|
+
initHelpdeskWidget({
|
|
677
|
+
widgetId: process.env.NEXT_PUBLIC_WIDGET_ID // Next.js
|
|
678
|
+
// or
|
|
679
|
+
widgetId: import.meta.env.VITE_WIDGET_ID // Vite
|
|
680
|
+
// or
|
|
681
|
+
widgetId: process.env.REACT_APP_WIDGET_ID // Create React App
|
|
682
|
+
});
|
|
683
|
+
```
|
|
684
|
+
|
|
685
|
+
## TypeScript Support
|
|
686
|
+
|
|
687
|
+
Full TypeScript support is included. No additional `@types` packages needed!
|
|
688
|
+
|
|
689
|
+
```typescript
|
|
690
|
+
import { HelpdeskWidget, HelpdeskWidgetConfig } from '@weldsuite/helpdesk-widget';
|
|
691
|
+
|
|
692
|
+
const config: HelpdeskWidgetConfig = {
|
|
693
|
+
widgetId: 'your-widget-id'
|
|
694
|
+
};
|
|
695
|
+
|
|
696
|
+
const widget = new HelpdeskWidget(config);
|
|
697
|
+
widget.init();
|
|
698
|
+
```
|
|
699
|
+
|
|
700
|
+
## Backoffice Configuration
|
|
701
|
+
|
|
702
|
+
All widget behavior and appearance is controlled from your backoffice dashboard:
|
|
703
|
+
|
|
704
|
+
### Theme Settings
|
|
705
|
+
- Primary color
|
|
706
|
+
- Button color
|
|
707
|
+
- Button text color
|
|
708
|
+
- Launcher color
|
|
709
|
+
- Header color
|
|
710
|
+
- Accent color
|
|
711
|
+
- Border radius
|
|
712
|
+
- Font size
|
|
713
|
+
|
|
714
|
+
### Widget Behavior
|
|
715
|
+
- Position (bottom-right, bottom-left, top-right, top-left)
|
|
716
|
+
- Auto-open on page load
|
|
717
|
+
- Starting page
|
|
718
|
+
- Welcome message
|
|
719
|
+
- Company name
|
|
720
|
+
|
|
721
|
+
### Enabled Pages
|
|
722
|
+
- Home
|
|
723
|
+
- Chat/Messages
|
|
724
|
+
- Help
|
|
725
|
+
- Status
|
|
726
|
+
- Changelog
|
|
727
|
+
- News
|
|
728
|
+
- Feedback
|
|
729
|
+
- Announcements
|
|
730
|
+
- Event Sign-up
|
|
731
|
+
- Parcel Tracking
|
|
732
|
+
|
|
733
|
+
### Typography
|
|
734
|
+
- Text color
|
|
735
|
+
- Background color
|
|
736
|
+
|
|
737
|
+
Simply log into your backoffice, update your widget settings, and see changes instantly on all sites using that widget ID - no code deployment needed!
|
|
738
|
+
|
|
739
|
+
## Browser Support
|
|
740
|
+
|
|
741
|
+
- Chrome (latest)
|
|
742
|
+
- Firefox (latest)
|
|
743
|
+
- Safari (latest)
|
|
744
|
+
- Edge (latest)
|
|
745
|
+
- iOS Safari (latest)
|
|
746
|
+
- Chrome for Android (latest)
|
|
747
|
+
|
|
748
|
+
## Security
|
|
749
|
+
|
|
750
|
+
The widget is loaded in an isolated iframe with:
|
|
751
|
+
- Restricted iframe permissions
|
|
752
|
+
- Origin-verified postMessage communication
|
|
753
|
+
- No access to parent page DOM or JavaScript
|
|
754
|
+
- Secure HTTPS-only loading
|
|
755
|
+
|
|
756
|
+
## Troubleshooting
|
|
757
|
+
|
|
758
|
+
### Widget Not Appearing?
|
|
759
|
+
|
|
760
|
+
1. **Check widget ID** - Verify it matches your backoffice configuration
|
|
761
|
+
2. **Check console** - Look for error messages in browser console
|
|
762
|
+
3. **Check backoffice** - Make sure the widget is enabled and configured
|
|
763
|
+
4. **Network check** - Verify `https://widget.welddesk.com` is accessible
|
|
764
|
+
|
|
765
|
+
### Need to Change Colors/Position?
|
|
766
|
+
|
|
767
|
+
**Don't edit the code!** Just update the settings in your backoffice dashboard. Changes will take effect immediately.
|
|
768
|
+
|
|
769
|
+
### Testing Multiple Configurations?
|
|
770
|
+
|
|
771
|
+
Create multiple widget IDs in your backoffice with different configurations, then swap the `widgetId` in your code:
|
|
772
|
+
|
|
773
|
+
```javascript
|
|
774
|
+
// Development widget
|
|
775
|
+
const devWidgetId = 'dev-widget-123';
|
|
776
|
+
|
|
777
|
+
// Production widget
|
|
778
|
+
const prodWidgetId = 'prod-widget-456';
|
|
779
|
+
|
|
780
|
+
initHelpdeskWidget({
|
|
781
|
+
widgetId: process.env.NODE_ENV === 'production' ? prodWidgetId : devWidgetId
|
|
782
|
+
});
|
|
783
|
+
```
|
|
784
|
+
|
|
785
|
+
## FAQ
|
|
786
|
+
|
|
787
|
+
**Q: Can I change the widget color from my code?**
|
|
788
|
+
A: No, all styling is managed in the backoffice. This ensures consistency across all your properties.
|
|
789
|
+
|
|
790
|
+
**Q: Can I set the position programmatically?**
|
|
791
|
+
A: No, position is configured in the backoffice per widget ID.
|
|
792
|
+
|
|
793
|
+
**Q: How do I enable/disable specific pages?**
|
|
794
|
+
A: Configure enabled pages in your backoffice dashboard.
|
|
795
|
+
|
|
796
|
+
**Q: Can I have multiple widgets on one page?**
|
|
797
|
+
A: Yes! Create multiple widget IDs in your backoffice and initialize each one:
|
|
798
|
+
|
|
799
|
+
```javascript
|
|
800
|
+
initHelpdeskWidget({ widgetId: 'sales-widget' });
|
|
801
|
+
initHelpdeskWidget({ widgetId: 'support-widget' });
|
|
802
|
+
```
|
|
803
|
+
|
|
804
|
+
**Q: Does it work with server-side rendering?**
|
|
805
|
+
A: Yes! Just make sure to initialize the widget in a client-side context (useEffect, onMounted, ngOnInit, etc.).
|
|
806
|
+
|
|
807
|
+
## Contributing
|
|
808
|
+
|
|
809
|
+
Contributions are welcome! Please open an issue or submit a pull request.
|
|
810
|
+
|
|
811
|
+
## License
|
|
812
|
+
|
|
813
|
+
MIT © WeldSuite
|
|
814
|
+
|
|
815
|
+
## Support
|
|
816
|
+
|
|
817
|
+
For questions or issues:
|
|
818
|
+
- Open an issue on [GitHub](https://github.com/weldcorporation/weldsuite/issues)
|
|
819
|
+
- Email: support@weldsuite.com
|
|
820
|
+
- Documentation: [Full Integration Guide](./INTEGRATION_GUIDE.md)
|
|
821
|
+
|
|
822
|
+
---
|
|
823
|
+
|
|
824
|
+
Made with ❤️ by [WeldSuite](https://weldsuite.com)
|