cevro-messenger-sdk 0.1.0 → 0.1.1
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 +477 -1
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +21 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/types/core/ApiClient.d.ts.map +1 -1
- package/dist/types/core/CevroMessenger.d.ts +4 -0
- package/dist/types/core/CevroMessenger.d.ts.map +1 -1
- package/dist/types/ui/ChatWindow.d.ts.map +1 -1
- package/dist/umd/cevro-messenger.min.js +1 -1
- package/dist/umd/cevro-messenger.min.js.map +1 -1
- package/package.json +2 -9
package/README.md
CHANGED
|
@@ -1 +1,477 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Cevro Messenger SDK
|
|
2
|
+
|
|
3
|
+
A lightweight, universal JavaScript SDK for integrating Cevro AI customer support chat into any website or web application. Works with vanilla JavaScript, React, Vue, Angular, and any other framework.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
### NPM / Yarn / PNPM
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install cevro-messenger-sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
yarn add cevro-messenger-sdk
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pnpm add cevro-messenger-sdk
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### CDN
|
|
22
|
+
|
|
23
|
+
Add the script tag to your HTML:
|
|
24
|
+
|
|
25
|
+
```html
|
|
26
|
+
<!-- Using unpkg -->
|
|
27
|
+
<script src="https://unpkg.com/cevro-messenger-sdk/dist/umd/cevro-messenger.min.js"></script>
|
|
28
|
+
|
|
29
|
+
<!-- Or using jsdelivr -->
|
|
30
|
+
<script src="https://cdn.jsdelivr.net/npm/cevro-messenger-sdk/dist/umd/cevro-messenger.min.js"></script>
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Quick Start
|
|
34
|
+
|
|
35
|
+
### ES Modules (React, Vue, Angular, etc.)
|
|
36
|
+
|
|
37
|
+
```javascript
|
|
38
|
+
import { CevroMessenger } from 'cevro-messenger-sdk';
|
|
39
|
+
|
|
40
|
+
const messenger = new CevroMessenger({
|
|
41
|
+
apiBase: 'https://api.cevro.ai',
|
|
42
|
+
workspaceId: 'your-workspace-id',
|
|
43
|
+
brandId: 'your-brand-id',
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
messenger.boot();
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Browser (Script Tag)
|
|
50
|
+
|
|
51
|
+
```html
|
|
52
|
+
<script src="https://unpkg.com/cevro-messenger-sdk/dist/umd/cevro-messenger.min.js"></script>
|
|
53
|
+
<script>
|
|
54
|
+
const messenger = new CevroMessenger({
|
|
55
|
+
apiBase: 'https://api.cevro.ai',
|
|
56
|
+
workspaceId: 'your-workspace-id',
|
|
57
|
+
brandId: 'your-brand-id',
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
messenger.boot();
|
|
61
|
+
</script>
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Configuration Options
|
|
65
|
+
|
|
66
|
+
| Option | Type | Required | Default | Description |
|
|
67
|
+
|--------|------|----------|---------|-------------|
|
|
68
|
+
| `apiBase` | `string` | Yes | - | API base URL for the Cevro backend |
|
|
69
|
+
| `workspaceId` | `string` | Yes | - | Your Cevro workspace ID |
|
|
70
|
+
| `brandId` | `string` | Yes | - | Brand ID for the workspace |
|
|
71
|
+
| `player` | `PlayerData` | No | - | Authenticated user information |
|
|
72
|
+
| `customLauncherSelector` | `string` | No | - | CSS selector for custom launcher button |
|
|
73
|
+
| `hideDefaultLauncher` | `boolean` | No | `false` | Hide the default floating launcher button |
|
|
74
|
+
| `alignment` | `'left' \| 'right'` | No | `'right'` | Horizontal position of the messenger |
|
|
75
|
+
| `verticalPadding` | `number` | No | `20` | Padding from bottom (px) |
|
|
76
|
+
| `horizontalPadding` | `number` | No | `20` | Padding from edge (px) |
|
|
77
|
+
| `theme` | `'light' \| 'dark' \| 'system'` | No | `'light'` | Color theme |
|
|
78
|
+
| `locale` | `string` | No | - | Locale (e.g., 'en', 'uk') |
|
|
79
|
+
| `debug` | `boolean` | No | `false` | Enable debug logging |
|
|
80
|
+
| `zIndex` | `number` | No | `2147483647` | Z-index for the widget |
|
|
81
|
+
| `fileUpload` | `FileUploadConfig` | No | - | File upload settings |
|
|
82
|
+
|
|
83
|
+
### PlayerData (Authenticated Users)
|
|
84
|
+
|
|
85
|
+
Pass user information to identify authenticated users:
|
|
86
|
+
|
|
87
|
+
```javascript
|
|
88
|
+
const messenger = new CevroMessenger({
|
|
89
|
+
apiBase: 'https://api.cevro.ai',
|
|
90
|
+
workspaceId: 'your-workspace-id',
|
|
91
|
+
brandId: 'your-brand-id',
|
|
92
|
+
player: {
|
|
93
|
+
playerId: 'user-123',
|
|
94
|
+
email: 'user@example.com',
|
|
95
|
+
firstName: 'John',
|
|
96
|
+
lastName: 'Doe',
|
|
97
|
+
phone: '+1234567890',
|
|
98
|
+
customAttributes: {
|
|
99
|
+
plan: 'premium',
|
|
100
|
+
accountAge: 365,
|
|
101
|
+
verified: true,
|
|
102
|
+
},
|
|
103
|
+
playerHash: 'hmac-hash-for-verification', // Optional: HMAC for identity verification
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
| Field | Type | Description |
|
|
109
|
+
|-------|------|-------------|
|
|
110
|
+
| `playerId` | `string` | Unique user ID on your platform (required) |
|
|
111
|
+
| `email` | `string` | User's email address |
|
|
112
|
+
| `firstName` | `string` | User's first name |
|
|
113
|
+
| `lastName` | `string` | User's last name |
|
|
114
|
+
| `phone` | `string` | User's phone number |
|
|
115
|
+
| `customAttributes` | `object` | Custom key-value attributes (string, number, or boolean values) |
|
|
116
|
+
| `playerHash` | `string` | HMAC hash for identity verification |
|
|
117
|
+
|
|
118
|
+
### FileUploadConfig
|
|
119
|
+
|
|
120
|
+
Configure file upload behavior:
|
|
121
|
+
|
|
122
|
+
```javascript
|
|
123
|
+
const messenger = new CevroMessenger({
|
|
124
|
+
// ... other options
|
|
125
|
+
fileUpload: {
|
|
126
|
+
allowedMimeTypes: ['image/*', 'application/pdf'],
|
|
127
|
+
additionalBlockedExtensions: ['.exe', '.bat'],
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## API Methods
|
|
133
|
+
|
|
134
|
+
### `boot()`
|
|
135
|
+
|
|
136
|
+
Initialize and render the messenger widget.
|
|
137
|
+
|
|
138
|
+
```javascript
|
|
139
|
+
messenger.boot();
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### `shutdown(options?)`
|
|
143
|
+
|
|
144
|
+
Remove the messenger from the page.
|
|
145
|
+
|
|
146
|
+
```javascript
|
|
147
|
+
// Normal shutdown
|
|
148
|
+
messenger.shutdown();
|
|
149
|
+
|
|
150
|
+
// Clear visitor data (visitor will get new identity on next init)
|
|
151
|
+
messenger.shutdown({ clearVisitorData: true });
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### `show()`
|
|
155
|
+
|
|
156
|
+
Open the chat window.
|
|
157
|
+
|
|
158
|
+
```javascript
|
|
159
|
+
messenger.show();
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### `hide()`
|
|
163
|
+
|
|
164
|
+
Close the chat window.
|
|
165
|
+
|
|
166
|
+
```javascript
|
|
167
|
+
messenger.hide();
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### `toggle()`
|
|
171
|
+
|
|
172
|
+
Toggle the chat window visibility.
|
|
173
|
+
|
|
174
|
+
```javascript
|
|
175
|
+
messenger.toggle();
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### `update(playerData)`
|
|
179
|
+
|
|
180
|
+
Update user information. If `playerId` is added for the first time, the session will be re-initialized to merge the visitor with the authenticated player.
|
|
181
|
+
|
|
182
|
+
```javascript
|
|
183
|
+
// Identify a visitor as an authenticated user
|
|
184
|
+
await messenger.update({
|
|
185
|
+
playerId: 'user-123',
|
|
186
|
+
email: 'user@example.com',
|
|
187
|
+
firstName: 'John',
|
|
188
|
+
});
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
> **Note:** This is primarily used to identify anonymous visitors after they log in. The data will be used on the next session initialization.
|
|
192
|
+
|
|
193
|
+
### `showNewMessage(prefilledText?)`
|
|
194
|
+
|
|
195
|
+
Open the chat with optional pre-filled text.
|
|
196
|
+
|
|
197
|
+
```javascript
|
|
198
|
+
messenger.showNewMessage('I need help with my order');
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### `getUnreadCount()`
|
|
202
|
+
|
|
203
|
+
Get the current unread message count.
|
|
204
|
+
|
|
205
|
+
```javascript
|
|
206
|
+
const count = messenger.getUnreadCount();
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### `getVisitorId()`
|
|
210
|
+
|
|
211
|
+
Get the current visitor ID.
|
|
212
|
+
|
|
213
|
+
```javascript
|
|
214
|
+
const visitorId = messenger.getVisitorId();
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
## Events
|
|
218
|
+
|
|
219
|
+
Subscribe to events using the `on()` method:
|
|
220
|
+
|
|
221
|
+
```javascript
|
|
222
|
+
// Subscribe to an event
|
|
223
|
+
const unsubscribe = messenger.on('message:received', (data) => {
|
|
224
|
+
console.log('New message:', data.message);
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
// Unsubscribe later
|
|
228
|
+
unsubscribe();
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
### Available Events
|
|
232
|
+
|
|
233
|
+
| Event | Payload | Description |
|
|
234
|
+
|-------|---------|-------------|
|
|
235
|
+
| `boot` | - | Messenger has been initialized |
|
|
236
|
+
| `ready` | - | WebSocket connected and ready |
|
|
237
|
+
| `show` | - | Chat window opened |
|
|
238
|
+
| `hide` | - | Chat window closed |
|
|
239
|
+
| `shutdown` | - | Messenger has been removed |
|
|
240
|
+
| `session:initialized` | `{ sessionId, contactId, ticketId, isNewSession, isNewTicket }` | Session created/restored |
|
|
241
|
+
| `message:received` | `{ ticketId, message }` | New message from agent/AI |
|
|
242
|
+
| `message:sent` | `{ message }` | Message successfully sent |
|
|
243
|
+
| `unread_count_change` | `{ count }` | Unread count changed |
|
|
244
|
+
| `conversation:started` | `{ ticketId }` | New conversation started |
|
|
245
|
+
| `chat:new_started` | - | New chat started after previous was closed |
|
|
246
|
+
| `typing:start` | `{ ticketId, actor }` | Agent/AI started typing |
|
|
247
|
+
| `typing:stop` | `{ ticketId, actor }` | Agent/AI stopped typing |
|
|
248
|
+
| `error` | `{ type, error, message? }` | An error occurred |
|
|
249
|
+
| `connection:open` | - | WebSocket connected |
|
|
250
|
+
| `connection:close` | - | WebSocket disconnected |
|
|
251
|
+
| `connection:error` | `{ error }` | WebSocket error |
|
|
252
|
+
|
|
253
|
+
### Event Examples
|
|
254
|
+
|
|
255
|
+
```javascript
|
|
256
|
+
// Handle incoming messages
|
|
257
|
+
messenger.on('message:received', (data) => {
|
|
258
|
+
console.log('New message:', data.message.body);
|
|
259
|
+
|
|
260
|
+
// Show browser notification
|
|
261
|
+
if (Notification.permission === 'granted') {
|
|
262
|
+
new Notification('New message', { body: data.message.body });
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
// Track when chat is opened
|
|
267
|
+
messenger.on('show', () => {
|
|
268
|
+
analytics.track('chat_opened');
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
// Handle errors
|
|
272
|
+
messenger.on('error', (data) => {
|
|
273
|
+
console.error(`Error [${data.type}]:`, data.error);
|
|
274
|
+
|
|
275
|
+
if (data.type === 'file_validation') {
|
|
276
|
+
alert(data.message);
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
// Update UI when unread count changes
|
|
281
|
+
messenger.on('unread_count_change', (data) => {
|
|
282
|
+
document.querySelector('.notification-badge').textContent = data.count;
|
|
283
|
+
});
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
## Framework Examples
|
|
287
|
+
|
|
288
|
+
### React
|
|
289
|
+
|
|
290
|
+
```jsx
|
|
291
|
+
import { useEffect, useRef } from 'react';
|
|
292
|
+
import { CevroMessenger } from 'cevro-messenger-sdk';
|
|
293
|
+
|
|
294
|
+
function App() {
|
|
295
|
+
const messengerRef = useRef(null);
|
|
296
|
+
|
|
297
|
+
useEffect(() => {
|
|
298
|
+
messengerRef.current = new CevroMessenger({
|
|
299
|
+
apiBase: 'https://api.cevro.ai',
|
|
300
|
+
workspaceId: 'your-workspace-id',
|
|
301
|
+
brandId: 'your-brand-id',
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
messengerRef.current.boot();
|
|
305
|
+
|
|
306
|
+
return () => {
|
|
307
|
+
messengerRef.current?.shutdown();
|
|
308
|
+
};
|
|
309
|
+
}, []);
|
|
310
|
+
|
|
311
|
+
return <div>Your App</div>;
|
|
312
|
+
}
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
### Vue 3
|
|
316
|
+
|
|
317
|
+
```vue
|
|
318
|
+
<script setup>
|
|
319
|
+
import { onMounted, onUnmounted, ref } from 'vue';
|
|
320
|
+
import { CevroMessenger } from 'cevro-messenger-sdk';
|
|
321
|
+
|
|
322
|
+
const messenger = ref(null);
|
|
323
|
+
|
|
324
|
+
onMounted(() => {
|
|
325
|
+
messenger.value = new CevroMessenger({
|
|
326
|
+
apiBase: 'https://api.cevro.ai',
|
|
327
|
+
workspaceId: 'your-workspace-id',
|
|
328
|
+
brandId: 'your-brand-id',
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
messenger.value.boot();
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
onUnmounted(() => {
|
|
335
|
+
messenger.value?.shutdown();
|
|
336
|
+
});
|
|
337
|
+
</script>
|
|
338
|
+
|
|
339
|
+
<template>
|
|
340
|
+
<div>Your App</div>
|
|
341
|
+
</template>
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
### Angular
|
|
345
|
+
|
|
346
|
+
```typescript
|
|
347
|
+
import { Component, OnDestroy, OnInit } from '@angular/core';
|
|
348
|
+
import { CevroMessenger } from 'cevro-messenger-sdk';
|
|
349
|
+
|
|
350
|
+
@Component({
|
|
351
|
+
selector: 'app-root',
|
|
352
|
+
template: '<div>Your App</div>',
|
|
353
|
+
})
|
|
354
|
+
export class AppComponent implements OnInit, OnDestroy {
|
|
355
|
+
private messenger: CevroMessenger | null = null;
|
|
356
|
+
|
|
357
|
+
ngOnInit() {
|
|
358
|
+
this.messenger = new CevroMessenger({
|
|
359
|
+
apiBase: 'https://api.cevro.ai',
|
|
360
|
+
workspaceId: 'your-workspace-id',
|
|
361
|
+
brandId: 'your-brand-id',
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
this.messenger.boot();
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
ngOnDestroy() {
|
|
368
|
+
this.messenger?.shutdown();
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
### Next.js
|
|
374
|
+
|
|
375
|
+
```jsx
|
|
376
|
+
'use client';
|
|
377
|
+
|
|
378
|
+
import { useEffect, useRef } from 'react';
|
|
379
|
+
import { CevroMessenger } from 'cevro-messenger-sdk';
|
|
380
|
+
|
|
381
|
+
export default function ChatWidget() {
|
|
382
|
+
const messengerRef = useRef(null);
|
|
383
|
+
|
|
384
|
+
useEffect(() => {
|
|
385
|
+
// Only run on client side
|
|
386
|
+
if (typeof window !== 'undefined') {
|
|
387
|
+
messengerRef.current = new CevroMessenger({
|
|
388
|
+
apiBase: 'https://api.cevro.ai',
|
|
389
|
+
workspaceId: 'your-workspace-id',
|
|
390
|
+
brandId: 'your-brand-id',
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
messengerRef.current.boot();
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
return () => {
|
|
397
|
+
messengerRef.current?.shutdown();
|
|
398
|
+
};
|
|
399
|
+
}, []);
|
|
400
|
+
|
|
401
|
+
return null;
|
|
402
|
+
}
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
## Custom Launcher
|
|
406
|
+
|
|
407
|
+
Use your own button to open the chat:
|
|
408
|
+
|
|
409
|
+
```html
|
|
410
|
+
<button id="my-chat-button">Chat with us</button>
|
|
411
|
+
|
|
412
|
+
<script>
|
|
413
|
+
const messenger = new CevroMessenger({
|
|
414
|
+
apiBase: 'https://api.cevro.ai',
|
|
415
|
+
workspaceId: 'your-workspace-id',
|
|
416
|
+
brandId: 'your-brand-id',
|
|
417
|
+
hideDefaultLauncher: true,
|
|
418
|
+
customLauncherSelector: '#my-chat-button',
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
messenger.boot();
|
|
422
|
+
</script>
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
Or control it programmatically:
|
|
426
|
+
|
|
427
|
+
```javascript
|
|
428
|
+
const messenger = new CevroMessenger({
|
|
429
|
+
apiBase: 'https://api.cevro.ai',
|
|
430
|
+
workspaceId: 'your-workspace-id',
|
|
431
|
+
brandId: 'your-brand-id',
|
|
432
|
+
hideDefaultLauncher: true,
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
messenger.boot();
|
|
436
|
+
|
|
437
|
+
document.getElementById('my-chat-button').addEventListener('click', () => {
|
|
438
|
+
messenger.toggle();
|
|
439
|
+
});
|
|
440
|
+
```
|
|
441
|
+
|
|
442
|
+
## TypeScript Support
|
|
443
|
+
|
|
444
|
+
The SDK is written in TypeScript and includes full type definitions:
|
|
445
|
+
|
|
446
|
+
```typescript
|
|
447
|
+
import { CevroMessenger, CevroMessengerConfig } from 'cevro-messenger-sdk';
|
|
448
|
+
|
|
449
|
+
const config: CevroMessengerConfig = {
|
|
450
|
+
apiBase: 'https://api.cevro.ai',
|
|
451
|
+
workspaceId: 'your-workspace-id',
|
|
452
|
+
brandId: 'your-brand-id',
|
|
453
|
+
};
|
|
454
|
+
|
|
455
|
+
const messenger = new CevroMessenger(config);
|
|
456
|
+
|
|
457
|
+
messenger.on('message:received', (data) => {
|
|
458
|
+
console.log(data.message.body);
|
|
459
|
+
});
|
|
460
|
+
```
|
|
461
|
+
|
|
462
|
+
## Browser Support
|
|
463
|
+
|
|
464
|
+
- Chrome (latest)
|
|
465
|
+
- Firefox (latest)
|
|
466
|
+
- Safari (latest)
|
|
467
|
+
- Edge (latest)
|
|
468
|
+
- iOS Safari (latest)
|
|
469
|
+
- Android Chrome (latest)
|
|
470
|
+
|
|
471
|
+
## License
|
|
472
|
+
|
|
473
|
+
MIT
|
|
474
|
+
|
|
475
|
+
## Support
|
|
476
|
+
|
|
477
|
+
For support, contact us at [cevro.ai](https://cevro.ai)
|