@satek-team-intern/chatbot-widget 0.8.10 → 0.10.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 +928 -61
- package/dist/chatbot-widget.es.js +3627 -1662
- package/dist/chatbot-widget.umd.js +10 -7
- package/dist/locales/en.json.d.ts +129 -5
- package/dist/locales/vi.json.d.ts +129 -5
- package/dist/src/assets/Icons.d.ts +43 -0
- package/dist/src/assets/createIcon.d.ts +19 -0
- package/dist/src/assets/index.d.ts +1 -0
- package/dist/src/components/ChatWindow.d.ts +16 -0
- package/dist/src/components/modals/UpdateGroup.d.ts +1 -1
- package/dist/src/components/modals/UserProfileModal.d.ts +10 -0
- package/dist/src/components/shared/ToastContainer.d.ts +3 -0
- package/dist/src/components/sidebar/AppSideBar.d.ts +8 -0
- package/dist/src/components/sidebar/ChatList.d.ts +0 -1
- package/dist/src/components/sidebar/ChatSearchBar.d.ts +1 -0
- package/dist/src/components/sidebar/SideBarInfoChat.d.ts +11 -0
- package/dist/src/components/sidebar/index.d.ts +1 -0
- package/dist/src/components/view/ChatHeader.d.ts +1 -0
- package/dist/src/components/view/ContactList.d.ts +8 -0
- package/dist/src/components/view/GroupList.d.ts +9 -0
- package/dist/src/components/view/index.d.ts +2 -0
- package/dist/src/contexts/ToastContext.d.ts +4 -0
- package/dist/src/contexts/toast-context.d.ts +16 -0
- package/dist/src/hooks/useSetting.d.ts +1 -1
- package/dist/src/hooks/useToast.d.ts +1 -0
- package/dist/src/hooks/useTranslation.d.ts +3 -0
- package/dist/src/services/chat.service.d.ts +3 -2
- package/dist/src/store/selectors/setting.d.ts +15 -45
- package/dist/src/store/slices/chatSlice.d.ts +5 -2
- package/dist/src/store/slices/settingSlice.d.ts +3 -3
- package/dist/src/types/chat.type.d.ts +33 -4
- package/dist/src/types/types.d.ts +38 -14
- package/dist/src/utils/chat.utils.d.ts +14 -7
- package/dist/src/utils/formatDateLabel.d.ts +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,35 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @satek-vn/chatbot-widget
|
|
2
2
|
|
|
3
|
-
A chatbot widget that can be integrated into any website, providing a seamless and interactive user experience. It is designed to be easily embedded and customizable, allowing businesses to engage with their customers effectively.
|
|
3
|
+
A powerful chatbot widget package that can be integrated into any website, providing a seamless and interactive user experience. It is designed to be easily embedded and customizable, allowing businesses to engage with their customers effectively.
|
|
4
|
+
|
|
5
|
+
## 📋 Table of Contents
|
|
6
|
+
|
|
7
|
+
### Widget Section (English)
|
|
8
|
+
|
|
9
|
+
1. [Features](#features)
|
|
10
|
+
2. [Installation](#installation)
|
|
11
|
+
3. [Widget Usage](#widget-usage)
|
|
12
|
+
4. [Configuration](#configuration)
|
|
13
|
+
5. [Customization](#customization)
|
|
14
|
+
6. [Troubleshooting](#troubleshooting)
|
|
15
|
+
|
|
16
|
+
### SDK Section (Advanced)
|
|
17
|
+
|
|
18
|
+
7. [SDK Guide](#sdk-guide-english)
|
|
19
|
+
8. [SDK Initialization](#sdk-initialization)
|
|
20
|
+
9. [Authentication Management](#authentication-management)
|
|
21
|
+
10. [Receiver Management](#receiver-management)
|
|
22
|
+
11. [Member Management](#member-management)
|
|
23
|
+
12. [Chat Management](#chat-management)
|
|
24
|
+
13. [Message Management](#message-management)
|
|
25
|
+
14. [Event System](#event-system)
|
|
26
|
+
|
|
27
|
+
### Support & License
|
|
28
|
+
|
|
29
|
+
15. [Support](#support)
|
|
30
|
+
16. [License](#license)
|
|
31
|
+
|
|
32
|
+
---
|
|
4
33
|
|
|
5
34
|
## Features
|
|
6
35
|
|
|
@@ -10,6 +39,8 @@ A chatbot widget that can be integrated into any website, providing a seamless a
|
|
|
10
39
|
- 🔧 Easy to integrate into any website
|
|
11
40
|
- 💬 Support for advanced chat features
|
|
12
41
|
|
|
42
|
+
---
|
|
43
|
+
|
|
13
44
|
## Installation
|
|
14
45
|
|
|
15
46
|
### 1. React Component (npm)
|
|
@@ -17,19 +48,20 @@ A chatbot widget that can be integrated into any website, providing a seamless a
|
|
|
17
48
|
#### Step 1: Install package
|
|
18
49
|
|
|
19
50
|
```bash
|
|
20
|
-
npm install @satek-
|
|
51
|
+
npm install @satek-vn/chatbot-widget
|
|
21
52
|
```
|
|
22
53
|
|
|
23
54
|
#### Step 2: Import and use
|
|
24
55
|
|
|
25
56
|
```jsx
|
|
26
57
|
import React from 'react';
|
|
27
|
-
import { ChatWidget } from '@satek-
|
|
58
|
+
import { ChatWidget } from '@satek-vn/chatbot-widget';
|
|
28
59
|
|
|
29
60
|
export default function App() {
|
|
30
61
|
return (
|
|
31
62
|
<ChatWidget
|
|
32
63
|
title="Hỗ trợ"
|
|
64
|
+
logoUrl="https://example.com/logo.png"
|
|
33
65
|
primaryColor="#6366f1"
|
|
34
66
|
auth={{
|
|
35
67
|
code: 'user_1002',
|
|
@@ -39,14 +71,13 @@ export default function App() {
|
|
|
39
71
|
email: 'user@example.com',
|
|
40
72
|
}}
|
|
41
73
|
chatKey="your_chat_key_here"
|
|
42
|
-
features={
|
|
43
|
-
'
|
|
44
|
-
'
|
|
45
|
-
|
|
46
|
-
'
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
]}
|
|
74
|
+
features={{
|
|
75
|
+
attachments: ['image', 'video', 'file'],
|
|
76
|
+
languages: ['english', 'vietnamese'],
|
|
77
|
+
communication: ['voice'],
|
|
78
|
+
chatModes: ['single', 'group'],
|
|
79
|
+
customizations: ['change-color', 'change-theme'],
|
|
80
|
+
}}
|
|
50
81
|
/>
|
|
51
82
|
);
|
|
52
83
|
}
|
|
@@ -65,7 +96,7 @@ export default function App() {
|
|
|
65
96
|
```jsx
|
|
66
97
|
import React from 'react';
|
|
67
98
|
import ReactDOM from 'react-dom/client';
|
|
68
|
-
import { ChatWidget } from '@satek-
|
|
99
|
+
import { ChatWidget } from '@satek-vn/chatbot-widget';
|
|
69
100
|
|
|
70
101
|
const container = document.getElementById('root');
|
|
71
102
|
if (container) {
|
|
@@ -73,6 +104,7 @@ if (container) {
|
|
|
73
104
|
<React.StrictMode>
|
|
74
105
|
<ChatWidget
|
|
75
106
|
title="Hỗ trợ khách hàng"
|
|
107
|
+
logoUrl="https://example.com/logo.png"
|
|
76
108
|
primaryColor="#6366f1"
|
|
77
109
|
auth={{
|
|
78
110
|
code: 'user_1002',
|
|
@@ -82,15 +114,13 @@ if (container) {
|
|
|
82
114
|
email: 'user@example.com',
|
|
83
115
|
}}
|
|
84
116
|
chatKey="your_chat_key_here"
|
|
85
|
-
features={
|
|
86
|
-
'
|
|
87
|
-
'
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
'change-color',
|
|
91
|
-
|
|
92
|
-
'language:vietnamese',
|
|
93
|
-
]}
|
|
117
|
+
features={{
|
|
118
|
+
attachments: ['image', 'video', 'audio', 'file', 'multiple'],
|
|
119
|
+
languages: ['english', 'vietnamese'],
|
|
120
|
+
communication: ['voice'],
|
|
121
|
+
chatModes: ['single', 'group'],
|
|
122
|
+
customizations: ['change-color', 'change-theme'],
|
|
123
|
+
}}
|
|
94
124
|
/>
|
|
95
125
|
</React.StrictMode>,
|
|
96
126
|
);
|
|
@@ -102,13 +132,13 @@ if (container) {
|
|
|
102
132
|
#### Step 1: Add script tag
|
|
103
133
|
|
|
104
134
|
```html
|
|
105
|
-
<script src="https://unpkg.com/@satek-
|
|
135
|
+
<script src="https://unpkg.com/@satek-vn/chatbot-widget/dist/chatbot-widget.umd.js"></script>
|
|
106
136
|
```
|
|
107
137
|
|
|
108
138
|
Or use jsdelivr CDN:
|
|
109
139
|
|
|
110
140
|
```html
|
|
111
|
-
<script src="https://cdn.jsdelivr.net/npm/@satek-
|
|
141
|
+
<script src="https://cdn.jsdelivr.net/npm/@satek-vn/chatbot-widget/dist/chatbot-widget.umd.js"></script>
|
|
112
142
|
```
|
|
113
143
|
|
|
114
144
|
#### Step 2: Initialize widget
|
|
@@ -124,10 +154,11 @@ Or use jsdelivr CDN:
|
|
|
124
154
|
<body>
|
|
125
155
|
<h1>Welcome to our website</h1>
|
|
126
156
|
|
|
127
|
-
<script src="https://unpkg.com/@satek-
|
|
157
|
+
<script src="https://unpkg.com/@satek-vn/chatbot-widget/dist/chatbot-widget.umd.js"></script>
|
|
128
158
|
<script>
|
|
129
159
|
ChatbotWidget.init({
|
|
130
160
|
title: 'Customer Support',
|
|
161
|
+
logoUrl: 'https://example.com/logo.png',
|
|
131
162
|
primaryColor: '#6366f1',
|
|
132
163
|
auth: {
|
|
133
164
|
code: 'user_1001',
|
|
@@ -137,43 +168,50 @@ Or use jsdelivr CDN:
|
|
|
137
168
|
email: 'user@example.com',
|
|
138
169
|
},
|
|
139
170
|
chatKey: 'your_chat_key_here',
|
|
140
|
-
features:
|
|
141
|
-
'
|
|
142
|
-
'
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
'change-color',
|
|
146
|
-
|
|
147
|
-
'language:vietnamese',
|
|
148
|
-
],
|
|
171
|
+
features: {
|
|
172
|
+
attachments: ['image', 'video', 'audio', 'file', 'multiple'],
|
|
173
|
+
languages: ['english', 'vietnamese'],
|
|
174
|
+
communication: ['voice'],
|
|
175
|
+
chatModes: ['single', 'group'],
|
|
176
|
+
customizations: ['change-color', 'change-theme'],
|
|
177
|
+
},
|
|
149
178
|
});
|
|
150
179
|
</script>
|
|
151
180
|
</body>
|
|
152
181
|
</html>
|
|
153
182
|
```
|
|
154
183
|
|
|
155
|
-
|
|
184
|
+
---
|
|
185
|
+
|
|
186
|
+
## Widget Usage
|
|
156
187
|
|
|
157
188
|
### Props / Options
|
|
158
189
|
|
|
159
|
-
| Name
|
|
160
|
-
|
|
|
161
|
-
| `title`
|
|
162
|
-
| `
|
|
163
|
-
| `
|
|
164
|
-
| `
|
|
165
|
-
| `auth
|
|
166
|
-
| `auth.
|
|
167
|
-
| `auth.
|
|
168
|
-
| `auth.
|
|
169
|
-
| `auth.
|
|
170
|
-
| `
|
|
190
|
+
| Name | Type | Required | Description |
|
|
191
|
+
| ------------------------- | ------ | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
192
|
+
| `title` | string | ✅ | Title of the chat widget |
|
|
193
|
+
| `logoUrl` | string | ❌ | URL of the logo image to display in the widget header |
|
|
194
|
+
| `primaryColor` | string | ❌ | Primary color (hex format). Default: #6366f1 |
|
|
195
|
+
| `chatKey` | string | ✅ | Authentication key to connect to backend |
|
|
196
|
+
| `auth` | object | ✅ | User authentication information |
|
|
197
|
+
| `auth.code` | string | ✅ | Unique user identifier |
|
|
198
|
+
| `auth.name` | string | ✅ | User name |
|
|
199
|
+
| `auth.avatar` | string | ✅ | URL of user avatar image |
|
|
200
|
+
| `auth.phone` | string | ❌ | User phone number |
|
|
201
|
+
| `auth.email` | string | ✅ | User email address |
|
|
202
|
+
| `features` | object | ❌ | Feature configuration object with properties: `attachments`, `languages`, `communication`, `chatModes`, `customizations` |
|
|
203
|
+
| `features.attachments` | array | ❌ | Allowed file types for upload: `'image'`, `'video'`, `'audio'`, `'file'`, `'multiple'`. If not provided, no file upload allowed |
|
|
204
|
+
| `features.languages` | array | ❌ | Supported languages: `'english'`, `'vietnamese'`. When multiple languages are enabled, a language switcher appears in the widget. Default: `['english']` |
|
|
205
|
+
| `features.communication` | array | ❌ | Communication features: `'voice'` for voice recording and audio messages. Default: `[]` |
|
|
206
|
+
| `features.chatModes` | array | ❌ | Supported chat modes: `'single'` for one-to-one chat, `'group'` for group chat. Default: `['single']` |
|
|
207
|
+
| `features.customizations` | array | ❌ | User customization options: `'change-color'` to allow color customization, `'change-theme'` to allow theme switching. Default: `[]` |
|
|
171
208
|
|
|
172
209
|
### Configuration example
|
|
173
210
|
|
|
174
211
|
```javascript
|
|
175
212
|
{
|
|
176
213
|
title: 'Customer Support',
|
|
214
|
+
logoUrl: 'https://example.com/logo.png',
|
|
177
215
|
primaryColor: '#FF6B6B',
|
|
178
216
|
auth: {
|
|
179
217
|
code: 'customer_123',
|
|
@@ -183,13 +221,25 @@ Or use jsdelivr CDN:
|
|
|
183
221
|
email: 'john@example.com',
|
|
184
222
|
},
|
|
185
223
|
chatKey: 'secure_key_abc123xyz',
|
|
186
|
-
features:
|
|
224
|
+
features: {
|
|
225
|
+
attachments: ['image', 'video', 'file', 'multiple'],
|
|
226
|
+
languages: ['english', 'vietnamese'],
|
|
227
|
+
communication: ['voice'],
|
|
228
|
+
chatModes: ['single', 'group'],
|
|
229
|
+
customizations: ['change-color', 'change-theme'],
|
|
230
|
+
},
|
|
187
231
|
}
|
|
188
232
|
```
|
|
189
233
|
|
|
234
|
+
---
|
|
235
|
+
|
|
236
|
+
## Configuration
|
|
237
|
+
|
|
238
|
+
---
|
|
239
|
+
|
|
190
240
|
## Customization
|
|
191
241
|
|
|
192
|
-
### Change color
|
|
242
|
+
### Change primary color
|
|
193
243
|
|
|
194
244
|
You can customize the primary color of the widget using the `primaryColor` prop:
|
|
195
245
|
|
|
@@ -213,6 +263,8 @@ ChatbotWidget.init({
|
|
|
213
263
|
|
|
214
264
|
### Change title
|
|
215
265
|
|
|
266
|
+
**React:**
|
|
267
|
+
|
|
216
268
|
```jsx
|
|
217
269
|
<ChatWidget
|
|
218
270
|
title="Customer Service"
|
|
@@ -220,6 +272,8 @@ ChatbotWidget.init({
|
|
|
220
272
|
/>
|
|
221
273
|
```
|
|
222
274
|
|
|
275
|
+
**UMD:**
|
|
276
|
+
|
|
223
277
|
```javascript
|
|
224
278
|
ChatbotWidget.init({
|
|
225
279
|
title: 'Customer Service',
|
|
@@ -227,13 +281,40 @@ ChatbotWidget.init({
|
|
|
227
281
|
});
|
|
228
282
|
```
|
|
229
283
|
|
|
284
|
+
### Change logo
|
|
285
|
+
|
|
286
|
+
You can customize the logo displayed in the widget header using the `logoUrl` prop:
|
|
287
|
+
|
|
288
|
+
**React:**
|
|
289
|
+
|
|
290
|
+
```jsx
|
|
291
|
+
<ChatWidget
|
|
292
|
+
logoUrl="https://example.com/logo.png"
|
|
293
|
+
// ... other props
|
|
294
|
+
/>
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
**UMD:**
|
|
298
|
+
|
|
299
|
+
```javascript
|
|
300
|
+
ChatbotWidget.init({
|
|
301
|
+
logoUrl: 'https://example.com/logo.png',
|
|
302
|
+
// ... other options
|
|
303
|
+
});
|
|
304
|
+
```
|
|
305
|
+
|
|
230
306
|
### Configure features
|
|
231
307
|
|
|
232
308
|
**React:**
|
|
233
309
|
|
|
234
310
|
```jsx
|
|
235
311
|
<ChatWidget
|
|
236
|
-
features={
|
|
312
|
+
features={{
|
|
313
|
+
attachments: ['image', 'video', 'file'],
|
|
314
|
+
languages: ['english', 'vietnamese'],
|
|
315
|
+
communication: ['voice'],
|
|
316
|
+
chatModes: ['single', 'group'],
|
|
317
|
+
}}
|
|
237
318
|
// ... other props
|
|
238
319
|
/>
|
|
239
320
|
```
|
|
@@ -242,20 +323,122 @@ ChatbotWidget.init({
|
|
|
242
323
|
|
|
243
324
|
```javascript
|
|
244
325
|
ChatbotWidget.init({
|
|
245
|
-
features:
|
|
326
|
+
features: {
|
|
327
|
+
attachments: ['image', 'video', 'file'],
|
|
328
|
+
languages: ['english', 'vietnamese'],
|
|
329
|
+
communication: ['voice'],
|
|
330
|
+
chatModes: ['single', 'group'],
|
|
331
|
+
},
|
|
332
|
+
// ... other options
|
|
333
|
+
});
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
### Configure supported attachments
|
|
337
|
+
|
|
338
|
+
Specify which file types users can upload:
|
|
339
|
+
|
|
340
|
+
**React:**
|
|
341
|
+
|
|
342
|
+
```jsx
|
|
343
|
+
<ChatWidget
|
|
344
|
+
features={{
|
|
345
|
+
attachments: ['image', 'video', 'audio', 'file', 'multiple'],
|
|
346
|
+
}}
|
|
347
|
+
// ... other props
|
|
348
|
+
/>
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
**UMD:**
|
|
352
|
+
|
|
353
|
+
```javascript
|
|
354
|
+
ChatbotWidget.init({
|
|
355
|
+
features: {
|
|
356
|
+
attachments: ['image', 'video', 'audio', 'file', 'multiple'],
|
|
357
|
+
},
|
|
358
|
+
// ... other options
|
|
359
|
+
});
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
Supported attachment types:
|
|
363
|
+
|
|
364
|
+
- `'image'` - Image files (jpg, png, etc.)
|
|
365
|
+
- `'video'` - Video files
|
|
366
|
+
- `'audio'` - Audio files
|
|
367
|
+
- `'file'` - General documents
|
|
368
|
+
- `'multiple'` - Allow selecting multiple files at once
|
|
369
|
+
|
|
370
|
+
### Configure communication features
|
|
371
|
+
|
|
372
|
+
Enable audio and video communication capabilities:
|
|
373
|
+
|
|
374
|
+
**React:**
|
|
375
|
+
|
|
376
|
+
```jsx
|
|
377
|
+
<ChatWidget
|
|
378
|
+
features={{
|
|
379
|
+
communication: ['voice'],
|
|
380
|
+
}}
|
|
381
|
+
// ... other props
|
|
382
|
+
/>
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
**UMD:**
|
|
386
|
+
|
|
387
|
+
```javascript
|
|
388
|
+
ChatbotWidget.init({
|
|
389
|
+
features: {
|
|
390
|
+
communication: ['voice'],
|
|
391
|
+
},
|
|
392
|
+
// ... other options
|
|
393
|
+
});
|
|
394
|
+
```
|
|
395
|
+
|
|
396
|
+
Supported communication features:
|
|
397
|
+
|
|
398
|
+
- `'voice'` - Voice recording and sending audio messages
|
|
399
|
+
|
|
400
|
+
### Configure chat modes
|
|
401
|
+
|
|
402
|
+
Enable single-to-single or group chat capabilities:
|
|
403
|
+
|
|
404
|
+
**React:**
|
|
405
|
+
|
|
406
|
+
```jsx
|
|
407
|
+
<ChatWidget
|
|
408
|
+
features={{
|
|
409
|
+
chatModes: ['single', 'group'],
|
|
410
|
+
}}
|
|
411
|
+
// ... other props
|
|
412
|
+
/>
|
|
413
|
+
```
|
|
414
|
+
|
|
415
|
+
**UMD:**
|
|
416
|
+
|
|
417
|
+
```javascript
|
|
418
|
+
ChatbotWidget.init({
|
|
419
|
+
features: {
|
|
420
|
+
chatModes: ['single', 'group'],
|
|
421
|
+
},
|
|
246
422
|
// ... other options
|
|
247
423
|
});
|
|
248
424
|
```
|
|
249
425
|
|
|
426
|
+
Supported chat modes:
|
|
427
|
+
|
|
428
|
+
- `'single'` - One-to-one direct messaging
|
|
429
|
+
- `'group'` - Group chat with multiple participants
|
|
430
|
+
|
|
250
431
|
### Allow color change
|
|
251
432
|
|
|
252
|
-
Enable users to change the widget's color using
|
|
433
|
+
Enable users to change the widget's color and theme using customization features:
|
|
253
434
|
|
|
254
435
|
**React:**
|
|
255
436
|
|
|
256
437
|
```jsx
|
|
257
438
|
<ChatWidget
|
|
258
|
-
features={
|
|
439
|
+
features={{
|
|
440
|
+
customizations: ['change-color', 'change-theme'],
|
|
441
|
+
}}
|
|
259
442
|
// ... other props
|
|
260
443
|
/>
|
|
261
444
|
```
|
|
@@ -264,20 +447,24 @@ Enable users to change the widget's color using the `'change-color'` feature:
|
|
|
264
447
|
|
|
265
448
|
```javascript
|
|
266
449
|
ChatbotWidget.init({
|
|
267
|
-
features:
|
|
450
|
+
features: {
|
|
451
|
+
customizations: ['change-color', 'change-theme'],
|
|
452
|
+
},
|
|
268
453
|
// ... other options
|
|
269
454
|
});
|
|
270
455
|
```
|
|
271
456
|
|
|
272
457
|
### Configure language support
|
|
273
458
|
|
|
274
|
-
Enable language switching by adding language options to the
|
|
459
|
+
Enable language switching by adding language options to the `languages` array in features:
|
|
275
460
|
|
|
276
461
|
**React:**
|
|
277
462
|
|
|
278
463
|
```jsx
|
|
279
464
|
<ChatWidget
|
|
280
|
-
features={
|
|
465
|
+
features={{
|
|
466
|
+
languages: ['english', 'vietnamese'],
|
|
467
|
+
}}
|
|
281
468
|
// ... other props
|
|
282
469
|
/>
|
|
283
470
|
```
|
|
@@ -286,18 +473,22 @@ Enable language switching by adding language options to the features array:
|
|
|
286
473
|
|
|
287
474
|
```javascript
|
|
288
475
|
ChatbotWidget.init({
|
|
289
|
-
features:
|
|
476
|
+
features: {
|
|
477
|
+
languages: ['english', 'vietnamese'],
|
|
478
|
+
},
|
|
290
479
|
// ... other options
|
|
291
480
|
});
|
|
292
481
|
```
|
|
293
482
|
|
|
294
483
|
Supported languages:
|
|
295
484
|
|
|
296
|
-
- `'
|
|
297
|
-
- `'
|
|
485
|
+
- `'english'` - English
|
|
486
|
+
- `'vietnamese'` - Tiếng Việt
|
|
298
487
|
|
|
299
488
|
**Note:** When multiple language options are enabled, users will see a language switcher in the widget interface.
|
|
300
489
|
|
|
490
|
+
---
|
|
491
|
+
|
|
301
492
|
## Troubleshooting
|
|
302
493
|
|
|
303
494
|
### Widget not displaying
|
|
@@ -319,14 +510,690 @@ npm install @reduxjs/toolkit react-redux wasm-media-encoders
|
|
|
319
510
|
- Check `chatKey` and backend configuration
|
|
320
511
|
- Make sure CORS is properly configured on the server
|
|
321
512
|
|
|
513
|
+
---
|
|
514
|
+
|
|
515
|
+
## 🔌 Advanced: Core SDK API (SDK Documentation)
|
|
516
|
+
|
|
517
|
+
> **Bridge Note:** The Chatbot Widget is a pre-built, user-friendly interface built on top of the Core SDK. If you're using the Widget component, you don't need to interact with the SDK directly. This section is for **advanced users** who want to build a **custom UI** or integrate chat functionality into their own applications using the SDK's lower-level API.
|
|
518
|
+
|
|
519
|
+
---
|
|
520
|
+
|
|
521
|
+
### SDK Usage Guide
|
|
522
|
+
|
|
523
|
+
This documentation provides detailed instructions on how to use the Chat SDK functions for real-time chat applications.
|
|
524
|
+
|
|
525
|
+
#### SDK Table of Contents
|
|
526
|
+
|
|
527
|
+
1. [SDK Initialization](#sdk-initialization)
|
|
528
|
+
2. [Authentication Management](#authentication-management)
|
|
529
|
+
3. [Receiver Management](#receiver-management)
|
|
530
|
+
4. [Member Management](#member-management)
|
|
531
|
+
5. [Chat Management](#chat-management)
|
|
532
|
+
6. [Message Management](#message-management)
|
|
533
|
+
7. [Event System](#event-system)
|
|
534
|
+
|
|
535
|
+
---
|
|
536
|
+
|
|
537
|
+
#### SDK Initialization
|
|
538
|
+
|
|
539
|
+
##### Step 1: Import SDK
|
|
540
|
+
|
|
541
|
+
```html
|
|
542
|
+
<script src="https://chat.satek.vn/sdk/1.0.js?key=[API KEY]"></script>
|
|
543
|
+
```
|
|
544
|
+
|
|
545
|
+
##### Step 2: Create instance and configure
|
|
546
|
+
|
|
547
|
+
```javascript
|
|
548
|
+
// Create SDK instance
|
|
549
|
+
const chatSDK = new initSChat();
|
|
550
|
+
|
|
551
|
+
// Create SDK instance with a workspace
|
|
552
|
+
const chatSDK = new initSChat('dev');
|
|
553
|
+
|
|
554
|
+
// Configure if needed
|
|
555
|
+
chatSDK.setConfig({
|
|
556
|
+
// Custom configuration
|
|
557
|
+
});
|
|
558
|
+
```
|
|
559
|
+
|
|
560
|
+
---
|
|
561
|
+
|
|
562
|
+
#### Authentication Management
|
|
563
|
+
|
|
564
|
+
#### `setAuth(data)` - Login/Create Account
|
|
565
|
+
|
|
566
|
+
Create or login a member account.
|
|
567
|
+
|
|
568
|
+
**Parameters:**
|
|
569
|
+
|
|
570
|
+
- `data` (Object): Member information
|
|
571
|
+
- `code` (String, required): Unique identifier code
|
|
572
|
+
- `name` (String, required): Member name
|
|
573
|
+
- `avatar` (String, optional): Avatar image URL
|
|
574
|
+
- `phone` (String, optional): Phone number
|
|
575
|
+
- `email` (String, optional): Email address
|
|
576
|
+
|
|
577
|
+
**Returns:** Promise returning member object
|
|
578
|
+
|
|
579
|
+
**Example:**
|
|
580
|
+
|
|
581
|
+
```javascript
|
|
582
|
+
await chatSDK.setAuth({
|
|
583
|
+
code: 'user_1001',
|
|
584
|
+
name: 'John Doe',
|
|
585
|
+
avatar: 'https://example.com/avatar.jpg',
|
|
586
|
+
phone: '0123456789',
|
|
587
|
+
email: 'user@example.com',
|
|
588
|
+
});
|
|
589
|
+
```
|
|
590
|
+
|
|
591
|
+
**Note:**
|
|
592
|
+
|
|
593
|
+
- This function also automatically connects to the realtime server
|
|
594
|
+
- Loads unread message count from server
|
|
595
|
+
- Calling this function initializes the realtime connection
|
|
596
|
+
|
|
597
|
+
---
|
|
598
|
+
|
|
599
|
+
#### `getAuth()` - Get Current Account Information
|
|
600
|
+
|
|
601
|
+
Get logged-in member information.
|
|
602
|
+
|
|
603
|
+
**Returns:** Member object or null
|
|
604
|
+
|
|
605
|
+
**Example:**
|
|
606
|
+
|
|
607
|
+
```javascript
|
|
608
|
+
const currentUser = chatSDK.getAuth();
|
|
609
|
+
console.log(currentUser);
|
|
610
|
+
```
|
|
611
|
+
|
|
612
|
+
---
|
|
613
|
+
|
|
614
|
+
#### `clearAuth()` - Logout
|
|
615
|
+
|
|
616
|
+
Clear current authentication information.
|
|
617
|
+
|
|
618
|
+
**Example:**
|
|
619
|
+
|
|
620
|
+
```javascript
|
|
621
|
+
chatSDK.clearAuth();
|
|
622
|
+
```
|
|
623
|
+
|
|
624
|
+
---
|
|
625
|
+
|
|
626
|
+
#### Receiver Management
|
|
627
|
+
|
|
628
|
+
#### `setReceiver(data)` - Set Receiver
|
|
629
|
+
|
|
630
|
+
Create receiver account (typically used for 1-1 chat).
|
|
631
|
+
|
|
632
|
+
**Parameters:**
|
|
633
|
+
|
|
634
|
+
- `data` (Object): Receiver information (same as `setAuth`)
|
|
635
|
+
|
|
636
|
+
**Returns:** Promise returning receiver object
|
|
637
|
+
|
|
638
|
+
**Example:**
|
|
639
|
+
|
|
640
|
+
```javascript
|
|
641
|
+
await chatSDK.setReceiver({
|
|
642
|
+
code: 'user_1002',
|
|
643
|
+
name: 'Jane Doe',
|
|
644
|
+
avatar: 'https://example.com/avatar2.jpg',
|
|
645
|
+
});
|
|
646
|
+
```
|
|
647
|
+
|
|
648
|
+
---
|
|
649
|
+
|
|
650
|
+
#### `getReceiver()` - Get Receiver Information
|
|
651
|
+
|
|
652
|
+
**Returns:** Receiver object or null
|
|
653
|
+
|
|
654
|
+
**Example:**
|
|
655
|
+
|
|
656
|
+
```javascript
|
|
657
|
+
const receiver = chatSDK.getReceiver();
|
|
658
|
+
console.log(receiver);
|
|
659
|
+
```
|
|
660
|
+
|
|
661
|
+
---
|
|
662
|
+
|
|
663
|
+
#### `clearReceiver()` - Clear Receiver Information
|
|
664
|
+
|
|
665
|
+
**Example:**
|
|
666
|
+
|
|
667
|
+
```javascript
|
|
668
|
+
chatSDK.clearReceiver();
|
|
669
|
+
```
|
|
670
|
+
|
|
671
|
+
---
|
|
672
|
+
|
|
673
|
+
#### Member Management
|
|
674
|
+
|
|
675
|
+
#### `getMembers(chatId, limit, page, include)` - Get Member List
|
|
676
|
+
|
|
677
|
+
Get list of members in a chat or all members.
|
|
678
|
+
|
|
679
|
+
**Parameters:**
|
|
680
|
+
|
|
681
|
+
- `chatId` (Number, optional): Chat ID. If null, get all members
|
|
682
|
+
- `limit` (Number, optional): Number of records (default: 0 = all)
|
|
683
|
+
- `page` (Number, optional): Page number (default: 1)
|
|
684
|
+
- `include` (String, optional): Additional fields to retrieve
|
|
685
|
+
|
|
686
|
+
**Returns:** Promise returning member list
|
|
687
|
+
|
|
688
|
+
**Example:**
|
|
689
|
+
|
|
690
|
+
```javascript
|
|
691
|
+
// Get all members
|
|
692
|
+
const allMembers = await chatSDK.getMembers();
|
|
693
|
+
|
|
694
|
+
// Get members of a chat
|
|
695
|
+
const chatMembers = await chatSDK.getMembers(123, 50, 1);
|
|
696
|
+
|
|
697
|
+
// Pagination
|
|
698
|
+
const page1Members = await chatSDK.getMembers(123, 10, 1);
|
|
699
|
+
const page2Members = await chatSDK.getMembers(123, 10, 2);
|
|
700
|
+
```
|
|
701
|
+
|
|
702
|
+
---
|
|
703
|
+
|
|
704
|
+
#### `addMember(chatId, memberId)` - Add Member to Group
|
|
705
|
+
|
|
706
|
+
Invite another member to the group chat.
|
|
707
|
+
|
|
708
|
+
**Parameters:**
|
|
709
|
+
|
|
710
|
+
- `chatId` (Number, required): Chat ID
|
|
711
|
+
- `memberId` (Number, required): Member ID to add
|
|
712
|
+
|
|
713
|
+
**Returns:** Promise returning result
|
|
714
|
+
|
|
715
|
+
**Example:**
|
|
716
|
+
|
|
717
|
+
```javascript
|
|
718
|
+
await chatSDK.addMember(123, 456);
|
|
719
|
+
```
|
|
720
|
+
|
|
721
|
+
---
|
|
722
|
+
|
|
723
|
+
#### `removeMember(chatId, memberId)` - Remove Member from Group
|
|
724
|
+
|
|
725
|
+
Remove a member from the group or member leaves the group.
|
|
726
|
+
|
|
727
|
+
**Parameters:**
|
|
728
|
+
|
|
729
|
+
- `chatId` (Number, required): Chat ID
|
|
730
|
+
- `memberId` (Number, required): Member ID to remove
|
|
731
|
+
|
|
732
|
+
**Returns:** Promise returning result
|
|
733
|
+
|
|
734
|
+
**Example:**
|
|
735
|
+
|
|
736
|
+
```javascript
|
|
737
|
+
await chatSDK.removeMember(123, 456);
|
|
738
|
+
```
|
|
739
|
+
|
|
740
|
+
**Note:** If you remove yourself from the group, the group will be completely deleted
|
|
741
|
+
|
|
742
|
+
---
|
|
743
|
+
|
|
744
|
+
#### Chat Management
|
|
745
|
+
|
|
746
|
+
#### `getChats(limit, page)` - Get Chat List
|
|
747
|
+
|
|
748
|
+
Get list of chats for the current member.
|
|
749
|
+
|
|
750
|
+
**Parameters:**
|
|
751
|
+
|
|
752
|
+
- `limit` (Number, optional): Number of items (default: 0 = all)
|
|
753
|
+
- `page` (Number, optional): Page number (default: 1)
|
|
754
|
+
|
|
755
|
+
**Returns:** Promise returning chat list
|
|
756
|
+
|
|
757
|
+
**Example:**
|
|
758
|
+
|
|
759
|
+
```javascript
|
|
760
|
+
// Get all chats
|
|
761
|
+
const chats = await chatSDK.getChats();
|
|
762
|
+
|
|
763
|
+
// Pagination: 20 chats per page
|
|
764
|
+
const page1 = await chatSDK.getChats(20, 1);
|
|
765
|
+
const page2 = await chatSDK.getChats(20, 2);
|
|
766
|
+
```
|
|
767
|
+
|
|
768
|
+
---
|
|
769
|
+
|
|
770
|
+
#### `findChatByReceiver(receiverId)` - Find Chat with Receiver
|
|
771
|
+
|
|
772
|
+
Find 1-1 chat with a specific person.
|
|
773
|
+
|
|
774
|
+
**Parameters:**
|
|
775
|
+
|
|
776
|
+
- `receiverId` (Number, required): Receiver ID
|
|
777
|
+
|
|
778
|
+
**Returns:** Promise returning chat object or null
|
|
779
|
+
|
|
780
|
+
**Example:**
|
|
781
|
+
|
|
782
|
+
```javascript
|
|
783
|
+
const existChat = await chatSDK.findChatByReceiver(456);
|
|
784
|
+
|
|
785
|
+
if (existChat) {
|
|
786
|
+
console.log('Chat already exists');
|
|
787
|
+
} else {
|
|
788
|
+
console.log('No chat with this person yet');
|
|
789
|
+
}
|
|
790
|
+
```
|
|
791
|
+
|
|
792
|
+
---
|
|
793
|
+
|
|
794
|
+
#### `addChat(receiverId, content)` - Create 1-1 Chat
|
|
795
|
+
|
|
796
|
+
Create a new chat with someone (or get existing chat if already exists).
|
|
797
|
+
|
|
798
|
+
**Parameters:**
|
|
799
|
+
|
|
800
|
+
- `receiverId` (Number, required): Receiver ID
|
|
801
|
+
- `content` (String, optional): First message (if needed)
|
|
802
|
+
|
|
803
|
+
**Returns:** Promise returning chat object
|
|
804
|
+
|
|
805
|
+
**Example:**
|
|
806
|
+
|
|
807
|
+
```javascript
|
|
808
|
+
// Create new chat
|
|
809
|
+
const chat1 = await chatSDK.addChat(456);
|
|
810
|
+
|
|
811
|
+
// Create chat with first message
|
|
812
|
+
const chat2 = await chatSDK.addChat(456, 'Hello!');
|
|
813
|
+
```
|
|
814
|
+
|
|
815
|
+
---
|
|
816
|
+
|
|
817
|
+
#### `addGroup(memberIds, name, avatar)` - Create Group Chat
|
|
818
|
+
|
|
819
|
+
Create a new group chat.
|
|
820
|
+
|
|
821
|
+
**Parameters:**
|
|
822
|
+
|
|
823
|
+
- `memberIds` (Array, required): List of member IDs (at least 2 other members)
|
|
824
|
+
- `name` (String, required): Group name
|
|
825
|
+
- `avatar` (String|File, optional): New avatar URL or File
|
|
826
|
+
|
|
827
|
+
**Returns:** Promise returning group object
|
|
828
|
+
|
|
829
|
+
**Example:**
|
|
830
|
+
|
|
831
|
+
```javascript
|
|
832
|
+
// Create simple group
|
|
833
|
+
const group = await chatSDK.addGroup([456, 789], 'Project A Group');
|
|
834
|
+
|
|
835
|
+
// Create group with avatar
|
|
836
|
+
const groupWithAvatar = await chatSDK.addGroup(
|
|
837
|
+
[456, 789],
|
|
838
|
+
'Project B Group',
|
|
839
|
+
'https://example.com/group.jpg',
|
|
840
|
+
);
|
|
841
|
+
```
|
|
842
|
+
|
|
843
|
+
---
|
|
844
|
+
|
|
845
|
+
#### `updateGroup(chatId, name, avatar)` - Update Group Information
|
|
846
|
+
|
|
847
|
+
Update group name and avatar.
|
|
848
|
+
|
|
849
|
+
**Parameters:**
|
|
850
|
+
|
|
851
|
+
- `chatId` (Number, required): Group ID
|
|
852
|
+
- `name` (String, required): New group name
|
|
853
|
+
- `avatar` (String|File, optional): New avatar URL or File
|
|
854
|
+
|
|
855
|
+
**Returns:** Promise returning updated group object
|
|
856
|
+
|
|
857
|
+
**Example:**
|
|
858
|
+
|
|
859
|
+
```javascript
|
|
860
|
+
// Update name only
|
|
861
|
+
await chatSDK.updateGroup(123, 'New Group Name');
|
|
862
|
+
|
|
863
|
+
// Update both name and avatar
|
|
864
|
+
await chatSDK.updateGroup(
|
|
865
|
+
123,
|
|
866
|
+
'New Group Name',
|
|
867
|
+
'https://example.com/new-avatar.jpg',
|
|
868
|
+
);
|
|
869
|
+
```
|
|
870
|
+
|
|
871
|
+
---
|
|
872
|
+
|
|
873
|
+
#### `removeChat(chatId)` - Delete Chat
|
|
874
|
+
|
|
875
|
+
Delete a chat (1-1 chat or group).
|
|
876
|
+
|
|
877
|
+
**Parameters:**
|
|
878
|
+
|
|
879
|
+
- `chatId` (Number, required): Chat ID
|
|
880
|
+
|
|
881
|
+
**Returns:** Promise returning result
|
|
882
|
+
|
|
883
|
+
**Example:**
|
|
884
|
+
|
|
885
|
+
```javascript
|
|
886
|
+
await chatSDK.removeChat(123);
|
|
887
|
+
```
|
|
888
|
+
|
|
889
|
+
---
|
|
890
|
+
|
|
891
|
+
#### `readChat(chatId)` - Mark Chat as Read
|
|
892
|
+
|
|
893
|
+
Mark a chat as read.
|
|
894
|
+
|
|
895
|
+
**Parameters:**
|
|
896
|
+
|
|
897
|
+
- `chatId` (Number, required): Chat ID
|
|
898
|
+
|
|
899
|
+
**Returns:** Promise returning result
|
|
900
|
+
|
|
901
|
+
**Example:**
|
|
902
|
+
|
|
903
|
+
```javascript
|
|
904
|
+
await chatSDK.readChat(123);
|
|
905
|
+
```
|
|
906
|
+
|
|
907
|
+
---
|
|
908
|
+
|
|
909
|
+
#### `unreadChat(chatId)` - Mark Chat as Unread
|
|
910
|
+
|
|
911
|
+
Mark a chat as unread.
|
|
912
|
+
|
|
913
|
+
**Parameters:**
|
|
914
|
+
|
|
915
|
+
- `chatId` (Number, required): Chat ID
|
|
916
|
+
|
|
917
|
+
**Returns:** Promise returning result
|
|
918
|
+
|
|
919
|
+
**Example:**
|
|
920
|
+
|
|
921
|
+
```javascript
|
|
922
|
+
await chatSDK.unreadChat(123);
|
|
923
|
+
```
|
|
924
|
+
|
|
925
|
+
---
|
|
926
|
+
|
|
927
|
+
#### Message Management
|
|
928
|
+
|
|
929
|
+
#### `getMessages(chatId, limit, page)` - Get Message List
|
|
930
|
+
|
|
931
|
+
Get list of messages in a chat (supports pagination for loading history).
|
|
932
|
+
|
|
933
|
+
**Parameters:**
|
|
934
|
+
|
|
935
|
+
- `chatId` (Number, required): Chat ID
|
|
936
|
+
- `limit` (Number, optional): Number of messages (default: 20)
|
|
937
|
+
- `page` (Number, optional): Page number (default: 1)
|
|
938
|
+
|
|
939
|
+
**Returns:** Promise returning message list
|
|
940
|
+
|
|
941
|
+
**Example:**
|
|
942
|
+
|
|
943
|
+
```javascript
|
|
944
|
+
// Get last 20 messages
|
|
945
|
+
const messages = await chatSDK.getMessages(123);
|
|
946
|
+
|
|
947
|
+
// Get 50 messages
|
|
948
|
+
const moreMessages = await chatSDK.getMessages(123, 50);
|
|
949
|
+
|
|
950
|
+
// Load history: page 2
|
|
951
|
+
const oldMessages = await chatSDK.getMessages(123, 20, 2);
|
|
952
|
+
```
|
|
953
|
+
|
|
954
|
+
---
|
|
955
|
+
|
|
956
|
+
#### `addMessage(chatId, content, files, replyId)` - Send Message
|
|
957
|
+
|
|
958
|
+
Send a message with content, files, or reply to another message.
|
|
959
|
+
|
|
960
|
+
**Parameters:**
|
|
961
|
+
|
|
962
|
+
- `chatId` (Number, required): Chat ID
|
|
963
|
+
- `content` (String, optional): Message content (required if no files)
|
|
964
|
+
- `files` (FileList|File[], optional): List of files to send
|
|
965
|
+
- `replyId` (Number, optional): Message ID to reply to
|
|
966
|
+
|
|
967
|
+
**Returns:** Promise returning sent message object
|
|
968
|
+
|
|
969
|
+
**Example:**
|
|
970
|
+
|
|
971
|
+
```javascript
|
|
972
|
+
// Send text message
|
|
973
|
+
await chatSDK.addMessage(123, 'Hello!');
|
|
974
|
+
|
|
975
|
+
// Send message with file
|
|
976
|
+
const fileInput = document.querySelector('input[type=file]');
|
|
977
|
+
const files = fileInput.files;
|
|
978
|
+
await chatSDK.addMessage(123, 'Check this file', files);
|
|
979
|
+
|
|
980
|
+
// Reply to another message
|
|
981
|
+
await chatSDK.addMessage(123, 'Agreed!', null, 456);
|
|
982
|
+
|
|
983
|
+
// Send file only (no content)
|
|
984
|
+
await chatSDK.addMessage(123, null, files);
|
|
985
|
+
```
|
|
986
|
+
|
|
987
|
+
---
|
|
988
|
+
|
|
989
|
+
#### `actionMessage(chatId, messageId, action)` - Interact with Message
|
|
990
|
+
|
|
991
|
+
Perform interactions with messages like like, love, revoke, remove.
|
|
992
|
+
|
|
993
|
+
**Parameters:**
|
|
994
|
+
|
|
995
|
+
- `chatId` (Number, required): Chat ID
|
|
996
|
+
- `messageId` (Number, required): Message ID
|
|
997
|
+
- `action` (String, required): Interaction type
|
|
998
|
+
- `like`: Like message
|
|
999
|
+
- `love`: Love message
|
|
1000
|
+
- `revoke`: Revoke message (delete for everyone)
|
|
1001
|
+
- `remove`: Remove message (disable only on your device)
|
|
1002
|
+
|
|
1003
|
+
**Returns:** Promise returning result
|
|
1004
|
+
|
|
1005
|
+
**Example:**
|
|
1006
|
+
|
|
1007
|
+
```javascript
|
|
1008
|
+
// Like message
|
|
1009
|
+
await chatSDK.actionMessage(123, 456, 'like');
|
|
1010
|
+
|
|
1011
|
+
// Love message
|
|
1012
|
+
await chatSDK.actionMessage(123, 456, 'love');
|
|
1013
|
+
|
|
1014
|
+
// Revoke message
|
|
1015
|
+
await chatSDK.actionMessage(123, 456, 'revoke');
|
|
1016
|
+
|
|
1017
|
+
// Remove message
|
|
1018
|
+
await chatSDK.actionMessage(123, 456, 'remove');
|
|
1019
|
+
```
|
|
1020
|
+
|
|
1021
|
+
---
|
|
1022
|
+
|
|
1023
|
+
## Event System
|
|
1024
|
+
|
|
1025
|
+
SDK uses an event system to notify real-time changes.
|
|
1026
|
+
|
|
1027
|
+
### List of Events
|
|
1028
|
+
|
|
1029
|
+
```javascript
|
|
1030
|
+
chatSDK.EVENTS = {
|
|
1031
|
+
chats_created: 'chats.created', // New chat created
|
|
1032
|
+
chats_updated: 'chats.updated', // Chat updated
|
|
1033
|
+
chats_deleted: 'chats.deleted', // Chat deleted
|
|
1034
|
+
chats_member: 'chats.member', // Member joined/left group
|
|
1035
|
+
chats_action: 'chats.action', // Mark read/unread
|
|
1036
|
+
chats_message: 'chats.message', // New message or action
|
|
1037
|
+
members_connect: 'members.connect', // Member connected (online)
|
|
1038
|
+
members_disconnect: 'members.disconnect', // Member disconnected (offline)
|
|
1039
|
+
new_message: 'new_message', // Unread message count updated
|
|
1040
|
+
};
|
|
1041
|
+
```
|
|
1042
|
+
|
|
1043
|
+
---
|
|
1044
|
+
|
|
1045
|
+
### `addEventListener(event, listener)` - Register Event
|
|
1046
|
+
|
|
1047
|
+
Listen to a real-time event.
|
|
1048
|
+
|
|
1049
|
+
**Parameters:**
|
|
1050
|
+
|
|
1051
|
+
- `event` (String, required): Event name (from `EVENTS`)
|
|
1052
|
+
- `listener` (Function, required): Callback function executed when event occurs
|
|
1053
|
+
|
|
1054
|
+
**Example:**
|
|
1055
|
+
|
|
1056
|
+
```javascript
|
|
1057
|
+
// Listen for new messages
|
|
1058
|
+
chatSDK.addEventListener(chatSDK.EVENTS.chats_message, (data) => {
|
|
1059
|
+
console.log('New message:', data.message);
|
|
1060
|
+
console.log('Chat:', data.chat);
|
|
1061
|
+
console.log('Type:', data.type);
|
|
1062
|
+
});
|
|
1063
|
+
|
|
1064
|
+
// Listen for new chats
|
|
1065
|
+
chatSDK.addEventListener(chatSDK.EVENTS.chats_created, (data) => {
|
|
1066
|
+
console.log('New chat:', data.chat);
|
|
1067
|
+
});
|
|
1068
|
+
|
|
1069
|
+
// Listen for chat updates
|
|
1070
|
+
chatSDK.addEventListener(chatSDK.EVENTS.chats_updated, (data) => {
|
|
1071
|
+
console.log('Updated chat:', data.chat);
|
|
1072
|
+
});
|
|
1073
|
+
|
|
1074
|
+
// Listen for chat deletion
|
|
1075
|
+
chatSDK.addEventListener(chatSDK.EVENTS.chats_deleted, (data) => {
|
|
1076
|
+
console.log('Deleted chat ID:', data.chat_id);
|
|
1077
|
+
});
|
|
1078
|
+
|
|
1079
|
+
// Listen for member join/leave
|
|
1080
|
+
chatSDK.addEventListener(chatSDK.EVENTS.chats_member, (data) => {
|
|
1081
|
+
if (data.type === 'join') {
|
|
1082
|
+
console.log('New member:', data.member);
|
|
1083
|
+
} else if (data.type === 'leave') {
|
|
1084
|
+
console.log('Member left: ID', data.member_id);
|
|
1085
|
+
}
|
|
1086
|
+
});
|
|
1087
|
+
|
|
1088
|
+
// Listen for read/unread actions
|
|
1089
|
+
chatSDK.addEventListener(chatSDK.EVENTS.chats_action, (data) => {
|
|
1090
|
+
console.log('Action type:', data.type);
|
|
1091
|
+
console.log('Chat:', data.chat);
|
|
1092
|
+
});
|
|
1093
|
+
|
|
1094
|
+
// Listen for member online/offline status
|
|
1095
|
+
chatSDK.addEventListener(chatSDK.EVENTS.members_connect, (data) => {
|
|
1096
|
+
console.log('Member connected - Socket ID:', data.socketId);
|
|
1097
|
+
console.log('Timestamp:', data.timestamp);
|
|
1098
|
+
});
|
|
1099
|
+
|
|
1100
|
+
chatSDK.addEventListener(chatSDK.EVENTS.members_disconnect, (data) => {
|
|
1101
|
+
console.log('Member disconnected - Socket ID:', data.socketId);
|
|
1102
|
+
});
|
|
1103
|
+
|
|
1104
|
+
// Listen for unread message count
|
|
1105
|
+
chatSDK.addEventListener(chatSDK.EVENTS.new_message, (data) => {
|
|
1106
|
+
console.log('Unread messages:', data.new);
|
|
1107
|
+
});
|
|
1108
|
+
```
|
|
1109
|
+
|
|
1110
|
+
---
|
|
1111
|
+
|
|
1112
|
+
### `removeEventListener(event, listener)` - Unregister Event
|
|
1113
|
+
|
|
1114
|
+
Stop listening to an event.
|
|
1115
|
+
|
|
1116
|
+
**Parameters:**
|
|
1117
|
+
|
|
1118
|
+
- `event` (String, required): Event name
|
|
1119
|
+
- `listener` (Function, optional): Callback function to remove. If null, remove all listeners
|
|
1120
|
+
|
|
1121
|
+
**Example:**
|
|
1122
|
+
|
|
1123
|
+
```javascript
|
|
1124
|
+
// Define listener function
|
|
1125
|
+
const messageListener = (data) => {
|
|
1126
|
+
console.log('Message:', data.message);
|
|
1127
|
+
};
|
|
1128
|
+
|
|
1129
|
+
// Register
|
|
1130
|
+
chatSDK.addEventListener(chatSDK.EVENTS.chats_message, messageListener);
|
|
1131
|
+
|
|
1132
|
+
// Unregister specific function
|
|
1133
|
+
chatSDK.removeEventListener(chatSDK.EVENTS.chats_message, messageListener);
|
|
1134
|
+
|
|
1135
|
+
// Remove all listeners for the event
|
|
1136
|
+
chatSDK.removeEventListener(chatSDK.EVENTS.chats_message);
|
|
1137
|
+
```
|
|
1138
|
+
|
|
1139
|
+
---
|
|
1140
|
+
|
|
1141
|
+
### `setConfig(config)` - Set Configuration
|
|
1142
|
+
|
|
1143
|
+
Set custom configuration options for SDK.
|
|
1144
|
+
|
|
1145
|
+
**Parameters:**
|
|
1146
|
+
|
|
1147
|
+
- `config` (Object): Configuration options
|
|
1148
|
+
|
|
1149
|
+
**Example:**
|
|
1150
|
+
|
|
1151
|
+
```javascript
|
|
1152
|
+
chatSDK.setConfig({
|
|
1153
|
+
debugMode: true,
|
|
1154
|
+
maxRetries: 3,
|
|
1155
|
+
});
|
|
1156
|
+
```
|
|
1157
|
+
|
|
1158
|
+
---
|
|
1159
|
+
|
|
1160
|
+
### `runEvent(name, data)` - Push Custom Event
|
|
1161
|
+
|
|
1162
|
+
Push an event to all listeners (usually used for debugging or custom logic).
|
|
1163
|
+
|
|
1164
|
+
**Parameters:**
|
|
1165
|
+
|
|
1166
|
+
- `name` (String, required): Event name
|
|
1167
|
+
- `data` (Object): Event data
|
|
1168
|
+
|
|
1169
|
+
**Example:**
|
|
1170
|
+
|
|
1171
|
+
```javascript
|
|
1172
|
+
chatSDK.runEvent(chatSDK.EVENTS.new_message, { new: 5 });
|
|
1173
|
+
```
|
|
1174
|
+
|
|
1175
|
+
---
|
|
1176
|
+
|
|
1177
|
+
## Important Notes
|
|
1178
|
+
|
|
1179
|
+
1. **Realtime Connection**: The `setAuth()` function automatically connects realtime, no additional call needed
|
|
1180
|
+
2. **Promise-based**: All API functions (except events) return Promise, use `async/await`
|
|
1181
|
+
3. **Event Listeners**: Multiple listeners can be registered for a single event
|
|
1182
|
+
|
|
1183
|
+
---
|
|
1184
|
+
|
|
322
1185
|
## Support
|
|
323
1186
|
|
|
324
|
-
|
|
1187
|
+
For any feedback or support, please contact us via email: info@satek.vn or phone: 024.66.88.33.55.
|
|
1188
|
+
|
|
1189
|
+
---
|
|
325
1190
|
|
|
326
1191
|
## License
|
|
327
1192
|
|
|
328
1193
|
MIT
|
|
329
1194
|
|
|
1195
|
+
---
|
|
1196
|
+
|
|
330
1197
|
## Author
|
|
331
1198
|
|
|
332
|
-
Satek Team
|
|
1199
|
+
Satek Team
|