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