@warriorteam/redai-zalo-sdk 1.3.0 → 1.4.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 +565 -550
- package/dist/index.d.ts +0 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -5
- package/dist/index.js.map +1 -1
- package/dist/services/article.service.d.ts +1 -1
- package/dist/services/article.service.d.ts.map +1 -1
- package/dist/services/article.service.js +24 -16
- package/dist/services/article.service.js.map +1 -1
- package/dist/services/auth.service.d.ts +1 -0
- package/dist/services/auth.service.d.ts.map +1 -1
- package/dist/services/auth.service.js +23 -9
- package/dist/services/auth.service.js.map +1 -1
- package/dist/services/consultation.service.d.ts +63 -16
- package/dist/services/consultation.service.d.ts.map +1 -1
- package/dist/services/consultation.service.js +264 -49
- package/dist/services/consultation.service.js.map +1 -1
- package/dist/services/general-message.service.d.ts +2 -25
- package/dist/services/general-message.service.d.ts.map +1 -1
- package/dist/services/general-message.service.js +11 -112
- package/dist/services/general-message.service.js.map +1 -1
- package/dist/services/group-management.service.d.ts +1 -1
- package/dist/services/group-management.service.d.ts.map +1 -1
- package/dist/services/group-management.service.js +59 -27
- package/dist/services/group-management.service.js.map +1 -1
- package/dist/services/group-message.service.d.ts +1 -1
- package/dist/services/group-message.service.d.ts.map +1 -1
- package/dist/services/group-message.service.js +49 -23
- package/dist/services/group-message.service.js.map +1 -1
- package/dist/services/message-management.service.d.ts +21 -2
- package/dist/services/message-management.service.d.ts.map +1 -1
- package/dist/services/message-management.service.js +83 -7
- package/dist/services/message-management.service.js.map +1 -1
- package/dist/services/oa.service.d.ts +1 -0
- package/dist/services/oa.service.d.ts.map +1 -1
- package/dist/services/oa.service.js +23 -5
- package/dist/services/oa.service.js.map +1 -1
- package/dist/services/user.service.d.ts +108 -18
- package/dist/services/user.service.d.ts.map +1 -1
- package/dist/services/user.service.js +260 -59
- package/dist/services/user.service.js.map +1 -1
- package/dist/services/video-upload.service.d.ts +1 -1
- package/dist/services/video-upload.service.d.ts.map +1 -1
- package/dist/services/video-upload.service.js +11 -8
- package/dist/services/video-upload.service.js.map +1 -1
- package/dist/services/zns.service.d.ts +88 -21
- package/dist/services/zns.service.d.ts.map +1 -1
- package/dist/services/zns.service.js +157 -42
- package/dist/services/zns.service.js.map +1 -1
- package/dist/types/group.d.ts +5 -5
- package/dist/types/group.d.ts.map +1 -1
- package/dist/types/user.d.ts +155 -12
- package/dist/types/user.d.ts.map +1 -1
- package/dist/types/user.js.map +1 -1
- package/dist/types/webhook.d.ts +8 -0
- package/dist/types/webhook.d.ts.map +1 -1
- package/dist/types/webhook.js.map +1 -1
- package/dist/types/zns.d.ts +67 -33
- package/dist/types/zns.d.ts.map +1 -1
- package/dist/zalo-sdk.d.ts +3 -11
- package/dist/zalo-sdk.d.ts.map +1 -1
- package/dist/zalo-sdk.js +0 -10
- package/dist/zalo-sdk.js.map +1 -1
- package/docs/CONSULTATION_SERVICE.md +512 -330
- package/docs/GROUP_MANAGEMENT.md +2 -2
- package/docs/USER_MANAGEMENT.md +481 -1248
- package/docs/WEBHOOK_EVENTS.md +55 -3
- package/package.json +1 -1
- package/dist/services/tag.service.d.ts +0 -144
- package/dist/services/tag.service.d.ts.map +0 -1
- package/dist/services/tag.service.js +0 -184
- package/dist/services/tag.service.js.map +0 -1
- package/dist/services/user-management.service.d.ts +0 -117
- package/dist/services/user-management.service.d.ts.map +0 -1
- package/dist/services/user-management.service.js +0 -239
- package/dist/services/user-management.service.js.map +0 -1
|
@@ -31,6 +31,8 @@ const common_1 = require("../types/common");
|
|
|
31
31
|
class ConsultationService {
|
|
32
32
|
constructor(client) {
|
|
33
33
|
this.client = client;
|
|
34
|
+
// Zalo API endpoint for consultation messages
|
|
35
|
+
this.endpoint = "https://openapi.zalo.me/v3.0/oa/message/cs";
|
|
34
36
|
}
|
|
35
37
|
/**
|
|
36
38
|
* Gửi tin nhắn tư vấn văn bản
|
|
@@ -48,13 +50,16 @@ class ConsultationService {
|
|
|
48
50
|
if (message.text.length > 2000) {
|
|
49
51
|
throw new common_1.ZaloSDKError("Nội dung tin nhắn không được vượt quá 2000 ký tự", -1);
|
|
50
52
|
}
|
|
51
|
-
|
|
53
|
+
// Request structure theo API spec
|
|
52
54
|
const request = {
|
|
53
|
-
recipient
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
recipient: {
|
|
56
|
+
user_id: recipient.user_id,
|
|
57
|
+
},
|
|
58
|
+
message: {
|
|
59
|
+
text: message.text,
|
|
60
|
+
},
|
|
56
61
|
};
|
|
57
|
-
const result = await this.client.apiPost(endpoint, accessToken, request);
|
|
62
|
+
const result = await this.client.apiPost(this.endpoint, accessToken, request);
|
|
58
63
|
if (result.error !== 0) {
|
|
59
64
|
throw new common_1.ZaloSDKError(result.message || "Failed to send consultation text message", result.error, result);
|
|
60
65
|
}
|
|
@@ -72,23 +77,45 @@ class ConsultationService {
|
|
|
72
77
|
}
|
|
73
78
|
/**
|
|
74
79
|
* Gửi tin nhắn tư vấn hình ảnh
|
|
80
|
+
* Endpoint: https://openapi.zalo.me/v3.0/oa/message/cs
|
|
81
|
+
* Method: POST
|
|
82
|
+
*
|
|
75
83
|
* @param accessToken Access token của Official Account
|
|
76
|
-
* @param
|
|
77
|
-
* @param
|
|
84
|
+
* @param userId ID người nhận (user_id)
|
|
85
|
+
* @param imageUrl URL hình ảnh (jpg, png, tối đa 1MB)
|
|
86
|
+
* @param text Tiêu đề ảnh (optional, tối đa 2000 ký tự)
|
|
78
87
|
* @returns Thông tin tin nhắn đã gửi
|
|
79
88
|
*/
|
|
80
|
-
async sendImageMessage(accessToken,
|
|
89
|
+
async sendImageMessage(accessToken, userId, imageUrl, text) {
|
|
81
90
|
try {
|
|
82
|
-
if (!
|
|
91
|
+
if (!imageUrl || imageUrl.trim().length === 0) {
|
|
83
92
|
throw new common_1.ZaloSDKError("URL hình ảnh không được để trống", -1);
|
|
84
93
|
}
|
|
85
|
-
|
|
94
|
+
if (text && text.length > 2000) {
|
|
95
|
+
throw new common_1.ZaloSDKError("Tiêu đề ảnh không được vượt quá 2000 ký tự", -1);
|
|
96
|
+
}
|
|
97
|
+
// Request structure theo API spec
|
|
86
98
|
const request = {
|
|
87
|
-
recipient
|
|
88
|
-
|
|
89
|
-
|
|
99
|
+
recipient: {
|
|
100
|
+
user_id: userId,
|
|
101
|
+
},
|
|
102
|
+
message: {
|
|
103
|
+
...(text && { text: text }),
|
|
104
|
+
attachment: {
|
|
105
|
+
type: "template",
|
|
106
|
+
payload: {
|
|
107
|
+
template_type: "media",
|
|
108
|
+
elements: [
|
|
109
|
+
{
|
|
110
|
+
media_type: "image",
|
|
111
|
+
url: imageUrl,
|
|
112
|
+
},
|
|
113
|
+
],
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
},
|
|
90
117
|
};
|
|
91
|
-
const result = await this.client.apiPost(endpoint, accessToken, request);
|
|
118
|
+
const result = await this.client.apiPost(this.endpoint, accessToken, request);
|
|
92
119
|
if (result.error !== 0) {
|
|
93
120
|
throw new common_1.ZaloSDKError(result.message || "Failed to send consultation image message", result.error, result);
|
|
94
121
|
}
|
|
@@ -105,24 +132,156 @@ class ConsultationService {
|
|
|
105
132
|
}
|
|
106
133
|
}
|
|
107
134
|
/**
|
|
108
|
-
* Gửi tin nhắn tư vấn
|
|
135
|
+
* Gửi tin nhắn tư vấn hình ảnh bằng attachment_id
|
|
136
|
+
* Endpoint: https://openapi.zalo.me/v3.0/oa/message/cs
|
|
137
|
+
* Method: POST
|
|
138
|
+
*
|
|
109
139
|
* @param accessToken Access token của Official Account
|
|
110
|
-
* @param
|
|
111
|
-
* @param
|
|
140
|
+
* @param userId ID người nhận (user_id)
|
|
141
|
+
* @param attachmentId ID của ảnh đã upload (từ API upload ảnh)
|
|
142
|
+
* @param text Tiêu đề ảnh (optional, tối đa 2000 ký tự)
|
|
143
|
+
* @returns Thông tin tin nhắn đã gửi
|
|
144
|
+
*/
|
|
145
|
+
async sendImageByAttachmentId(accessToken, userId, attachmentId, text) {
|
|
146
|
+
try {
|
|
147
|
+
if (!attachmentId || attachmentId.trim().length === 0) {
|
|
148
|
+
throw new common_1.ZaloSDKError("Attachment ID không được để trống", -1);
|
|
149
|
+
}
|
|
150
|
+
if (text && text.length > 2000) {
|
|
151
|
+
throw new common_1.ZaloSDKError("Tiêu đề ảnh không được vượt quá 2000 ký tự", -1);
|
|
152
|
+
}
|
|
153
|
+
// Request structure theo API spec
|
|
154
|
+
const request = {
|
|
155
|
+
recipient: {
|
|
156
|
+
user_id: userId,
|
|
157
|
+
},
|
|
158
|
+
message: {
|
|
159
|
+
...(text && { text: text }),
|
|
160
|
+
attachment: {
|
|
161
|
+
type: "template",
|
|
162
|
+
payload: {
|
|
163
|
+
template_type: "media",
|
|
164
|
+
elements: [
|
|
165
|
+
{
|
|
166
|
+
media_type: "image",
|
|
167
|
+
attachment_id: attachmentId,
|
|
168
|
+
},
|
|
169
|
+
],
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
},
|
|
173
|
+
};
|
|
174
|
+
const result = await this.client.apiPost(this.endpoint, accessToken, request);
|
|
175
|
+
if (result.error !== 0) {
|
|
176
|
+
throw new common_1.ZaloSDKError(result.message || "Failed to send consultation image message", result.error, result);
|
|
177
|
+
}
|
|
178
|
+
if (!result.data) {
|
|
179
|
+
throw new common_1.ZaloSDKError("No response data received", -1);
|
|
180
|
+
}
|
|
181
|
+
return result.data;
|
|
182
|
+
}
|
|
183
|
+
catch (error) {
|
|
184
|
+
if (error instanceof common_1.ZaloSDKError) {
|
|
185
|
+
throw error;
|
|
186
|
+
}
|
|
187
|
+
throw new common_1.ZaloSDKError(`Failed to send consultation image message: ${error.message}`, -1, error);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Gửi tin nhắn tư vấn GIF
|
|
192
|
+
* Endpoint: https://openapi.zalo.me/v3.0/oa/message/cs
|
|
193
|
+
* Method: POST
|
|
194
|
+
*
|
|
195
|
+
* @param accessToken Access token của Official Account
|
|
196
|
+
* @param userId ID người nhận (user_id)
|
|
197
|
+
* @param gifUrl URL ảnh GIF
|
|
198
|
+
* @param width Chiều rộng của ảnh (bắt buộc cho GIF)
|
|
199
|
+
* @param height Chiều cao của ảnh (bắt buộc cho GIF)
|
|
200
|
+
* @param text Tiêu đề ảnh (optional, tối đa 2000 ký tự)
|
|
201
|
+
* @returns Thông tin tin nhắn đã gửi
|
|
202
|
+
*/
|
|
203
|
+
async sendGifMessage(accessToken, userId, gifUrl, width, height, text) {
|
|
204
|
+
try {
|
|
205
|
+
if (!gifUrl || gifUrl.trim().length === 0) {
|
|
206
|
+
throw new common_1.ZaloSDKError("URL GIF không được để trống", -1);
|
|
207
|
+
}
|
|
208
|
+
if (width <= 0 || height <= 0) {
|
|
209
|
+
throw new common_1.ZaloSDKError("Chiều rộng và chiều cao phải lớn hơn 0", -1);
|
|
210
|
+
}
|
|
211
|
+
if (text && text.length > 2000) {
|
|
212
|
+
throw new common_1.ZaloSDKError("Tiêu đề ảnh không được vượt quá 2000 ký tự", -1);
|
|
213
|
+
}
|
|
214
|
+
// Request structure theo API spec
|
|
215
|
+
const request = {
|
|
216
|
+
recipient: {
|
|
217
|
+
user_id: userId,
|
|
218
|
+
},
|
|
219
|
+
message: {
|
|
220
|
+
...(text && { text: text }),
|
|
221
|
+
attachment: {
|
|
222
|
+
type: "template",
|
|
223
|
+
payload: {
|
|
224
|
+
template_type: "media",
|
|
225
|
+
elements: [
|
|
226
|
+
{
|
|
227
|
+
media_type: "gif",
|
|
228
|
+
url: gifUrl,
|
|
229
|
+
width: width,
|
|
230
|
+
height: height,
|
|
231
|
+
},
|
|
232
|
+
],
|
|
233
|
+
},
|
|
234
|
+
},
|
|
235
|
+
},
|
|
236
|
+
};
|
|
237
|
+
const result = await this.client.apiPost(this.endpoint, accessToken, request);
|
|
238
|
+
if (result.error !== 0) {
|
|
239
|
+
throw new common_1.ZaloSDKError(result.message || "Failed to send consultation gif message", result.error, result);
|
|
240
|
+
}
|
|
241
|
+
if (!result.data) {
|
|
242
|
+
throw new common_1.ZaloSDKError("No response data received", -1);
|
|
243
|
+
}
|
|
244
|
+
return result.data;
|
|
245
|
+
}
|
|
246
|
+
catch (error) {
|
|
247
|
+
if (error instanceof common_1.ZaloSDKError) {
|
|
248
|
+
throw error;
|
|
249
|
+
}
|
|
250
|
+
throw new common_1.ZaloSDKError(`Failed to send consultation gif message: ${error.message}`, -1, error);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Gửi tin nhắn tư vấn đính kèm file
|
|
255
|
+
* Endpoint: https://openapi.zalo.me/v3.0/oa/message/cs
|
|
256
|
+
* Method: POST
|
|
257
|
+
*
|
|
258
|
+
* @param accessToken Access token của Official Account
|
|
259
|
+
* @param userId ID người nhận (user_id)
|
|
260
|
+
* @param fileToken Token của file đã upload (từ API upload file)
|
|
112
261
|
* @returns Thông tin tin nhắn đã gửi
|
|
262
|
+
*
|
|
263
|
+
* Note: Cần sử dụng API upload file trước để lấy token
|
|
113
264
|
*/
|
|
114
|
-
async sendFileMessage(accessToken,
|
|
265
|
+
async sendFileMessage(accessToken, userId, fileToken) {
|
|
115
266
|
try {
|
|
116
|
-
if (!
|
|
117
|
-
throw new common_1.ZaloSDKError("
|
|
267
|
+
if (!fileToken || fileToken.trim().length === 0) {
|
|
268
|
+
throw new common_1.ZaloSDKError("File token không được để trống", -1);
|
|
118
269
|
}
|
|
119
|
-
|
|
270
|
+
// Request structure theo API spec
|
|
120
271
|
const request = {
|
|
121
|
-
recipient
|
|
122
|
-
|
|
123
|
-
|
|
272
|
+
recipient: {
|
|
273
|
+
user_id: userId,
|
|
274
|
+
},
|
|
275
|
+
message: {
|
|
276
|
+
attachment: {
|
|
277
|
+
type: "file",
|
|
278
|
+
payload: {
|
|
279
|
+
token: fileToken,
|
|
280
|
+
},
|
|
281
|
+
},
|
|
282
|
+
},
|
|
124
283
|
};
|
|
125
|
-
const result = await this.client.apiPost(endpoint, accessToken, request);
|
|
284
|
+
const result = await this.client.apiPost(this.endpoint, accessToken, request);
|
|
126
285
|
if (result.error !== 0) {
|
|
127
286
|
throw new common_1.ZaloSDKError(result.message || "Failed to send consultation file message", result.error, result);
|
|
128
287
|
}
|
|
@@ -139,26 +298,59 @@ class ConsultationService {
|
|
|
139
298
|
}
|
|
140
299
|
}
|
|
141
300
|
/**
|
|
142
|
-
* Gửi tin nhắn tư vấn
|
|
301
|
+
* Gửi tin nhắn tư vấn theo mẫu yêu cầu thông tin người dùng
|
|
302
|
+
* Endpoint: https://openapi.zalo.me/v3.0/oa/message/cs
|
|
303
|
+
* Method: POST
|
|
304
|
+
*
|
|
143
305
|
* @param accessToken Access token của Official Account
|
|
144
|
-
* @param
|
|
145
|
-
* @param
|
|
306
|
+
* @param userId ID người nhận (user_id)
|
|
307
|
+
* @param title Tiêu đề hiển thị của template (tối đa 100 ký tự)
|
|
308
|
+
* @param subtitle Tiêu đề phụ của template (tối đa 500 ký tự)
|
|
309
|
+
* @param imageUrl Đường dẫn đến ảnh
|
|
146
310
|
* @returns Thông tin tin nhắn đã gửi
|
|
147
311
|
*/
|
|
148
|
-
async
|
|
312
|
+
async sendRequestUserInfoMessage(accessToken, userId, title, subtitle, imageUrl) {
|
|
149
313
|
try {
|
|
150
|
-
|
|
151
|
-
|
|
314
|
+
// Validation theo API spec
|
|
315
|
+
if (!title || title.trim().length === 0) {
|
|
316
|
+
throw new common_1.ZaloSDKError("Tiêu đề không được để trống", -1);
|
|
152
317
|
}
|
|
153
|
-
|
|
318
|
+
if (title.length > 100) {
|
|
319
|
+
throw new common_1.ZaloSDKError("Tiêu đề không được vượt quá 100 ký tự", -1);
|
|
320
|
+
}
|
|
321
|
+
if (!subtitle || subtitle.trim().length === 0) {
|
|
322
|
+
throw new common_1.ZaloSDKError("Tiêu đề phụ không được để trống", -1);
|
|
323
|
+
}
|
|
324
|
+
if (subtitle.length > 500) {
|
|
325
|
+
throw new common_1.ZaloSDKError("Tiêu đề phụ không được vượt quá 500 ký tự", -1);
|
|
326
|
+
}
|
|
327
|
+
if (!imageUrl || imageUrl.trim().length === 0) {
|
|
328
|
+
throw new common_1.ZaloSDKError("URL hình ảnh không được để trống", -1);
|
|
329
|
+
}
|
|
330
|
+
// Request structure theo API spec
|
|
154
331
|
const request = {
|
|
155
|
-
recipient
|
|
156
|
-
|
|
157
|
-
|
|
332
|
+
recipient: {
|
|
333
|
+
user_id: userId,
|
|
334
|
+
},
|
|
335
|
+
message: {
|
|
336
|
+
attachment: {
|
|
337
|
+
type: "template",
|
|
338
|
+
payload: {
|
|
339
|
+
template_type: "request_user_info",
|
|
340
|
+
elements: [
|
|
341
|
+
{
|
|
342
|
+
title: title,
|
|
343
|
+
subtitle: subtitle,
|
|
344
|
+
image_url: imageUrl,
|
|
345
|
+
},
|
|
346
|
+
],
|
|
347
|
+
},
|
|
348
|
+
},
|
|
349
|
+
},
|
|
158
350
|
};
|
|
159
|
-
const result = await this.client.apiPost(endpoint, accessToken, request);
|
|
351
|
+
const result = await this.client.apiPost(this.endpoint, accessToken, request);
|
|
160
352
|
if (result.error !== 0) {
|
|
161
|
-
throw new common_1.ZaloSDKError(result.message || "Failed to send
|
|
353
|
+
throw new common_1.ZaloSDKError(result.message || "Failed to send request user info message", result.error, result);
|
|
162
354
|
}
|
|
163
355
|
if (!result.data) {
|
|
164
356
|
throw new common_1.ZaloSDKError("No response data received", -1);
|
|
@@ -169,27 +361,50 @@ class ConsultationService {
|
|
|
169
361
|
if (error instanceof common_1.ZaloSDKError) {
|
|
170
362
|
throw error;
|
|
171
363
|
}
|
|
172
|
-
throw new common_1.ZaloSDKError(`Failed to send
|
|
364
|
+
throw new common_1.ZaloSDKError(`Failed to send request user info message: ${error.message}`, -1, error);
|
|
173
365
|
}
|
|
174
366
|
}
|
|
175
367
|
/**
|
|
176
|
-
* Gửi tin nhắn tư vấn
|
|
368
|
+
* Gửi tin nhắn tư vấn kèm Sticker
|
|
369
|
+
* Endpoint: https://openapi.zalo.me/v3.0/oa/message/cs
|
|
370
|
+
* Method: POST
|
|
371
|
+
*
|
|
177
372
|
* @param accessToken Access token của Official Account
|
|
178
|
-
* @param
|
|
179
|
-
* @param
|
|
373
|
+
* @param userId ID người nhận (user_id)
|
|
374
|
+
* @param stickerAttachmentId ID của sticker (lấy từ https://stickers.zaloapp.com/)
|
|
180
375
|
* @returns Thông tin tin nhắn đã gửi
|
|
376
|
+
*
|
|
377
|
+
* Note: Sticker ID lấy từ nguồn https://stickers.zaloapp.com/
|
|
378
|
+
* Xem video hướng dẫn: https://vimeo.com/649330161
|
|
181
379
|
*/
|
|
182
|
-
async
|
|
380
|
+
async sendStickerMessage(accessToken, userId, stickerAttachmentId) {
|
|
183
381
|
try {
|
|
184
|
-
|
|
382
|
+
if (!stickerAttachmentId || stickerAttachmentId.trim().length === 0) {
|
|
383
|
+
throw new common_1.ZaloSDKError("Sticker attachment ID không được để trống", -1);
|
|
384
|
+
}
|
|
385
|
+
// Request structure theo API spec
|
|
185
386
|
const request = {
|
|
186
|
-
recipient
|
|
187
|
-
|
|
188
|
-
|
|
387
|
+
recipient: {
|
|
388
|
+
user_id: userId,
|
|
389
|
+
},
|
|
390
|
+
message: {
|
|
391
|
+
attachment: {
|
|
392
|
+
type: "template",
|
|
393
|
+
payload: {
|
|
394
|
+
template_type: "media",
|
|
395
|
+
elements: [
|
|
396
|
+
{
|
|
397
|
+
media_type: "sticker",
|
|
398
|
+
attachment_id: stickerAttachmentId,
|
|
399
|
+
},
|
|
400
|
+
],
|
|
401
|
+
},
|
|
402
|
+
},
|
|
403
|
+
},
|
|
189
404
|
};
|
|
190
|
-
const result = await this.client.apiPost(endpoint, accessToken, request);
|
|
405
|
+
const result = await this.client.apiPost(this.endpoint, accessToken, request);
|
|
191
406
|
if (result.error !== 0) {
|
|
192
|
-
throw new common_1.ZaloSDKError(result.message || "Failed to send consultation message", result.error, result);
|
|
407
|
+
throw new common_1.ZaloSDKError(result.message || "Failed to send consultation sticker message", result.error, result);
|
|
193
408
|
}
|
|
194
409
|
if (!result.data) {
|
|
195
410
|
throw new common_1.ZaloSDKError("No response data received", -1);
|
|
@@ -200,7 +415,7 @@ class ConsultationService {
|
|
|
200
415
|
if (error instanceof common_1.ZaloSDKError) {
|
|
201
416
|
throw error;
|
|
202
417
|
}
|
|
203
|
-
throw new common_1.ZaloSDKError(`Failed to send consultation message: ${error.message}`, -1, error);
|
|
418
|
+
throw new common_1.ZaloSDKError(`Failed to send consultation sticker message: ${error.message}`, -1, error);
|
|
204
419
|
}
|
|
205
420
|
}
|
|
206
421
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consultation.service.js","sourceRoot":"","sources":["../../src/services/consultation.service.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"consultation.service.js","sourceRoot":"","sources":["../../src/services/consultation.service.ts"],"names":[],"mappings":";;;AAMA,4CAA6D;AAE7D;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAa,mBAAmB;IAI9B,YAA6B,MAAkB;QAAlB,WAAM,GAAN,MAAM,CAAY;QAH/C,8CAA8C;QAC7B,aAAQ,GAAG,4CAA4C,CAAC;IAEvB,CAAC;IAEnD;;;;;;OAMG;IACI,KAAK,CAAC,eAAe,CAC1B,WAAmB,EACnB,SAA2B,EAC3B,OAAoB;QAEpB,IAAI,CAAC;YACH,8CAA8C;YAC9C,IAAI,CAAC,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBACtD,MAAM,IAAI,qBAAY,CAAC,uCAAuC,EAAE,CAAC,CAAC,CAAC,CAAC;YACtE,CAAC;YAED,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,GAAG,IAAI,EAAE,CAAC;gBAC/B,MAAM,IAAI,qBAAY,CACpB,kDAAkD,EAClD,CAAC,CAAC,CACH,CAAC;YACJ,CAAC;YAED,kCAAkC;YAClC,MAAM,OAA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AAC,CAAC;YAC1D,CAAC;YAED,OAAO,MAAM,CAAC,IAAI,CAAC;QACrB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,YAAY,qBAAY,EAAE,CAAC;gBAClC,MAAM,KAAK,CAAC;YACd,CAAC;YACD,MAAM,IAAI,qBAAY,CACpB,gDACG,KAAe,CAAC,OACnB,EAAE,EACF,CAAC,CAAC,EACF,KAAK,CACN,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AAriBD,kDAqiBC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ZaloClient } from "../clients/zalo-client";
|
|
2
|
-
import { Message, SendMessageResponse,
|
|
2
|
+
import { Message, SendMessageResponse, ImageMessage, MessageRecipient, AnonymousTextMessage } from "../types/message";
|
|
3
3
|
/**
|
|
4
4
|
* Service xử lý các API tin nhắn tổng quát của Zalo Official Account
|
|
5
5
|
*
|
|
@@ -31,15 +31,8 @@ import { Message, SendMessageResponse, UploadFileResponse, TextMessage, ImageMes
|
|
|
31
31
|
*/
|
|
32
32
|
export declare class GeneralMessageService {
|
|
33
33
|
private readonly client;
|
|
34
|
+
private readonly endpoints;
|
|
34
35
|
constructor(client: ZaloClient);
|
|
35
|
-
/**
|
|
36
|
-
* Gửi tin nhắn phản hồi văn bản
|
|
37
|
-
* @param accessToken Access token của Official Account
|
|
38
|
-
* @param recipient Thông tin người nhận
|
|
39
|
-
* @param message Nội dung tin nhắn văn bản
|
|
40
|
-
* @returns Thông tin tin nhắn đã gửi
|
|
41
|
-
*/
|
|
42
|
-
sendResponseTextMessage(accessToken: string, recipient: MessageRecipient, message: TextMessage): Promise<SendMessageResponse>;
|
|
43
36
|
/**
|
|
44
37
|
* Gửi tin nhắn phản hồi hình ảnh
|
|
45
38
|
* @param accessToken Access token của Official Account
|
|
@@ -56,22 +49,6 @@ export declare class GeneralMessageService {
|
|
|
56
49
|
* @returns Thông tin tin nhắn đã gửi
|
|
57
50
|
*/
|
|
58
51
|
sendAnonymousMessage(accessToken: string, recipient: MessageRecipient, message: AnonymousTextMessage): Promise<SendMessageResponse>;
|
|
59
|
-
/**
|
|
60
|
-
* Upload file để sử dụng trong tin nhắn
|
|
61
|
-
* @param accessToken Access token của Official Account
|
|
62
|
-
* @param file File data (base64 hoặc buffer)
|
|
63
|
-
* @param fileName Tên file
|
|
64
|
-
* @returns Thông tin file đã upload
|
|
65
|
-
*/
|
|
66
|
-
uploadFile(accessToken: string, file: string | Buffer, fileName: string): Promise<UploadFileResponse>;
|
|
67
|
-
/**
|
|
68
|
-
* Upload hình ảnh để sử dụng trong tin nhắn
|
|
69
|
-
* @param accessToken Access token của Official Account
|
|
70
|
-
* @param image Image data (base64 hoặc buffer)
|
|
71
|
-
* @param fileName Tên file hình ảnh
|
|
72
|
-
* @returns Thông tin hình ảnh đã upload
|
|
73
|
-
*/
|
|
74
|
-
uploadImage(accessToken: string, image: string | Buffer, fileName: string): Promise<UploadFileResponse>;
|
|
75
52
|
/**
|
|
76
53
|
* Gửi tin nhắn tổng quát
|
|
77
54
|
* @param accessToken Access token của Official Account
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"general-message.service.d.ts","sourceRoot":"","sources":["../../src/services/general-message.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EACL,OAAO,EAEP,mBAAmB,EACnB,
|
|
1
|
+
{"version":3,"file":"general-message.service.d.ts","sourceRoot":"","sources":["../../src/services/general-message.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EACL,OAAO,EAEP,mBAAmB,EACnB,YAAY,EACZ,gBAAgB,EAChB,oBAAoB,EACrB,MAAM,kBAAkB,CAAC;AAG1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,qBAAa,qBAAqB;IAWpB,OAAO,CAAC,QAAQ,CAAC,MAAM;IATnC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAOxB;gBAE2B,MAAM,EAAE,UAAU;IAI/C;;;;;;OAMG;IACU,wBAAwB,CACnC,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,gBAAgB,EAC3B,OAAO,EAAE,YAAY,GACpB,OAAO,CAAC,mBAAmB,CAAC;IAyC/B;;;;;;OAMG;IACU,oBAAoB,CAC/B,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,gBAAgB,EAC3B,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,mBAAmB,CAAC;IA+C/B;;;;;;;OAOG;IACU,WAAW,CACtB,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,gBAAgB,EAC3B,OAAO,EAAE,OAAO,EAChB,aAAa,GACT,cAAc,GACd,aAAa,GACb,WAAW,GACX,UAAU,GACV,QAAQ,GACR,aAA0B,GAC7B,OAAO,CAAC,mBAAmB,CAAC;CAoChC"}
|
|
@@ -34,43 +34,14 @@ const common_1 = require("../types/common");
|
|
|
34
34
|
class GeneralMessageService {
|
|
35
35
|
constructor(client) {
|
|
36
36
|
this.client = client;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
async sendResponseTextMessage(accessToken, recipient, message) {
|
|
46
|
-
try {
|
|
47
|
-
if (!message.text || message.text.trim().length === 0) {
|
|
48
|
-
throw new common_1.ZaloSDKError("Nội dung tin nhắn không được để trống", -1);
|
|
49
|
-
}
|
|
50
|
-
if (message.text.length > 2000) {
|
|
51
|
-
throw new common_1.ZaloSDKError("Nội dung tin nhắn không được vượt quá 2000 ký tự", -1);
|
|
52
|
-
}
|
|
53
|
-
const endpoint = this.client.endpoints.message.send;
|
|
54
|
-
const request = {
|
|
55
|
-
recipient,
|
|
56
|
-
message,
|
|
57
|
-
messaging_type: "response",
|
|
58
|
-
};
|
|
59
|
-
const result = await this.client.apiPost(endpoint, accessToken, request);
|
|
60
|
-
if (result.error !== 0) {
|
|
61
|
-
throw new common_1.ZaloSDKError(result.message || "Failed to send response text message", result.error, result);
|
|
62
|
-
}
|
|
63
|
-
if (!result.data) {
|
|
64
|
-
throw new common_1.ZaloSDKError("No response data received", -1);
|
|
65
|
-
}
|
|
66
|
-
return result.data;
|
|
67
|
-
}
|
|
68
|
-
catch (error) {
|
|
69
|
-
if (error instanceof common_1.ZaloSDKError) {
|
|
70
|
-
throw error;
|
|
71
|
-
}
|
|
72
|
-
throw new common_1.ZaloSDKError(`Failed to send response text message: ${error.message}`, -1, error);
|
|
73
|
-
}
|
|
37
|
+
// Zalo API endpoints - organized by functionality
|
|
38
|
+
this.endpoints = {
|
|
39
|
+
// Message endpoints
|
|
40
|
+
message: {
|
|
41
|
+
send: "https://openapi.zalo.me/v3.0/oa/message/cs",
|
|
42
|
+
sendAnonymous: "https://openapi.zalo.me/v3.0/oa/message/anonymous",
|
|
43
|
+
},
|
|
44
|
+
};
|
|
74
45
|
}
|
|
75
46
|
/**
|
|
76
47
|
* Gửi tin nhắn phản hồi hình ảnh
|
|
@@ -84,7 +55,7 @@ class GeneralMessageService {
|
|
|
84
55
|
if (!message.attachment?.payload?.url) {
|
|
85
56
|
throw new common_1.ZaloSDKError("URL hình ảnh không được để trống", -1);
|
|
86
57
|
}
|
|
87
|
-
const endpoint = this.
|
|
58
|
+
const endpoint = this.endpoints.message.send;
|
|
88
59
|
const request = {
|
|
89
60
|
recipient,
|
|
90
61
|
message,
|
|
@@ -118,7 +89,7 @@ class GeneralMessageService {
|
|
|
118
89
|
if (!message.text || message.text.trim().length === 0) {
|
|
119
90
|
throw new common_1.ZaloSDKError("Nội dung tin nhắn ẩn danh không được để trống", -1);
|
|
120
91
|
}
|
|
121
|
-
const endpoint = this.
|
|
92
|
+
const endpoint = this.endpoints.message.sendAnonymous;
|
|
122
93
|
const request = {
|
|
123
94
|
recipient,
|
|
124
95
|
message,
|
|
@@ -139,78 +110,6 @@ class GeneralMessageService {
|
|
|
139
110
|
throw new common_1.ZaloSDKError(`Failed to send anonymous message: ${error.message}`, -1, error);
|
|
140
111
|
}
|
|
141
112
|
}
|
|
142
|
-
/**
|
|
143
|
-
* Upload file để sử dụng trong tin nhắn
|
|
144
|
-
* @param accessToken Access token của Official Account
|
|
145
|
-
* @param file File data (base64 hoặc buffer)
|
|
146
|
-
* @param fileName Tên file
|
|
147
|
-
* @returns Thông tin file đã upload
|
|
148
|
-
*/
|
|
149
|
-
async uploadFile(accessToken, file, fileName) {
|
|
150
|
-
try {
|
|
151
|
-
const endpoint = this.client.endpoints.upload.file;
|
|
152
|
-
const formData = new FormData();
|
|
153
|
-
if (typeof file === "string") {
|
|
154
|
-
// Base64 string
|
|
155
|
-
const buffer = Buffer.from(file, "base64");
|
|
156
|
-
formData.append("file", new Blob([new Uint8Array(buffer)]), fileName);
|
|
157
|
-
}
|
|
158
|
-
else {
|
|
159
|
-
// Buffer
|
|
160
|
-
formData.append("file", new Blob([new Uint8Array(file)]), fileName);
|
|
161
|
-
}
|
|
162
|
-
const result = await this.client.apiPost(endpoint, accessToken, formData);
|
|
163
|
-
if (result.error !== 0) {
|
|
164
|
-
throw new common_1.ZaloSDKError(result.message || "Failed to upload file", result.error, result);
|
|
165
|
-
}
|
|
166
|
-
if (!result.data) {
|
|
167
|
-
throw new common_1.ZaloSDKError("No response data received", -1);
|
|
168
|
-
}
|
|
169
|
-
return result.data;
|
|
170
|
-
}
|
|
171
|
-
catch (error) {
|
|
172
|
-
if (error instanceof common_1.ZaloSDKError) {
|
|
173
|
-
throw error;
|
|
174
|
-
}
|
|
175
|
-
throw new common_1.ZaloSDKError(`Failed to upload file: ${error.message}`, -1, error);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* Upload hình ảnh để sử dụng trong tin nhắn
|
|
180
|
-
* @param accessToken Access token của Official Account
|
|
181
|
-
* @param image Image data (base64 hoặc buffer)
|
|
182
|
-
* @param fileName Tên file hình ảnh
|
|
183
|
-
* @returns Thông tin hình ảnh đã upload
|
|
184
|
-
*/
|
|
185
|
-
async uploadImage(accessToken, image, fileName) {
|
|
186
|
-
try {
|
|
187
|
-
const endpoint = this.client.endpoints.upload.image;
|
|
188
|
-
const formData = new FormData();
|
|
189
|
-
if (typeof image === "string") {
|
|
190
|
-
// Base64 string
|
|
191
|
-
const buffer = Buffer.from(image, "base64");
|
|
192
|
-
formData.append("file", new Blob([new Uint8Array(buffer)]), fileName);
|
|
193
|
-
}
|
|
194
|
-
else {
|
|
195
|
-
// Buffer
|
|
196
|
-
formData.append("file", new Blob([new Uint8Array(image)]), fileName);
|
|
197
|
-
}
|
|
198
|
-
const result = await this.client.apiPost(endpoint, accessToken, formData);
|
|
199
|
-
if (result.error !== 0) {
|
|
200
|
-
throw new common_1.ZaloSDKError(result.message || "Failed to upload image", result.error, result);
|
|
201
|
-
}
|
|
202
|
-
if (!result.data) {
|
|
203
|
-
throw new common_1.ZaloSDKError("No response data received", -1);
|
|
204
|
-
}
|
|
205
|
-
return result.data;
|
|
206
|
-
}
|
|
207
|
-
catch (error) {
|
|
208
|
-
if (error instanceof common_1.ZaloSDKError) {
|
|
209
|
-
throw error;
|
|
210
|
-
}
|
|
211
|
-
throw new common_1.ZaloSDKError(`Failed to upload image: ${error.message}`, -1, error);
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
113
|
/**
|
|
215
114
|
* Gửi tin nhắn tổng quát
|
|
216
115
|
* @param accessToken Access token của Official Account
|
|
@@ -221,7 +120,7 @@ class GeneralMessageService {
|
|
|
221
120
|
*/
|
|
222
121
|
async sendMessage(accessToken, recipient, message, messagingType = "response") {
|
|
223
122
|
try {
|
|
224
|
-
const endpoint = this.
|
|
123
|
+
const endpoint = this.endpoints.message.send;
|
|
225
124
|
const request = {
|
|
226
125
|
recipient,
|
|
227
126
|
message,
|