@warriorteam/redai-zalo-sdk 1.17.5 → 1.19.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/CHANGELOG.md +161 -0
- package/dist/services/consultation.service.d.ts +167 -0
- package/dist/services/consultation.service.d.ts.map +1 -1
- package/dist/services/consultation.service.js +274 -0
- package/dist/services/consultation.service.js.map +1 -1
- package/dist/services/group-message.service.d.ts +200 -0
- package/dist/services/group-message.service.d.ts.map +1 -1
- package/dist/services/group-message.service.js +331 -0
- package/dist/services/group-message.service.js.map +1 -1
- package/docs/group-message-list-api.md +332 -0
- package/docs/message-sequence-api.md +464 -0
- package/examples/group-message-list.ts +288 -0
- package/examples/send-message-sequence.ts +200 -0
- package/package.json +16 -3
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import {
|
|
2
|
+
GroupMessageService,
|
|
3
|
+
GroupMessageItem,
|
|
4
|
+
SendMessageListToGroupRequest,
|
|
5
|
+
SendMessageListToMultipleGroupsRequest,
|
|
6
|
+
GroupMessageProgressInfo,
|
|
7
|
+
MultipleGroupsProgressInfo
|
|
8
|
+
} from "../src/services/group-message.service";
|
|
9
|
+
import { ZaloClient } from "../src/clients/zalo-client";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Ví dụ sử dụng API gửi danh sách tin nhắn tới 1 group với callback tracking
|
|
13
|
+
*/
|
|
14
|
+
async function sendMessageListToGroupExample() {
|
|
15
|
+
// Khởi tạo Zalo client và group message service
|
|
16
|
+
const zaloClient = new ZaloClient();
|
|
17
|
+
const groupMessageService = new GroupMessageService(zaloClient);
|
|
18
|
+
|
|
19
|
+
// Thông tin cấu hình
|
|
20
|
+
const accessToken = "YOUR_ACCESS_TOKEN";
|
|
21
|
+
const groupId = "GROUP_ID_TO_SEND_TO";
|
|
22
|
+
|
|
23
|
+
// Định nghĩa danh sách tin nhắn thông báo
|
|
24
|
+
const messages: GroupMessageItem[] = [
|
|
25
|
+
{
|
|
26
|
+
type: "text",
|
|
27
|
+
text: "📢 THÔNG BÁO QUAN TRỌNG",
|
|
28
|
+
delay: 2000,
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
type: "text",
|
|
32
|
+
text: "🔧 Hệ thống sẽ bảo trì từ 2:00 - 4:00 sáng ngày mai (15/09/2024)",
|
|
33
|
+
delay: 1500,
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
type: "image",
|
|
37
|
+
imageUrl: "https://example.com/maintenance-schedule.jpg",
|
|
38
|
+
caption: "Lịch trình bảo trì chi tiết",
|
|
39
|
+
delay: 2000,
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
type: "text",
|
|
43
|
+
text: "⚠️ Trong thời gian bảo trì, các dịch vụ sau sẽ tạm ngưng:\n• Website chính\n• Mobile App\n• API Services",
|
|
44
|
+
delay: 1500,
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
type: "sticker",
|
|
48
|
+
stickerId: "MAINTENANCE_STICKER_ID",
|
|
49
|
+
delay: 1000,
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
type: "text",
|
|
53
|
+
text: "📞 Hotline hỗ trợ khẩn cấp: 1900-xxxx\n📧 Email: support@company.com",
|
|
54
|
+
},
|
|
55
|
+
];
|
|
56
|
+
|
|
57
|
+
// Callback function để tracking tiến trình
|
|
58
|
+
const onProgress = (progress: GroupMessageProgressInfo) => {
|
|
59
|
+
const percentage = Math.round(((progress.messageIndex + 1) / progress.totalMessages) * 100);
|
|
60
|
+
|
|
61
|
+
switch (progress.status) {
|
|
62
|
+
case 'started':
|
|
63
|
+
console.log(`🚀 [${percentage}%] Bắt đầu gửi tin nhắn ${progress.messageIndex + 1}/${progress.totalMessages} (${progress.messageType})`);
|
|
64
|
+
break;
|
|
65
|
+
|
|
66
|
+
case 'completed':
|
|
67
|
+
const duration = progress.endTime ? progress.endTime - progress.startTime : 0;
|
|
68
|
+
console.log(`✅ [${percentage}%] Hoàn thành tin nhắn ${progress.messageIndex + 1}/${progress.totalMessages} - ${duration}ms`);
|
|
69
|
+
break;
|
|
70
|
+
|
|
71
|
+
case 'failed':
|
|
72
|
+
const failDuration = progress.endTime ? progress.endTime - progress.startTime : 0;
|
|
73
|
+
console.log(`❌ [${percentage}%] Thất bại tin nhắn ${progress.messageIndex + 1}/${progress.totalMessages} - ${failDuration}ms - Lỗi: ${progress.error}`);
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
// Tạo request
|
|
79
|
+
const request: SendMessageListToGroupRequest = {
|
|
80
|
+
accessToken,
|
|
81
|
+
groupId,
|
|
82
|
+
messages,
|
|
83
|
+
defaultDelay: 1000, // Delay mặc định 1 giây giữa các tin nhắn
|
|
84
|
+
onProgress, // Callback tracking
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
try {
|
|
88
|
+
console.log("📢 Bắt đầu gửi danh sách tin nhắn thông báo tới group...");
|
|
89
|
+
console.log(`👥 Group ID: ${groupId}`);
|
|
90
|
+
console.log(`📝 Tổng số tin nhắn: ${messages.length}`);
|
|
91
|
+
console.log("─".repeat(60));
|
|
92
|
+
|
|
93
|
+
// Gửi danh sách tin nhắn tới group
|
|
94
|
+
const result = await groupMessageService.sendMessageListToGroup(request);
|
|
95
|
+
|
|
96
|
+
console.log("─".repeat(60));
|
|
97
|
+
console.log("🎊 KẾT QUẢ:");
|
|
98
|
+
console.log(`📝 Tổng tin nhắn: ${result.totalMessages}`);
|
|
99
|
+
console.log(`✅ Thành công: ${result.successfulMessages} (${Math.round((result.successfulMessages / result.totalMessages) * 100)}%)`);
|
|
100
|
+
console.log(`❌ Thất bại: ${result.failedMessages} (${Math.round((result.failedMessages / result.totalMessages) * 100)}%)`);
|
|
101
|
+
console.log(`⏱️ Tổng thời gian: ${result.totalDuration}ms (${Math.round(result.totalDuration / 1000)}s)`);
|
|
102
|
+
|
|
103
|
+
// In chi tiết từng tin nhắn
|
|
104
|
+
console.log("\n📋 CHI TIẾT TỪNG TIN NHẮN:");
|
|
105
|
+
result.messageResults.forEach((messageResult, index) => {
|
|
106
|
+
const status = messageResult.success ? "✅" : "❌";
|
|
107
|
+
console.log(`${status} [${index + 1}] ${messageResult.messageType} - ${messageResult.duration}ms`);
|
|
108
|
+
|
|
109
|
+
if (!messageResult.success && messageResult.error) {
|
|
110
|
+
console.log(` ❌ Lỗi: ${messageResult.error}`);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
} catch (error) {
|
|
115
|
+
console.error("❌ Lỗi khi gửi danh sách tin nhắn tới group:", error);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Ví dụ gửi danh sách tin nhắn tới nhiều groups
|
|
121
|
+
*/
|
|
122
|
+
async function sendMessageListToMultipleGroupsExample() {
|
|
123
|
+
const zaloClient = new ZaloClient();
|
|
124
|
+
const groupMessageService = new GroupMessageService(zaloClient);
|
|
125
|
+
|
|
126
|
+
const accessToken = "YOUR_ACCESS_TOKEN";
|
|
127
|
+
const groupIds = [
|
|
128
|
+
"GROUP_ID_1",
|
|
129
|
+
"GROUP_ID_2",
|
|
130
|
+
"GROUP_ID_3",
|
|
131
|
+
"GROUP_ID_4"
|
|
132
|
+
];
|
|
133
|
+
|
|
134
|
+
// Danh sách tin nhắn marketing
|
|
135
|
+
const messages: GroupMessageItem[] = [
|
|
136
|
+
{
|
|
137
|
+
type: "text",
|
|
138
|
+
text: "🎉 FLASH SALE 24H - GIẢM GIÁ SỐC!",
|
|
139
|
+
delay: 2000,
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
type: "image",
|
|
143
|
+
imageUrl: "https://example.com/flash-sale-banner.jpg",
|
|
144
|
+
caption: "🔥 Giảm tới 70% + Freeship toàn quốc",
|
|
145
|
+
delay: 3000,
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
type: "text",
|
|
149
|
+
text: "⏰ Chỉ còn 12 giờ! Số lượng có hạn!\n🛒 Mua ngay: https://shop.example.com/flash-sale",
|
|
150
|
+
delay: 1500,
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
type: "sticker",
|
|
154
|
+
stickerId: "SALE_STICKER_ID",
|
|
155
|
+
},
|
|
156
|
+
];
|
|
157
|
+
|
|
158
|
+
// Callback tracking cho multiple groups
|
|
159
|
+
let completedGroups = 0;
|
|
160
|
+
const onProgress = (progress: MultipleGroupsProgressInfo) => {
|
|
161
|
+
switch (progress.status) {
|
|
162
|
+
case 'started':
|
|
163
|
+
console.log(`🎯 Bắt đầu gửi tới Group ${progress.groupIndex + 1}/${progress.totalGroups} (${progress.groupId})`);
|
|
164
|
+
break;
|
|
165
|
+
|
|
166
|
+
case 'completed':
|
|
167
|
+
completedGroups++;
|
|
168
|
+
const successRate = progress.result ?
|
|
169
|
+
Math.round((progress.result.successfulMessages / progress.result.totalMessages) * 100) : 0;
|
|
170
|
+
console.log(`✅ Hoàn thành Group ${completedGroups}/${progress.totalGroups} - Thành công: ${successRate}%`);
|
|
171
|
+
break;
|
|
172
|
+
|
|
173
|
+
case 'failed':
|
|
174
|
+
console.log(`❌ Thất bại Group ${progress.groupIndex + 1}/${progress.totalGroups} - Lỗi: ${progress.error}`);
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
const request: SendMessageListToMultipleGroupsRequest = {
|
|
180
|
+
accessToken,
|
|
181
|
+
groupIds,
|
|
182
|
+
messages,
|
|
183
|
+
defaultDelay: 1000, // Delay giữa tin nhắn
|
|
184
|
+
delayBetweenGroups: 3000, // Delay 3 giây giữa các groups
|
|
185
|
+
onProgress,
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
try {
|
|
189
|
+
console.log("🎯 Bắt đầu chiến dịch marketing tới nhiều groups...");
|
|
190
|
+
console.log(`👥 Tổng số groups: ${groupIds.length}`);
|
|
191
|
+
console.log(`📝 Tổng số tin nhắn mỗi group: ${messages.length}`);
|
|
192
|
+
console.log(`📊 Tổng số tin nhắn sẽ gửi: ${groupIds.length * messages.length}`);
|
|
193
|
+
console.log("─".repeat(60));
|
|
194
|
+
|
|
195
|
+
const result = await groupMessageService.sendMessageListToMultipleGroups(request);
|
|
196
|
+
|
|
197
|
+
console.log("─".repeat(60));
|
|
198
|
+
console.log("🎊 KẾT QUẢ TỔNG QUAN:");
|
|
199
|
+
console.log(`👥 Tổng groups: ${result.totalGroups}`);
|
|
200
|
+
console.log(`✅ Groups thành công: ${result.successfulGroups} (${Math.round((result.successfulGroups / result.totalGroups) * 100)}%)`);
|
|
201
|
+
console.log(`❌ Groups thất bại: ${result.failedGroups} (${Math.round((result.failedGroups / result.totalGroups) * 100)}%)`);
|
|
202
|
+
console.log(`⏱️ Tổng thời gian: ${result.totalDuration}ms (${Math.round(result.totalDuration / 1000)}s)`);
|
|
203
|
+
|
|
204
|
+
console.log("\n📊 THỐNG KÊ TIN NHẮN:");
|
|
205
|
+
console.log(`✅ Tin nhắn thành công: ${result.messageStats.totalSuccessfulMessages}`);
|
|
206
|
+
console.log(`❌ Tin nhắn thất bại: ${result.messageStats.totalFailedMessages}`);
|
|
207
|
+
console.log(`📝 Tổng tin nhắn: ${result.messageStats.totalMessages}`);
|
|
208
|
+
console.log(`📈 Tỷ lệ thành công: ${Math.round((result.messageStats.totalSuccessfulMessages / result.messageStats.totalMessages) * 100)}%`);
|
|
209
|
+
|
|
210
|
+
// In chi tiết từng group
|
|
211
|
+
console.log("\n📋 CHI TIẾT TỪNG GROUP:");
|
|
212
|
+
result.groupResults.forEach((groupResult, index) => {
|
|
213
|
+
const status = groupResult.success ? "✅" : "❌";
|
|
214
|
+
const successRate = groupResult.messageListResult ?
|
|
215
|
+
Math.round((groupResult.messageListResult.successfulMessages / groupResult.messageListResult.totalMessages) * 100) : 0;
|
|
216
|
+
|
|
217
|
+
console.log(`${status} Group ${index + 1}: ${groupResult.groupId} - ${groupResult.duration}ms - Thành công: ${successRate}%`);
|
|
218
|
+
|
|
219
|
+
if (!groupResult.success && groupResult.error) {
|
|
220
|
+
console.log(` ❌ Lỗi: ${groupResult.error}`);
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
} catch (error) {
|
|
225
|
+
console.error("❌ Lỗi khi gửi danh sách tin nhắn tới nhiều groups:", error);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Ví dụ gửi tin nhắn mention tới group
|
|
231
|
+
*/
|
|
232
|
+
async function sendMentionMessageListExample() {
|
|
233
|
+
const zaloClient = new ZaloClient();
|
|
234
|
+
const groupMessageService = new GroupMessageService(zaloClient);
|
|
235
|
+
|
|
236
|
+
const accessToken = "YOUR_ACCESS_TOKEN";
|
|
237
|
+
const groupId = "GROUP_ID";
|
|
238
|
+
|
|
239
|
+
const messages: GroupMessageItem[] = [
|
|
240
|
+
{
|
|
241
|
+
type: "text",
|
|
242
|
+
text: "🎯 Cuộc họp quan trọng sắp diễn ra!",
|
|
243
|
+
delay: 1000,
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
type: "mention",
|
|
247
|
+
text: "@Admin @Manager Vui lòng chuẩn bị tài liệu cho cuộc họp lúc 14:00",
|
|
248
|
+
mentions: [
|
|
249
|
+
{ user_id: "ADMIN_USER_ID", offset: 0, length: 6 },
|
|
250
|
+
{ user_id: "MANAGER_USER_ID", offset: 7, length: 8 }
|
|
251
|
+
],
|
|
252
|
+
delay: 2000,
|
|
253
|
+
},
|
|
254
|
+
{
|
|
255
|
+
type: "text",
|
|
256
|
+
text: "📋 Agenda:\n1. Báo cáo tháng\n2. Kế hoạch quý mới\n3. Q&A",
|
|
257
|
+
},
|
|
258
|
+
];
|
|
259
|
+
|
|
260
|
+
const onProgress = (progress: GroupMessageProgressInfo) => {
|
|
261
|
+
if (progress.status === 'completed') {
|
|
262
|
+
console.log(`✅ Đã gửi tin nhắn ${progress.messageIndex + 1}: ${progress.messageType}`);
|
|
263
|
+
} else if (progress.status === 'failed') {
|
|
264
|
+
console.log(`❌ Gửi thất bại tin nhắn ${progress.messageIndex + 1}: ${progress.error}`);
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
try {
|
|
269
|
+
const result = await groupMessageService.sendMessageListToGroup({
|
|
270
|
+
accessToken,
|
|
271
|
+
groupId,
|
|
272
|
+
messages,
|
|
273
|
+
defaultDelay: 1500,
|
|
274
|
+
onProgress,
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
console.log(`\n📢 Đã gửi thông báo cuộc họp: ${result.successfulMessages}/${result.totalMessages} tin nhắn thành công`);
|
|
278
|
+
} catch (error) {
|
|
279
|
+
console.error("❌ Lỗi gửi thông báo cuộc họp:", error);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// Export các function để sử dụng
|
|
284
|
+
export {
|
|
285
|
+
sendMessageListToGroupExample,
|
|
286
|
+
sendMessageListToMultipleGroupsExample,
|
|
287
|
+
sendMentionMessageListExample,
|
|
288
|
+
};
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { ConsultationService, MessageItem, SendMessageSequenceRequest } from "../src/services/consultation.service";
|
|
2
|
+
import { ZaloClient } from "../src/clients/zalo-client";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Ví dụ sử dụng API gửi chuỗi tin nhắn tư vấn
|
|
6
|
+
*/
|
|
7
|
+
async function sendMessageSequenceExample() {
|
|
8
|
+
// Khởi tạo Zalo client và consultation service
|
|
9
|
+
const zaloClient = new ZaloClient();
|
|
10
|
+
const consultationService = new ConsultationService(zaloClient);
|
|
11
|
+
|
|
12
|
+
// Thông tin cấu hình
|
|
13
|
+
const accessToken = "YOUR_ACCESS_TOKEN";
|
|
14
|
+
const userId = "USER_ID_TO_SEND_TO";
|
|
15
|
+
|
|
16
|
+
// Định nghĩa chuỗi tin nhắn
|
|
17
|
+
const messages: MessageItem[] = [
|
|
18
|
+
// 1. Tin nhắn chào hỏi
|
|
19
|
+
{
|
|
20
|
+
type: "text",
|
|
21
|
+
text: "Xin chào! Cảm ơn bạn đã liên hệ với chúng tôi 👋",
|
|
22
|
+
delay: 2000, // Delay 2 giây sau tin nhắn này
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
// 2. Gửi sticker
|
|
26
|
+
{
|
|
27
|
+
type: "sticker",
|
|
28
|
+
stickerAttachmentId: "STICKER_ID",
|
|
29
|
+
delay: 1500, // Delay 1.5 giây
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
// 3. Tin nhắn giới thiệu dịch vụ
|
|
33
|
+
{
|
|
34
|
+
type: "text",
|
|
35
|
+
text: "Chúng tôi cung cấp các dịch vụ tư vấn chuyên nghiệp. Dưới đây là một số thông tin chi tiết:",
|
|
36
|
+
delay: 3000, // Delay 3 giây
|
|
37
|
+
},
|
|
38
|
+
|
|
39
|
+
// 4. Gửi hình ảnh minh họa
|
|
40
|
+
{
|
|
41
|
+
type: "image",
|
|
42
|
+
imageUrl: "https://example.com/service-image.jpg",
|
|
43
|
+
text: "Dịch vụ tư vấn của chúng tôi",
|
|
44
|
+
delay: 2000,
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
// 5. Gửi file tài liệu
|
|
48
|
+
{
|
|
49
|
+
type: "file",
|
|
50
|
+
fileToken: "FILE_TOKEN_FROM_UPLOAD_API",
|
|
51
|
+
delay: 1000,
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
// 6. Gửi GIF
|
|
55
|
+
{
|
|
56
|
+
type: "gif",
|
|
57
|
+
gifUrl: "https://example.com/animation.gif",
|
|
58
|
+
width: 300,
|
|
59
|
+
height: 200,
|
|
60
|
+
text: "Quy trình làm việc của chúng tôi",
|
|
61
|
+
delay: 2500,
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
// 7. Yêu cầu thông tin người dùng
|
|
65
|
+
{
|
|
66
|
+
type: "request_user_info",
|
|
67
|
+
title: "Đăng ký tư vấn miễn phí",
|
|
68
|
+
subtitle: "Vui lòng cung cấp thông tin để chúng tôi hỗ trợ bạn tốt nhất",
|
|
69
|
+
imageUrl: "https://example.com/consultation-form.jpg",
|
|
70
|
+
delay: 1000,
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
// 8. Tin nhắn kết thúc (không có delay vì là tin cuối)
|
|
74
|
+
{
|
|
75
|
+
type: "text",
|
|
76
|
+
text: "Cảm ơn bạn! Chúng tôi sẽ liên hệ lại trong thời gian sớm nhất. 🙏",
|
|
77
|
+
},
|
|
78
|
+
];
|
|
79
|
+
|
|
80
|
+
// Tạo request
|
|
81
|
+
const request: SendMessageSequenceRequest = {
|
|
82
|
+
accessToken,
|
|
83
|
+
userId,
|
|
84
|
+
messages,
|
|
85
|
+
defaultDelay: 1000, // Delay mặc định 1 giây nếu tin nhắn không có delay riêng
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
try {
|
|
89
|
+
console.log("🚀 Bắt đầu gửi chuỗi tin nhắn...");
|
|
90
|
+
console.log(`📝 Tổng số tin nhắn: ${messages.length}`);
|
|
91
|
+
|
|
92
|
+
// Gửi chuỗi tin nhắn
|
|
93
|
+
const result = await consultationService.sendMessageSequence(request);
|
|
94
|
+
|
|
95
|
+
console.log("\n✅ Kết quả gửi tin nhắn:");
|
|
96
|
+
console.log(`✅ Thành công: ${result.successCount}/${messages.length}`);
|
|
97
|
+
console.log(`❌ Thất bại: ${result.failureCount}/${messages.length}`);
|
|
98
|
+
console.log(`⏱️ Tổng thời gian: ${result.totalDuration}ms`);
|
|
99
|
+
|
|
100
|
+
// In chi tiết kết quả từng tin nhắn
|
|
101
|
+
console.log("\n📊 Chi tiết từng tin nhắn:");
|
|
102
|
+
result.results.forEach((messageResult, index) => {
|
|
103
|
+
const status = messageResult.success ? "✅" : "❌";
|
|
104
|
+
const time = new Date(messageResult.timestamp).toLocaleTimeString();
|
|
105
|
+
|
|
106
|
+
console.log(`${status} [${index + 1}] ${messageResult.type} - ${time}`);
|
|
107
|
+
|
|
108
|
+
if (messageResult.success && messageResult.response) {
|
|
109
|
+
console.log(` 📧 Message ID: ${messageResult.response.message_id}`);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (!messageResult.success && messageResult.error) {
|
|
113
|
+
console.log(` ❌ Lỗi: ${messageResult.error}`);
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
} catch (error) {
|
|
118
|
+
console.error("❌ Lỗi khi gửi chuỗi tin nhắn:", error);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Ví dụ gửi chuỗi tin nhắn đơn giản chỉ có text
|
|
124
|
+
*/
|
|
125
|
+
async function sendSimpleTextSequence() {
|
|
126
|
+
const zaloClient = new ZaloClient();
|
|
127
|
+
const consultationService = new ConsultationService(zaloClient);
|
|
128
|
+
|
|
129
|
+
const accessToken = "YOUR_ACCESS_TOKEN";
|
|
130
|
+
const userId = "USER_ID_TO_SEND_TO";
|
|
131
|
+
|
|
132
|
+
const messages: MessageItem[] = [
|
|
133
|
+
{
|
|
134
|
+
type: "text",
|
|
135
|
+
text: "Tin nhắn đầu tiên",
|
|
136
|
+
delay: 1000,
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
type: "text",
|
|
140
|
+
text: "Tin nhắn thứ hai",
|
|
141
|
+
delay: 1500,
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
type: "text",
|
|
145
|
+
text: "Tin nhắn cuối cùng",
|
|
146
|
+
},
|
|
147
|
+
];
|
|
148
|
+
|
|
149
|
+
const request: SendMessageSequenceRequest = {
|
|
150
|
+
accessToken,
|
|
151
|
+
userId,
|
|
152
|
+
messages,
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
try {
|
|
156
|
+
const result = await consultationService.sendMessageSequence(request);
|
|
157
|
+
console.log("Kết quả:", result);
|
|
158
|
+
} catch (error) {
|
|
159
|
+
console.error("Lỗi:", error);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Ví dụ gửi chuỗi tin nhắn với delay mặc định
|
|
165
|
+
*/
|
|
166
|
+
async function sendSequenceWithDefaultDelay() {
|
|
167
|
+
const zaloClient = new ZaloClient();
|
|
168
|
+
const consultationService = new ConsultationService(zaloClient);
|
|
169
|
+
|
|
170
|
+
const accessToken = "YOUR_ACCESS_TOKEN";
|
|
171
|
+
const userId = "USER_ID_TO_SEND_TO";
|
|
172
|
+
|
|
173
|
+
// Các tin nhắn không có delay riêng sẽ sử dụng defaultDelay
|
|
174
|
+
const messages: MessageItem[] = [
|
|
175
|
+
{ type: "text", text: "Tin nhắn 1" },
|
|
176
|
+
{ type: "text", text: "Tin nhắn 2" },
|
|
177
|
+
{ type: "text", text: "Tin nhắn 3" },
|
|
178
|
+
];
|
|
179
|
+
|
|
180
|
+
const request: SendMessageSequenceRequest = {
|
|
181
|
+
accessToken,
|
|
182
|
+
userId,
|
|
183
|
+
messages,
|
|
184
|
+
defaultDelay: 2000, // Delay 2 giây giữa các tin nhắn
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
try {
|
|
188
|
+
const result = await consultationService.sendMessageSequence(request);
|
|
189
|
+
console.log("Kết quả:", result);
|
|
190
|
+
} catch (error) {
|
|
191
|
+
console.error("Lỗi:", error);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// Export các function để sử dụng
|
|
196
|
+
export {
|
|
197
|
+
sendMessageSequenceExample,
|
|
198
|
+
sendSimpleTextSequence,
|
|
199
|
+
sendSequenceWithDefaultDelay,
|
|
200
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@warriorteam/redai-zalo-sdk",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "Comprehensive TypeScript/JavaScript SDK for Zalo APIs - Official Account, ZNS, Consultation Service, Group Messaging, Social APIs,
|
|
3
|
+
"version": "1.19.0",
|
|
4
|
+
"description": "Comprehensive TypeScript/JavaScript SDK for Zalo APIs - Official Account, ZNS, Consultation Service, Group Messaging with List APIs, Social APIs, Enhanced Article Management, and Message Sequence APIs with Real-time Tracking",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
@@ -33,7 +33,20 @@
|
|
|
33
33
|
"article-management",
|
|
34
34
|
"auto-pagination",
|
|
35
35
|
"bulk-fetch",
|
|
36
|
-
"progress-tracking"
|
|
36
|
+
"progress-tracking",
|
|
37
|
+
"message-sequence",
|
|
38
|
+
"bulk-messaging",
|
|
39
|
+
"marketing-automation",
|
|
40
|
+
"real-time-tracking",
|
|
41
|
+
"callback-tracking",
|
|
42
|
+
"multiple-users",
|
|
43
|
+
"campaign-management",
|
|
44
|
+
"group-messaging",
|
|
45
|
+
"group-message-list",
|
|
46
|
+
"bulk-group-messaging",
|
|
47
|
+
"group-notifications",
|
|
48
|
+
"team-communication",
|
|
49
|
+
"group-automation"
|
|
37
50
|
],
|
|
38
51
|
"author": "RedAI Team",
|
|
39
52
|
"license": "MIT",
|