@warriorteam/redai-zalo-sdk 1.18.0 → 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 +83 -0
- 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/examples/group-message-list.ts +288 -0
- package/package.json +9 -3
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,89 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [1.19.0] - 2025-08-29
|
|
9
|
+
|
|
10
|
+
### 🚀 NEW FEATURES
|
|
11
|
+
|
|
12
|
+
#### Group Message List APIs - Gửi Danh Sách Tin Nhắn Group
|
|
13
|
+
- **ADDED**: `sendMessageListToGroup()` - Gửi danh sách tin nhắn tới 1 group với delay tùy chỉnh
|
|
14
|
+
- **ADDED**: `sendMessageListToMultipleGroups()` - Gửi danh sách tin nhắn tới nhiều groups cùng lúc
|
|
15
|
+
- **SUPPORT**: Hỗ trợ đầy đủ 5 loại tin nhắn group: text, image, file, sticker, mention
|
|
16
|
+
- **FLEXIBLE**: Delay riêng cho từng tin nhắn + delay giữa groups để tránh rate limit
|
|
17
|
+
- **SMART**: Tự động loại bỏ group IDs trùng lặp và validation đầy đủ
|
|
18
|
+
|
|
19
|
+
#### Real-time Progress Tracking cho Groups
|
|
20
|
+
- **CALLBACK**: `onProgress` callback để tracking real-time từng tin nhắn và group
|
|
21
|
+
- **DETAILED**: Thống kê chi tiết thành công/thất bại cho từng tin nhắn và group
|
|
22
|
+
- **ISOLATION**: Error của 1 tin nhắn/group không ảnh hưởng phần còn lại
|
|
23
|
+
- **METRICS**: Tracking thời gian thực hiện, success rate, và message statistics
|
|
24
|
+
|
|
25
|
+
#### Advanced Group Messaging Features
|
|
26
|
+
- **MENTION**: Hỗ trợ mention members với offset và length chính xác
|
|
27
|
+
- **CAPTION**: Image messages với caption tối đa 2000 ký tự
|
|
28
|
+
- **FILE**: File attachments với token từ upload API
|
|
29
|
+
- **SEQUENTIAL**: Gửi tuần tự để đảm bảo thứ tự và tránh rate limit
|
|
30
|
+
|
|
31
|
+
### 📊 NEW INTERFACES
|
|
32
|
+
|
|
33
|
+
#### Group Message List Types
|
|
34
|
+
- **ADDED**: `GroupMessageItem` - Interface cho từng tin nhắn trong danh sách
|
|
35
|
+
- **ADDED**: `SendMessageListToGroupRequest` - Request cho single group
|
|
36
|
+
- **ADDED**: `SendMessageListToGroupResponse` - Response với detailed results
|
|
37
|
+
- **ADDED**: `SendMessageListToMultipleGroupsRequest` - Request cho multiple groups
|
|
38
|
+
- **ADDED**: `SendMessageListToMultipleGroupsResponse` - Response với group statistics
|
|
39
|
+
- **ADDED**: `GroupMessageProgressInfo` - Interface cho message progress tracking
|
|
40
|
+
- **ADDED**: `MultipleGroupsProgressInfo` - Interface cho multiple groups progress tracking
|
|
41
|
+
|
|
42
|
+
### 📚 DOCUMENTATION & EXAMPLES
|
|
43
|
+
|
|
44
|
+
#### New Documentation
|
|
45
|
+
- **ADDED**: `docs/group-message-list-api.md` - Comprehensive guide cho Group Message List APIs
|
|
46
|
+
- **UPDATED**: Hướng dẫn chi tiết từng loại tin nhắn group và use cases
|
|
47
|
+
- **ADDED**: So sánh API cũ vs mới với feature comparison table
|
|
48
|
+
|
|
49
|
+
#### New Examples
|
|
50
|
+
- **ADDED**: `examples/group-message-list.ts` - Ví dụ gửi danh sách tin nhắn group
|
|
51
|
+
- **INCLUDED**: System notifications, marketing campaigns, meeting notifications examples
|
|
52
|
+
- **DEMO**: Mention messages, image captions, file attachments usage
|
|
53
|
+
|
|
54
|
+
### 🎯 USE CASES
|
|
55
|
+
|
|
56
|
+
#### System Administration
|
|
57
|
+
- **MAINTENANCE**: Thông báo bảo trì hệ thống tới tất cả groups
|
|
58
|
+
- **ALERTS**: Emergency alerts với hình ảnh và file đính kèm
|
|
59
|
+
- **UPDATES**: System updates với mention admins
|
|
60
|
+
|
|
61
|
+
#### Marketing & Business
|
|
62
|
+
- **CAMPAIGNS**: Flash sales, khuyến mãi tới customer groups
|
|
63
|
+
- **PROMOTIONS**: Product launches với hình ảnh và stickers
|
|
64
|
+
- **ANNOUNCEMENTS**: Company announcements với professional formatting
|
|
65
|
+
|
|
66
|
+
#### Team Communication
|
|
67
|
+
- **MEETINGS**: Meeting notifications với mention participants
|
|
68
|
+
- **PROJECTS**: Project updates tới multiple team groups
|
|
69
|
+
- **REPORTS**: Regular reports với file attachments
|
|
70
|
+
|
|
71
|
+
### 🔧 TECHNICAL IMPROVEMENTS
|
|
72
|
+
|
|
73
|
+
#### Enhanced Error Handling
|
|
74
|
+
- **ROBUST**: Comprehensive error handling cho từng tin nhắn và group
|
|
75
|
+
- **CONTINUE**: Tiếp tục gửi khi gặp lỗi thay vì dừng toàn bộ process
|
|
76
|
+
- **DETAILED**: Error messages chi tiết với context information
|
|
77
|
+
- **ISOLATION**: Error isolation giữa tin nhắn và giữa groups
|
|
78
|
+
|
|
79
|
+
#### Performance Optimizations
|
|
80
|
+
- **SEQUENTIAL**: Sequential processing để tránh overwhelming Zalo servers
|
|
81
|
+
- **MEMORY**: Optimized memory usage cho large group lists
|
|
82
|
+
- **RATE-LIMIT**: Built-in rate limiting protection với configurable delays
|
|
83
|
+
- **TIMEOUT**: Proper timeout handling và cleanup
|
|
84
|
+
|
|
85
|
+
#### Type Safety & Validation
|
|
86
|
+
- **TYPESCRIPT**: Full TypeScript support với strict typing
|
|
87
|
+
- **VALIDATION**: Runtime validation cho tất cả input parameters
|
|
88
|
+
- **INTELLISENSE**: Complete IDE support với detailed JSDoc comments
|
|
89
|
+
- **CONSTRAINTS**: Proper validation cho message constraints (text length, etc.)
|
|
90
|
+
|
|
8
91
|
## [1.18.0] - 2025-08-29
|
|
9
92
|
|
|
10
93
|
### 🚀 NEW FEATURES
|
|
@@ -1,5 +1,185 @@
|
|
|
1
1
|
import { ZaloClient } from "../clients/zalo-client";
|
|
2
2
|
import { GroupTextMessage, GroupImageMessage, GroupFileMessage, GroupStickerMessage, GroupMentionMessage, GroupMessageResult, GroupInfo, GroupMember } from "../types/group";
|
|
3
|
+
/**
|
|
4
|
+
* Interface cho từng tin nhắn trong danh sách tin nhắn group
|
|
5
|
+
*/
|
|
6
|
+
export interface GroupMessageItem {
|
|
7
|
+
/** Loại tin nhắn */
|
|
8
|
+
type: "text" | "image" | "file" | "sticker" | "mention";
|
|
9
|
+
/** Nội dung tin nhắn (cho text/mention message) */
|
|
10
|
+
text?: string;
|
|
11
|
+
/** URL hình ảnh (cho image message) */
|
|
12
|
+
imageUrl?: string;
|
|
13
|
+
/** Attachment ID (cho image message) */
|
|
14
|
+
attachmentId?: string;
|
|
15
|
+
/** Caption cho hình ảnh (tối đa 2000 ký tự) */
|
|
16
|
+
caption?: string;
|
|
17
|
+
/** Token file (cho file message) */
|
|
18
|
+
fileToken?: string;
|
|
19
|
+
/** Tên file (cho file message) */
|
|
20
|
+
fileName?: string;
|
|
21
|
+
/** Sticker ID (cho sticker message) */
|
|
22
|
+
stickerId?: string;
|
|
23
|
+
/** Danh sách mentions (cho mention message) */
|
|
24
|
+
mentions?: Array<{
|
|
25
|
+
user_id: string;
|
|
26
|
+
offset: number;
|
|
27
|
+
length: number;
|
|
28
|
+
}>;
|
|
29
|
+
/** Delay sau khi gửi tin nhắn này (milliseconds) */
|
|
30
|
+
delay?: number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Interface cho request gửi danh sách tin nhắn tới 1 group
|
|
34
|
+
*/
|
|
35
|
+
export interface SendMessageListToGroupRequest {
|
|
36
|
+
/** Access token của Official Account */
|
|
37
|
+
accessToken: string;
|
|
38
|
+
/** Group ID */
|
|
39
|
+
groupId: string;
|
|
40
|
+
/** Danh sách tin nhắn */
|
|
41
|
+
messages: GroupMessageItem[];
|
|
42
|
+
/** Delay mặc định giữa các tin nhắn (milliseconds) */
|
|
43
|
+
defaultDelay?: number;
|
|
44
|
+
/** Callback function để tracking tiến trình */
|
|
45
|
+
onProgress?: (progress: GroupMessageProgressInfo) => void;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Interface cho thông tin tiến trình từng tin nhắn
|
|
49
|
+
*/
|
|
50
|
+
export interface GroupMessageProgressInfo {
|
|
51
|
+
/** Group ID */
|
|
52
|
+
groupId: string;
|
|
53
|
+
/** Index của tin nhắn trong danh sách (bắt đầu từ 0) */
|
|
54
|
+
messageIndex: number;
|
|
55
|
+
/** Tổng số tin nhắn */
|
|
56
|
+
totalMessages: number;
|
|
57
|
+
/** Loại tin nhắn */
|
|
58
|
+
messageType: string;
|
|
59
|
+
/** Trạng thái: 'started' | 'completed' | 'failed' */
|
|
60
|
+
status: 'started' | 'completed' | 'failed';
|
|
61
|
+
/** Kết quả gửi tin nhắn (nếu đã hoàn thành) */
|
|
62
|
+
result?: GroupMessageResult;
|
|
63
|
+
/** Thông tin lỗi (nếu thất bại) */
|
|
64
|
+
error?: string;
|
|
65
|
+
/** Thời gian bắt đầu */
|
|
66
|
+
startTime: number;
|
|
67
|
+
/** Thời gian kết thúc (nếu đã hoàn thành) */
|
|
68
|
+
endTime?: number;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Interface cho response gửi danh sách tin nhắn tới 1 group
|
|
72
|
+
*/
|
|
73
|
+
export interface SendMessageListToGroupResponse {
|
|
74
|
+
/** Group ID */
|
|
75
|
+
groupId: string;
|
|
76
|
+
/** Tổng số tin nhắn */
|
|
77
|
+
totalMessages: number;
|
|
78
|
+
/** Số tin nhắn gửi thành công */
|
|
79
|
+
successfulMessages: number;
|
|
80
|
+
/** Số tin nhắn gửi thất bại */
|
|
81
|
+
failedMessages: number;
|
|
82
|
+
/** Chi tiết kết quả từng tin nhắn */
|
|
83
|
+
messageResults: Array<{
|
|
84
|
+
/** Index của tin nhắn trong danh sách */
|
|
85
|
+
messageIndex: number;
|
|
86
|
+
/** Loại tin nhắn */
|
|
87
|
+
messageType: string;
|
|
88
|
+
/** Trạng thái gửi */
|
|
89
|
+
success: boolean;
|
|
90
|
+
/** Kết quả chi tiết */
|
|
91
|
+
result?: GroupMessageResult;
|
|
92
|
+
/** Thông tin lỗi nếu thất bại */
|
|
93
|
+
error?: string;
|
|
94
|
+
/** Thời gian bắt đầu gửi */
|
|
95
|
+
startTime: number;
|
|
96
|
+
/** Thời gian kết thúc */
|
|
97
|
+
endTime: number;
|
|
98
|
+
/** Thời gian thực hiện (milliseconds) */
|
|
99
|
+
duration: number;
|
|
100
|
+
}>;
|
|
101
|
+
/** Tổng thời gian thực hiện (milliseconds) */
|
|
102
|
+
totalDuration: number;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Interface cho request gửi danh sách tin nhắn tới nhiều groups
|
|
106
|
+
*/
|
|
107
|
+
export interface SendMessageListToMultipleGroupsRequest {
|
|
108
|
+
/** Access token của Official Account */
|
|
109
|
+
accessToken: string;
|
|
110
|
+
/** Danh sách group IDs */
|
|
111
|
+
groupIds: string[];
|
|
112
|
+
/** Danh sách tin nhắn */
|
|
113
|
+
messages: GroupMessageItem[];
|
|
114
|
+
/** Delay mặc định giữa các tin nhắn (milliseconds) */
|
|
115
|
+
defaultDelay?: number;
|
|
116
|
+
/** Delay giữa các groups (milliseconds) để tránh rate limit */
|
|
117
|
+
delayBetweenGroups?: number;
|
|
118
|
+
/** Callback function để tracking tiến trình */
|
|
119
|
+
onProgress?: (progress: MultipleGroupsProgressInfo) => void;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Interface cho thông tin tiến trình từng group
|
|
123
|
+
*/
|
|
124
|
+
export interface MultipleGroupsProgressInfo {
|
|
125
|
+
/** Group ID hiện tại */
|
|
126
|
+
groupId: string;
|
|
127
|
+
/** Index của group trong danh sách (bắt đầu từ 0) */
|
|
128
|
+
groupIndex: number;
|
|
129
|
+
/** Tổng số groups */
|
|
130
|
+
totalGroups: number;
|
|
131
|
+
/** Trạng thái: 'started' | 'completed' | 'failed' */
|
|
132
|
+
status: 'started' | 'completed' | 'failed';
|
|
133
|
+
/** Kết quả gửi tin nhắn cho group này (nếu đã hoàn thành) */
|
|
134
|
+
result?: SendMessageListToGroupResponse;
|
|
135
|
+
/** Thông tin lỗi (nếu thất bại) */
|
|
136
|
+
error?: string;
|
|
137
|
+
/** Thời gian bắt đầu */
|
|
138
|
+
startTime: number;
|
|
139
|
+
/** Thời gian kết thúc (nếu đã hoàn thành) */
|
|
140
|
+
endTime?: number;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Interface cho response gửi danh sách tin nhắn tới nhiều groups
|
|
144
|
+
*/
|
|
145
|
+
export interface SendMessageListToMultipleGroupsResponse {
|
|
146
|
+
/** Tổng số groups */
|
|
147
|
+
totalGroups: number;
|
|
148
|
+
/** Số groups gửi thành công */
|
|
149
|
+
successfulGroups: number;
|
|
150
|
+
/** Số groups gửi thất bại */
|
|
151
|
+
failedGroups: number;
|
|
152
|
+
/** Chi tiết kết quả từng group */
|
|
153
|
+
groupResults: Array<{
|
|
154
|
+
/** Group ID */
|
|
155
|
+
groupId: string;
|
|
156
|
+
/** Index của group trong danh sách */
|
|
157
|
+
groupIndex: number;
|
|
158
|
+
/** Trạng thái gửi cho group này */
|
|
159
|
+
success: boolean;
|
|
160
|
+
/** Kết quả chi tiết gửi tin nhắn */
|
|
161
|
+
messageListResult?: SendMessageListToGroupResponse;
|
|
162
|
+
/** Thông tin lỗi nếu thất bại */
|
|
163
|
+
error?: string;
|
|
164
|
+
/** Thời gian bắt đầu gửi */
|
|
165
|
+
startTime: number;
|
|
166
|
+
/** Thời gian kết thúc */
|
|
167
|
+
endTime: number;
|
|
168
|
+
/** Thời gian thực hiện (milliseconds) */
|
|
169
|
+
duration: number;
|
|
170
|
+
}>;
|
|
171
|
+
/** Tổng thời gian thực hiện (milliseconds) */
|
|
172
|
+
totalDuration: number;
|
|
173
|
+
/** Thống kê tin nhắn tổng cộng */
|
|
174
|
+
messageStats: {
|
|
175
|
+
/** Tổng số tin nhắn đã gửi thành công */
|
|
176
|
+
totalSuccessfulMessages: number;
|
|
177
|
+
/** Tổng số tin nhắn thất bại */
|
|
178
|
+
totalFailedMessages: number;
|
|
179
|
+
/** Tổng số tin nhắn */
|
|
180
|
+
totalMessages: number;
|
|
181
|
+
};
|
|
182
|
+
}
|
|
3
183
|
/**
|
|
4
184
|
* Service for handling Zalo Official Account Group Message Framework (GMF) APIs
|
|
5
185
|
*
|
|
@@ -97,6 +277,26 @@ export declare class GroupMessageService {
|
|
|
97
277
|
members: GroupMember[];
|
|
98
278
|
total: number;
|
|
99
279
|
}>;
|
|
280
|
+
/**
|
|
281
|
+
* Gửi danh sách tin nhắn tới 1 group với delay tùy chỉnh
|
|
282
|
+
* Hỗ trợ tất cả các loại tin nhắn: text, image, file, sticker, mention
|
|
283
|
+
*
|
|
284
|
+
* @param request Thông tin request gửi danh sách tin nhắn
|
|
285
|
+
* @returns Kết quả gửi từng tin nhắn
|
|
286
|
+
*/
|
|
287
|
+
sendMessageListToGroup(request: SendMessageListToGroupRequest): Promise<SendMessageListToGroupResponse>;
|
|
100
288
|
private handleGroupMessageError;
|
|
289
|
+
/**
|
|
290
|
+
* Gửi danh sách tin nhắn tới nhiều groups với callback tracking
|
|
291
|
+
*
|
|
292
|
+
* @param request Thông tin request gửi danh sách tin nhắn tới nhiều groups
|
|
293
|
+
* @returns Kết quả gửi tin nhắn cho tất cả groups
|
|
294
|
+
*/
|
|
295
|
+
sendMessageListToMultipleGroups(request: SendMessageListToMultipleGroupsRequest): Promise<SendMessageListToMultipleGroupsResponse>;
|
|
296
|
+
/**
|
|
297
|
+
* Utility method để sleep/delay
|
|
298
|
+
* @param ms Thời gian delay tính bằng milliseconds
|
|
299
|
+
*/
|
|
300
|
+
private sleep;
|
|
101
301
|
}
|
|
102
302
|
//# sourceMappingURL=group-message.service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"group-message.service.d.ts","sourceRoot":"","sources":["../../src/services/group-message.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,mBAAmB,EACnB,mBAAmB,EACnB,kBAAkB,EAClB,SAAS,EACT,WAAW,EACZ,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"group-message.service.d.ts","sourceRoot":"","sources":["../../src/services/group-message.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,mBAAmB,EACnB,mBAAmB,EACnB,kBAAkB,EAClB,SAAS,EACT,WAAW,EACZ,MAAM,gBAAgB,CAAC;AAGxB;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,oBAAoB;IACpB,IAAI,EAAE,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS,GAAG,SAAS,CAAC;IACxD,mDAAmD;IACnD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,uCAAuC;IACvC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,wCAAwC;IACxC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,+CAA+C;IAC/C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,oCAAoC;IACpC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kCAAkC;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,uCAAuC;IACvC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,+CAA+C;IAC/C,QAAQ,CAAC,EAAE,KAAK,CAAC;QACf,OAAO,EAAE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
|
4
|
+
const common_1 = require("../types/common");
|
|
4
5
|
/**
|
|
5
6
|
* Service for handling Zalo Official Account Group Message Framework (GMF) APIs
|
|
6
7
|
*
|
|
@@ -247,6 +248,183 @@ class GroupMessageService {
|
|
|
247
248
|
throw this.handleGroupMessageError(error, "Failed to get group members");
|
|
248
249
|
}
|
|
249
250
|
}
|
|
251
|
+
/**
|
|
252
|
+
* Gửi danh sách tin nhắn tới 1 group với delay tùy chỉnh
|
|
253
|
+
* Hỗ trợ tất cả các loại tin nhắn: text, image, file, sticker, mention
|
|
254
|
+
*
|
|
255
|
+
* @param request Thông tin request gửi danh sách tin nhắn
|
|
256
|
+
* @returns Kết quả gửi từng tin nhắn
|
|
257
|
+
*/
|
|
258
|
+
async sendMessageListToGroup(request) {
|
|
259
|
+
const startTime = Date.now();
|
|
260
|
+
const messageResults = [];
|
|
261
|
+
let successfulMessages = 0;
|
|
262
|
+
let failedMessages = 0;
|
|
263
|
+
try {
|
|
264
|
+
// Validate input
|
|
265
|
+
if (!request.accessToken || request.accessToken.trim().length === 0) {
|
|
266
|
+
throw new common_1.ZaloSDKError("Access token không được để trống", -1);
|
|
267
|
+
}
|
|
268
|
+
if (!request.groupId || request.groupId.trim().length === 0) {
|
|
269
|
+
throw new common_1.ZaloSDKError("Group ID không được để trống", -1);
|
|
270
|
+
}
|
|
271
|
+
if (!request.messages || request.messages.length === 0) {
|
|
272
|
+
throw new common_1.ZaloSDKError("Danh sách tin nhắn không được để trống", -1);
|
|
273
|
+
}
|
|
274
|
+
// Gửi từng tin nhắn theo thứ tự
|
|
275
|
+
for (let i = 0; i < request.messages.length; i++) {
|
|
276
|
+
const message = request.messages[i];
|
|
277
|
+
const messageStartTime = Date.now();
|
|
278
|
+
// Callback: Bắt đầu gửi tin nhắn
|
|
279
|
+
if (request.onProgress) {
|
|
280
|
+
request.onProgress({
|
|
281
|
+
groupId: request.groupId,
|
|
282
|
+
messageIndex: i,
|
|
283
|
+
totalMessages: request.messages.length,
|
|
284
|
+
messageType: message.type,
|
|
285
|
+
status: 'started',
|
|
286
|
+
startTime: messageStartTime,
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
const messageResult = {
|
|
290
|
+
messageIndex: i,
|
|
291
|
+
messageType: message.type,
|
|
292
|
+
success: false,
|
|
293
|
+
startTime: messageStartTime,
|
|
294
|
+
endTime: 0,
|
|
295
|
+
duration: 0,
|
|
296
|
+
};
|
|
297
|
+
try {
|
|
298
|
+
let result;
|
|
299
|
+
// Gửi tin nhắn theo loại
|
|
300
|
+
switch (message.type) {
|
|
301
|
+
case "text":
|
|
302
|
+
if (!message.text) {
|
|
303
|
+
throw new Error("Text không được để trống cho text message");
|
|
304
|
+
}
|
|
305
|
+
result = await this.sendTextMessage(request.accessToken, request.groupId, { type: "text", text: message.text });
|
|
306
|
+
break;
|
|
307
|
+
case "image":
|
|
308
|
+
if (!message.imageUrl && !message.attachmentId) {
|
|
309
|
+
throw new Error("imageUrl hoặc attachmentId là bắt buộc cho image message");
|
|
310
|
+
}
|
|
311
|
+
result = await this.sendImageMessage(request.accessToken, request.groupId, {
|
|
312
|
+
type: "image",
|
|
313
|
+
imageUrl: message.imageUrl,
|
|
314
|
+
attachmentId: message.attachmentId,
|
|
315
|
+
caption: message.caption,
|
|
316
|
+
});
|
|
317
|
+
break;
|
|
318
|
+
case "file":
|
|
319
|
+
if (!message.fileToken) {
|
|
320
|
+
throw new Error("fileToken là bắt buộc cho file message");
|
|
321
|
+
}
|
|
322
|
+
result = await this.sendFileMessage(request.accessToken, request.groupId, {
|
|
323
|
+
type: "file",
|
|
324
|
+
fileToken: message.fileToken,
|
|
325
|
+
fileName: message.fileName,
|
|
326
|
+
});
|
|
327
|
+
break;
|
|
328
|
+
case "sticker":
|
|
329
|
+
if (!message.stickerId) {
|
|
330
|
+
throw new Error("stickerId là bắt buộc cho sticker message");
|
|
331
|
+
}
|
|
332
|
+
result = await this.sendStickerMessage(request.accessToken, request.groupId, {
|
|
333
|
+
type: "sticker",
|
|
334
|
+
stickerId: message.stickerId,
|
|
335
|
+
});
|
|
336
|
+
break;
|
|
337
|
+
case "mention":
|
|
338
|
+
if (!message.text || !message.mentions) {
|
|
339
|
+
throw new Error("text và mentions là bắt buộc cho mention message");
|
|
340
|
+
}
|
|
341
|
+
result = await this.sendMentionMessage(request.accessToken, request.groupId, {
|
|
342
|
+
type: "mention",
|
|
343
|
+
text: message.text,
|
|
344
|
+
mentions: message.mentions,
|
|
345
|
+
});
|
|
346
|
+
break;
|
|
347
|
+
default:
|
|
348
|
+
throw new Error(`Loại tin nhắn không được hỗ trợ: ${message.type}`);
|
|
349
|
+
}
|
|
350
|
+
// Ghi nhận thành công
|
|
351
|
+
const messageEndTime = Date.now();
|
|
352
|
+
messageResult.success = true;
|
|
353
|
+
messageResult.result = result;
|
|
354
|
+
messageResult.endTime = messageEndTime;
|
|
355
|
+
messageResult.duration = messageEndTime - messageStartTime;
|
|
356
|
+
successfulMessages++;
|
|
357
|
+
// Callback: Hoàn thành thành công
|
|
358
|
+
if (request.onProgress) {
|
|
359
|
+
request.onProgress({
|
|
360
|
+
groupId: request.groupId,
|
|
361
|
+
messageIndex: i,
|
|
362
|
+
totalMessages: request.messages.length,
|
|
363
|
+
messageType: message.type,
|
|
364
|
+
status: 'completed',
|
|
365
|
+
result: result,
|
|
366
|
+
startTime: messageStartTime,
|
|
367
|
+
endTime: messageEndTime,
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
catch (error) {
|
|
372
|
+
// Ghi nhận thất bại
|
|
373
|
+
const messageEndTime = Date.now();
|
|
374
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
375
|
+
messageResult.success = false;
|
|
376
|
+
messageResult.error = errorMessage;
|
|
377
|
+
messageResult.endTime = messageEndTime;
|
|
378
|
+
messageResult.duration = messageEndTime - messageStartTime;
|
|
379
|
+
failedMessages++;
|
|
380
|
+
// Callback: Thất bại
|
|
381
|
+
if (request.onProgress) {
|
|
382
|
+
request.onProgress({
|
|
383
|
+
groupId: request.groupId,
|
|
384
|
+
messageIndex: i,
|
|
385
|
+
totalMessages: request.messages.length,
|
|
386
|
+
messageType: message.type,
|
|
387
|
+
status: 'failed',
|
|
388
|
+
error: errorMessage,
|
|
389
|
+
startTime: messageStartTime,
|
|
390
|
+
endTime: messageEndTime,
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
messageResults.push(messageResult);
|
|
395
|
+
// Delay trước khi gửi tin nhắn tiếp theo (trừ tin nhắn cuối cùng)
|
|
396
|
+
if (i < request.messages.length - 1) {
|
|
397
|
+
const delayTime = message.delay ?? request.defaultDelay ?? 0;
|
|
398
|
+
if (delayTime > 0) {
|
|
399
|
+
await this.sleep(delayTime);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
const totalDuration = Date.now() - startTime;
|
|
404
|
+
return {
|
|
405
|
+
groupId: request.groupId,
|
|
406
|
+
totalMessages: request.messages.length,
|
|
407
|
+
successfulMessages,
|
|
408
|
+
failedMessages,
|
|
409
|
+
messageResults,
|
|
410
|
+
totalDuration,
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
catch (error) {
|
|
414
|
+
const totalDuration = Date.now() - startTime;
|
|
415
|
+
if (error instanceof common_1.ZaloSDKError) {
|
|
416
|
+
throw error;
|
|
417
|
+
}
|
|
418
|
+
throw new common_1.ZaloSDKError(`Failed to send message list to group: ${error.message}`, -1, {
|
|
419
|
+
groupId: request.groupId,
|
|
420
|
+
totalMessages: request.messages?.length || 0,
|
|
421
|
+
successfulMessages,
|
|
422
|
+
failedMessages,
|
|
423
|
+
messageResults,
|
|
424
|
+
totalDuration,
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
}
|
|
250
428
|
handleGroupMessageError(error, defaultMessage) {
|
|
251
429
|
if (error.response?.data) {
|
|
252
430
|
const errorData = error.response.data;
|
|
@@ -254,6 +432,159 @@ class GroupMessageService {
|
|
|
254
432
|
}
|
|
255
433
|
return new Error(`${defaultMessage}: ${error.message || "Unknown error"}`);
|
|
256
434
|
}
|
|
435
|
+
/**
|
|
436
|
+
* Gửi danh sách tin nhắn tới nhiều groups với callback tracking
|
|
437
|
+
*
|
|
438
|
+
* @param request Thông tin request gửi danh sách tin nhắn tới nhiều groups
|
|
439
|
+
* @returns Kết quả gửi tin nhắn cho tất cả groups
|
|
440
|
+
*/
|
|
441
|
+
async sendMessageListToMultipleGroups(request) {
|
|
442
|
+
const startTime = Date.now();
|
|
443
|
+
const groupResults = [];
|
|
444
|
+
let successfulGroups = 0;
|
|
445
|
+
let failedGroups = 0;
|
|
446
|
+
let totalSuccessfulMessages = 0;
|
|
447
|
+
let totalFailedMessages = 0;
|
|
448
|
+
try {
|
|
449
|
+
// Validate input
|
|
450
|
+
if (!request.accessToken || request.accessToken.trim().length === 0) {
|
|
451
|
+
throw new common_1.ZaloSDKError("Access token không được để trống", -1);
|
|
452
|
+
}
|
|
453
|
+
if (!request.groupIds || request.groupIds.length === 0) {
|
|
454
|
+
throw new common_1.ZaloSDKError("Danh sách group IDs không được để trống", -1);
|
|
455
|
+
}
|
|
456
|
+
if (!request.messages || request.messages.length === 0) {
|
|
457
|
+
throw new common_1.ZaloSDKError("Danh sách tin nhắn không được để trống", -1);
|
|
458
|
+
}
|
|
459
|
+
// Loại bỏ group IDs trùng lặp và rỗng
|
|
460
|
+
const uniqueGroupIds = [...new Set(request.groupIds.filter(id => id && id.trim().length > 0))];
|
|
461
|
+
if (uniqueGroupIds.length === 0) {
|
|
462
|
+
throw new common_1.ZaloSDKError("Không có group ID hợp lệ nào", -1);
|
|
463
|
+
}
|
|
464
|
+
// Gửi tin nhắn cho từng group tuần tự
|
|
465
|
+
for (let i = 0; i < uniqueGroupIds.length; i++) {
|
|
466
|
+
const groupId = uniqueGroupIds[i];
|
|
467
|
+
const groupStartTime = Date.now();
|
|
468
|
+
// Callback: Bắt đầu gửi cho group
|
|
469
|
+
if (request.onProgress) {
|
|
470
|
+
request.onProgress({
|
|
471
|
+
groupId,
|
|
472
|
+
groupIndex: i,
|
|
473
|
+
totalGroups: uniqueGroupIds.length,
|
|
474
|
+
status: 'started',
|
|
475
|
+
startTime: groupStartTime,
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
const groupResult = {
|
|
479
|
+
groupId,
|
|
480
|
+
groupIndex: i,
|
|
481
|
+
success: false,
|
|
482
|
+
startTime: groupStartTime,
|
|
483
|
+
endTime: 0,
|
|
484
|
+
duration: 0,
|
|
485
|
+
};
|
|
486
|
+
try {
|
|
487
|
+
// Gửi danh sách tin nhắn cho group này
|
|
488
|
+
const messageListResult = await this.sendMessageListToGroup({
|
|
489
|
+
accessToken: request.accessToken,
|
|
490
|
+
groupId,
|
|
491
|
+
messages: request.messages,
|
|
492
|
+
defaultDelay: request.defaultDelay,
|
|
493
|
+
// Không truyền onProgress để tránh callback lồng nhau
|
|
494
|
+
});
|
|
495
|
+
// Ghi nhận thành công
|
|
496
|
+
const groupEndTime = Date.now();
|
|
497
|
+
groupResult.success = true;
|
|
498
|
+
groupResult.messageListResult = messageListResult;
|
|
499
|
+
groupResult.endTime = groupEndTime;
|
|
500
|
+
groupResult.duration = groupEndTime - groupStartTime;
|
|
501
|
+
successfulGroups++;
|
|
502
|
+
totalSuccessfulMessages += messageListResult.successfulMessages;
|
|
503
|
+
totalFailedMessages += messageListResult.failedMessages;
|
|
504
|
+
// Callback: Hoàn thành thành công
|
|
505
|
+
if (request.onProgress) {
|
|
506
|
+
request.onProgress({
|
|
507
|
+
groupId,
|
|
508
|
+
groupIndex: i,
|
|
509
|
+
totalGroups: uniqueGroupIds.length,
|
|
510
|
+
status: 'completed',
|
|
511
|
+
result: messageListResult,
|
|
512
|
+
startTime: groupStartTime,
|
|
513
|
+
endTime: groupEndTime,
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
catch (error) {
|
|
518
|
+
// Ghi nhận thất bại
|
|
519
|
+
const groupEndTime = Date.now();
|
|
520
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
521
|
+
groupResult.success = false;
|
|
522
|
+
groupResult.error = errorMessage;
|
|
523
|
+
groupResult.endTime = groupEndTime;
|
|
524
|
+
groupResult.duration = groupEndTime - groupStartTime;
|
|
525
|
+
failedGroups++;
|
|
526
|
+
// Với group thất bại, coi như tất cả tin nhắn đều thất bại
|
|
527
|
+
totalFailedMessages += request.messages.length;
|
|
528
|
+
// Callback: Thất bại
|
|
529
|
+
if (request.onProgress) {
|
|
530
|
+
request.onProgress({
|
|
531
|
+
groupId,
|
|
532
|
+
groupIndex: i,
|
|
533
|
+
totalGroups: uniqueGroupIds.length,
|
|
534
|
+
status: 'failed',
|
|
535
|
+
error: errorMessage,
|
|
536
|
+
startTime: groupStartTime,
|
|
537
|
+
endTime: groupEndTime,
|
|
538
|
+
});
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
groupResults.push(groupResult);
|
|
542
|
+
// Delay giữa các groups (trừ group cuối cùng)
|
|
543
|
+
if (i < uniqueGroupIds.length - 1 && request.delayBetweenGroups && request.delayBetweenGroups > 0) {
|
|
544
|
+
await this.sleep(request.delayBetweenGroups);
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
const totalDuration = Date.now() - startTime;
|
|
548
|
+
const totalMessages = uniqueGroupIds.length * request.messages.length;
|
|
549
|
+
return {
|
|
550
|
+
totalGroups: uniqueGroupIds.length,
|
|
551
|
+
successfulGroups,
|
|
552
|
+
failedGroups,
|
|
553
|
+
groupResults,
|
|
554
|
+
totalDuration,
|
|
555
|
+
messageStats: {
|
|
556
|
+
totalSuccessfulMessages,
|
|
557
|
+
totalFailedMessages,
|
|
558
|
+
totalMessages,
|
|
559
|
+
},
|
|
560
|
+
};
|
|
561
|
+
}
|
|
562
|
+
catch (error) {
|
|
563
|
+
const totalDuration = Date.now() - startTime;
|
|
564
|
+
if (error instanceof common_1.ZaloSDKError) {
|
|
565
|
+
throw error;
|
|
566
|
+
}
|
|
567
|
+
throw new common_1.ZaloSDKError(`Failed to send message list to multiple groups: ${error.message}`, -1, {
|
|
568
|
+
totalGroups: request.groupIds?.length || 0,
|
|
569
|
+
successfulGroups,
|
|
570
|
+
failedGroups,
|
|
571
|
+
groupResults,
|
|
572
|
+
totalDuration,
|
|
573
|
+
messageStats: {
|
|
574
|
+
totalSuccessfulMessages,
|
|
575
|
+
totalFailedMessages,
|
|
576
|
+
totalMessages: (request.groupIds?.length || 0) * (request.messages?.length || 0),
|
|
577
|
+
},
|
|
578
|
+
});
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
/**
|
|
582
|
+
* Utility method để sleep/delay
|
|
583
|
+
* @param ms Thời gian delay tính bằng milliseconds
|
|
584
|
+
*/
|
|
585
|
+
sleep(ms) {
|
|
586
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
587
|
+
}
|
|
257
588
|
}
|
|
258
589
|
exports.GroupMessageService = GroupMessageService;
|
|
259
590
|
//# sourceMappingURL=group-message.service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"group-message.service.js","sourceRoot":"","sources":["../../src/services/group-message.service.ts"],"names":[],"mappings":";;;AAYA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAa,mBAAmB;IAc9B,YAA6B,MAAkB;QAAlB,WAAM,GAAN,MAAM,CAAY;QAb/C,kDAAkD;QACjC,cAAS,GAAG;YAC3B,0BAA0B;YAC1B,OAAO,EAAE;gBACP,KAAK,EAAE,+CAA+C;aACvD;YACD,6BAA6B;YAC7B,KAAK,EAAE;gBACL,OAAO,EAAE,+CAA+C;gBACxD,UAAU,EAAE,kDAAkD;aAC/D;SACF,CAAC;IAEgD,CAAC;IAEnD;;;;;;OAMG;IACH,KAAK,CAAC,eAAe,CACnB,WAAmB,EACnB,OAAe,EACf,OAAyB;QAEzB,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAA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C;YAEF,OAAO,QAAQ,CAAC;QAClB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,CAAC,uBAAuB,CAChC,KAAK,EACL,iCAAiC,CAClC,CAAC;QACJ,CAAC;IACH,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,eAAe,CACnB,WAAmB,EACnB,OAAe,EACf,SAAiB,CAAC,EAClB,QAAgB,EAAE;QAElB,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CAGtC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,UAAU,EAAE,WAAW,EAAE;gBAC/C,QAAQ,EAAE,OAAO;gBACjB,MAAM;gBACN,KAAK;aACN,CAAC,CAAC;YAEH,OAAO,QAAQ,CAAC;QAClB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,CAAC,uBAAuB,CAAC,KAAK,EAAE,6BAA6B,CAAC,CAAC;QAC3E,CAAC;IACH,CAAC;IAEO,uBAAuB,CAAC,KAAU,EAAE,cAAsB;QAChE,IAAI,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC;YACzB,MAAM,SAAS,GAAG,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC;YACtC,OAAO,IAAI,KAAK,CACd,GAAG,cAAc,KACf,SAAS,CAAC,OAAO,IAAI,SAAS,CAAC,KAAK,IAAI,eAC1C,EAAE,CACH,CAAC;QACJ,CAAC;QACD,OAAO,IAAI,KAAK,CAAC,GAAG,cAAc,KAAK,KAAK,CAAC,OAAO,IAAI,eAAe,EAAE,CAAC,CAAC;IAC7E,CAAC;CACF;AA/SD,kDA+SC"}
|
|
1
|
+
{"version":3,"file":"group-message.service.js","sourceRoot":"","sources":["../../src/services/group-message.service.ts"],"names":[],"mappings":";;;AAWA,4CAA+C;AA6L/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAa,mBAAmB;I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AC1C,gBAAgB;gBAChB,YAAY;gBACZ,YAAY;gBACZ,aAAa;gBACb,YAAY,EAAE;oBACZ,uBAAuB;oBACvB,mBAAmB;oBACnB,aAAa,EAAE,CAAC,OAAO,CAAC,QAAQ,EAAE,MAAM,IAAI,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,EAAE,MAAM,IAAI,CAAC,CAAC;iBACjF;aACF,CACF,CAAC;QACJ,CAAC;IACH,CAAC;IAED;;;OAGG;IACK,KAAK,CAAC,EAAU;QACtB,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;IACzD,CAAC;CACF;AA1sBD,kDA0sBC"}
|
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
# API Gửi Danh Sách Tin Nhắn Group
|
|
2
|
+
|
|
3
|
+
API mở rộng cho phép gửi danh sách tin nhắn tới groups với callback tracking real-time.
|
|
4
|
+
|
|
5
|
+
## Tính năng
|
|
6
|
+
|
|
7
|
+
- ✅ Gửi danh sách tin nhắn tới 1 group
|
|
8
|
+
- ✅ Gửi danh sách tin nhắn tới nhiều groups cùng lúc
|
|
9
|
+
- ✅ Hỗ trợ đầy đủ 5 loại tin nhắn: text, image, file, sticker, mention
|
|
10
|
+
- ✅ Callback tracking real-time cho từng tin nhắn/group
|
|
11
|
+
- ✅ Delay tùy chỉnh giữa tin nhắn và giữa groups
|
|
12
|
+
- ✅ Thống kê chi tiết thành công/thất bại
|
|
13
|
+
- ✅ Error isolation - lỗi 1 tin nhắn/group không ảnh hưởng phần còn lại
|
|
14
|
+
|
|
15
|
+
## Cách sử dụng
|
|
16
|
+
|
|
17
|
+
### 1. Import các interface và service
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import {
|
|
21
|
+
GroupMessageService,
|
|
22
|
+
GroupMessageItem,
|
|
23
|
+
SendMessageListToGroupRequest,
|
|
24
|
+
SendMessageListToMultipleGroupsRequest
|
|
25
|
+
} from "../src/services/group-message.service";
|
|
26
|
+
import { ZaloClient } from "../src/clients/zalo-client";
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### 2. Khởi tạo service
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
const zaloClient = new ZaloClient();
|
|
33
|
+
const groupMessageService = new GroupMessageService(zaloClient);
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### 3. Định nghĩa danh sách tin nhắn
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
const messages: GroupMessageItem[] = [
|
|
40
|
+
{
|
|
41
|
+
type: "text",
|
|
42
|
+
text: "📢 Thông báo quan trọng!",
|
|
43
|
+
delay: 2000, // Delay 2 giây sau tin nhắn này
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
type: "image",
|
|
47
|
+
imageUrl: "https://example.com/image.jpg",
|
|
48
|
+
caption: "Hình ảnh minh họa",
|
|
49
|
+
delay: 1500,
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
type: "mention",
|
|
53
|
+
text: "@Admin Vui lòng xem thông báo",
|
|
54
|
+
mentions: [
|
|
55
|
+
{ user_id: "ADMIN_ID", offset: 0, length: 6 }
|
|
56
|
+
],
|
|
57
|
+
},
|
|
58
|
+
];
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### 4. Gửi tới 1 group
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
const result = await groupMessageService.sendMessageListToGroup({
|
|
65
|
+
accessToken: "YOUR_ACCESS_TOKEN",
|
|
66
|
+
groupId: "GROUP_ID",
|
|
67
|
+
messages,
|
|
68
|
+
defaultDelay: 1000,
|
|
69
|
+
onProgress: (progress) => {
|
|
70
|
+
console.log(`${progress.status}: Message ${progress.messageIndex + 1}/${progress.totalMessages}`);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
console.log(`Thành công: ${result.successfulMessages}/${result.totalMessages} tin nhắn`);
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### 5. Gửi tới nhiều groups
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
const result = await groupMessageService.sendMessageListToMultipleGroups({
|
|
81
|
+
accessToken: "YOUR_ACCESS_TOKEN",
|
|
82
|
+
groupIds: ["GROUP_1", "GROUP_2", "GROUP_3"],
|
|
83
|
+
messages,
|
|
84
|
+
defaultDelay: 1000,
|
|
85
|
+
delayBetweenGroups: 3000, // Delay 3s giữa các groups
|
|
86
|
+
onProgress: (progress) => {
|
|
87
|
+
console.log(`${progress.status}: Group ${progress.groupIndex + 1}/${progress.totalGroups}`);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
console.log(`Thành công: ${result.successfulGroups}/${result.totalGroups} groups`);
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Các loại tin nhắn được hỗ trợ
|
|
95
|
+
|
|
96
|
+
### 1. Text Message
|
|
97
|
+
```typescript
|
|
98
|
+
{
|
|
99
|
+
type: "text",
|
|
100
|
+
text: "Nội dung tin nhắn",
|
|
101
|
+
delay: 1000, // Optional
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### 2. Image Message
|
|
106
|
+
```typescript
|
|
107
|
+
// Sử dụng URL
|
|
108
|
+
{
|
|
109
|
+
type: "image",
|
|
110
|
+
imageUrl: "https://example.com/image.jpg",
|
|
111
|
+
caption: "Caption cho ảnh", // Optional, max 2000 ký tự
|
|
112
|
+
delay: 1500,
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Hoặc sử dụng attachment ID
|
|
116
|
+
{
|
|
117
|
+
type: "image",
|
|
118
|
+
attachmentId: "ATTACHMENT_ID",
|
|
119
|
+
caption: "Caption cho ảnh",
|
|
120
|
+
delay: 1500,
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### 3. File Message
|
|
125
|
+
```typescript
|
|
126
|
+
{
|
|
127
|
+
type: "file",
|
|
128
|
+
fileToken: "FILE_TOKEN_FROM_UPLOAD_API", // Bắt buộc
|
|
129
|
+
fileName: "document.pdf", // Optional
|
|
130
|
+
delay: 1000,
|
|
131
|
+
}
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### 4. Sticker Message
|
|
135
|
+
```typescript
|
|
136
|
+
{
|
|
137
|
+
type: "sticker",
|
|
138
|
+
stickerId: "STICKER_ID", // Bắt buộc
|
|
139
|
+
delay: 500,
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### 5. Mention Message
|
|
144
|
+
```typescript
|
|
145
|
+
{
|
|
146
|
+
type: "mention",
|
|
147
|
+
text: "@Admin @User Vui lòng xem thông báo", // Bắt buộc
|
|
148
|
+
mentions: [ // Bắt buộc
|
|
149
|
+
{ user_id: "ADMIN_ID", offset: 0, length: 6 },
|
|
150
|
+
{ user_id: "USER_ID", offset: 7, length: 5 }
|
|
151
|
+
],
|
|
152
|
+
delay: 2000,
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## Interface chi tiết
|
|
157
|
+
|
|
158
|
+
### GroupMessageItem
|
|
159
|
+
```typescript
|
|
160
|
+
interface GroupMessageItem {
|
|
161
|
+
type: "text" | "image" | "file" | "sticker" | "mention";
|
|
162
|
+
text?: string;
|
|
163
|
+
imageUrl?: string;
|
|
164
|
+
attachmentId?: string;
|
|
165
|
+
caption?: string;
|
|
166
|
+
fileToken?: string;
|
|
167
|
+
fileName?: string;
|
|
168
|
+
stickerId?: string;
|
|
169
|
+
mentions?: Array<{
|
|
170
|
+
user_id: string;
|
|
171
|
+
offset: number;
|
|
172
|
+
length: number;
|
|
173
|
+
}>;
|
|
174
|
+
delay?: number; // milliseconds
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### SendMessageListToGroupRequest
|
|
179
|
+
```typescript
|
|
180
|
+
interface SendMessageListToGroupRequest {
|
|
181
|
+
accessToken: string;
|
|
182
|
+
groupId: string;
|
|
183
|
+
messages: GroupMessageItem[];
|
|
184
|
+
defaultDelay?: number; // milliseconds
|
|
185
|
+
onProgress?: (progress: GroupMessageProgressInfo) => void;
|
|
186
|
+
}
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### SendMessageListToMultipleGroupsRequest
|
|
190
|
+
```typescript
|
|
191
|
+
interface SendMessageListToMultipleGroupsRequest {
|
|
192
|
+
accessToken: string;
|
|
193
|
+
groupIds: string[];
|
|
194
|
+
messages: GroupMessageItem[];
|
|
195
|
+
defaultDelay?: number; // milliseconds
|
|
196
|
+
delayBetweenGroups?: number; // milliseconds
|
|
197
|
+
onProgress?: (progress: MultipleGroupsProgressInfo) => void;
|
|
198
|
+
}
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
## Ví dụ thực tế
|
|
202
|
+
|
|
203
|
+
### Thông báo bảo trì hệ thống
|
|
204
|
+
```typescript
|
|
205
|
+
const maintenanceMessages: GroupMessageItem[] = [
|
|
206
|
+
{
|
|
207
|
+
type: "text",
|
|
208
|
+
text: "🔧 THÔNG BÁO BẢO TRÌ HỆ THỐNG",
|
|
209
|
+
delay: 2000,
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
type: "text",
|
|
213
|
+
text: "⏰ Thời gian: 2:00 - 4:00 sáng ngày mai\n⚠️ Các dịch vụ sẽ tạm ngưng",
|
|
214
|
+
delay: 1500,
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
type: "image",
|
|
218
|
+
imageUrl: "https://company.com/maintenance-schedule.jpg",
|
|
219
|
+
caption: "Lịch trình bảo trì chi tiết",
|
|
220
|
+
delay: 2000,
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
type: "text",
|
|
224
|
+
text: "📞 Hotline hỗ trợ: 1900-xxxx",
|
|
225
|
+
},
|
|
226
|
+
];
|
|
227
|
+
|
|
228
|
+
const result = await groupMessageService.sendMessageListToMultipleGroups({
|
|
229
|
+
accessToken: "TOKEN",
|
|
230
|
+
groupIds: ["TECH_GROUP", "SUPPORT_GROUP", "ADMIN_GROUP"],
|
|
231
|
+
messages: maintenanceMessages,
|
|
232
|
+
delayBetweenGroups: 2000,
|
|
233
|
+
onProgress: (progress) => {
|
|
234
|
+
if (progress.status === 'completed') {
|
|
235
|
+
console.log(`✅ Đã thông báo tới group ${progress.groupIndex + 1}`);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
### Marketing Campaign
|
|
242
|
+
```typescript
|
|
243
|
+
const campaignMessages: GroupMessageItem[] = [
|
|
244
|
+
{
|
|
245
|
+
type: "text",
|
|
246
|
+
text: "🎉 FLASH SALE 24H - GIẢM GIÁ SỐC!",
|
|
247
|
+
delay: 2000,
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
type: "image",
|
|
251
|
+
imageUrl: "https://shop.com/flash-sale-banner.jpg",
|
|
252
|
+
caption: "🔥 Giảm tới 70% + Freeship",
|
|
253
|
+
delay: 3000,
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
type: "text",
|
|
257
|
+
text: "⏰ Chỉ còn 12 giờ!\n🛒 Mua ngay: https://shop.com/sale",
|
|
258
|
+
delay: 1500,
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
type: "sticker",
|
|
262
|
+
stickerId: "SALE_STICKER_ID",
|
|
263
|
+
},
|
|
264
|
+
];
|
|
265
|
+
|
|
266
|
+
const customerGroups = ["VIP_CUSTOMERS", "REGULAR_CUSTOMERS", "NEW_CUSTOMERS"];
|
|
267
|
+
|
|
268
|
+
const result = await groupMessageService.sendMessageListToMultipleGroups({
|
|
269
|
+
accessToken: "TOKEN",
|
|
270
|
+
groupIds: customerGroups,
|
|
271
|
+
messages: campaignMessages,
|
|
272
|
+
defaultDelay: 1000,
|
|
273
|
+
delayBetweenGroups: 5000, // 5s delay để tránh spam
|
|
274
|
+
onProgress: (progress) => {
|
|
275
|
+
console.log(`📤 Campaign progress: ${progress.groupIndex + 1}/${progress.totalGroups}`);
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
console.log(`🎯 Campaign hoàn thành: ${result.successfulGroups} groups nhận được tin nhắn`);
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
### Meeting Notification với Mention
|
|
283
|
+
```typescript
|
|
284
|
+
const meetingMessages: GroupMessageItem[] = [
|
|
285
|
+
{
|
|
286
|
+
type: "text",
|
|
287
|
+
text: "📅 THÔNG BÁO CUỘC HỌP",
|
|
288
|
+
delay: 1000,
|
|
289
|
+
},
|
|
290
|
+
{
|
|
291
|
+
type: "mention",
|
|
292
|
+
text: "@TeamLead @Developer @Designer Cuộc họp dự án lúc 14:00 hôm nay",
|
|
293
|
+
mentions: [
|
|
294
|
+
{ user_id: "LEAD_ID", offset: 0, length: 9 },
|
|
295
|
+
{ user_id: "DEV_ID", offset: 10, length: 10 },
|
|
296
|
+
{ user_id: "DESIGN_ID", offset: 21, length: 9 }
|
|
297
|
+
],
|
|
298
|
+
delay: 2000,
|
|
299
|
+
},
|
|
300
|
+
{
|
|
301
|
+
type: "text",
|
|
302
|
+
text: "📋 Agenda:\n1. Sprint review\n2. Planning\n3. Q&A",
|
|
303
|
+
},
|
|
304
|
+
];
|
|
305
|
+
|
|
306
|
+
const result = await groupMessageService.sendMessageListToGroup({
|
|
307
|
+
accessToken: "TOKEN",
|
|
308
|
+
groupId: "PROJECT_TEAM_GROUP",
|
|
309
|
+
messages: meetingMessages,
|
|
310
|
+
defaultDelay: 1500,
|
|
311
|
+
});
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
## So sánh với API cũ
|
|
315
|
+
|
|
316
|
+
| Tính năng | API cũ | API mới |
|
|
317
|
+
|-----------|--------|---------|
|
|
318
|
+
| Số lượng tin nhắn | 1 tin nhắn | Nhiều tin nhắn |
|
|
319
|
+
| Số lượng groups | 1 group | 1 hoặc nhiều groups |
|
|
320
|
+
| Callback tracking | ❌ | ✅ Real-time |
|
|
321
|
+
| Delay control | ❌ | ✅ Tùy chỉnh |
|
|
322
|
+
| Error handling | Dừng khi lỗi | Tiếp tục với tin nhắn/group khác |
|
|
323
|
+
| Statistics | ❌ | ✅ Chi tiết |
|
|
324
|
+
| Use case | Tin nhắn đơn lẻ | Campaigns, notifications |
|
|
325
|
+
|
|
326
|
+
## Lưu ý quan trọng
|
|
327
|
+
|
|
328
|
+
1. **Rate Limiting**: Sử dụng `delayBetweenGroups` để tránh hit rate limit
|
|
329
|
+
2. **Group Permissions**: OA phải có quyền gửi tin nhắn trong group
|
|
330
|
+
3. **Message Limits**: Tuân thủ giới hạn của từng loại tin nhắn (text: 2000 ký tự, etc.)
|
|
331
|
+
4. **Error Isolation**: Lỗi của 1 tin nhắn/group không ảnh hưởng phần còn lại
|
|
332
|
+
5. **Callback Performance**: Callback không nên thực hiện operations nặng
|
|
@@ -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
|
+
};
|
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, Enhanced Article Management, and Message Sequence APIs with Real-time Tracking",
|
|
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": {
|
|
@@ -40,7 +40,13 @@
|
|
|
40
40
|
"real-time-tracking",
|
|
41
41
|
"callback-tracking",
|
|
42
42
|
"multiple-users",
|
|
43
|
-
"campaign-management"
|
|
43
|
+
"campaign-management",
|
|
44
|
+
"group-messaging",
|
|
45
|
+
"group-message-list",
|
|
46
|
+
"bulk-group-messaging",
|
|
47
|
+
"group-notifications",
|
|
48
|
+
"team-communication",
|
|
49
|
+
"group-automation"
|
|
44
50
|
],
|
|
45
51
|
"author": "RedAI Team",
|
|
46
52
|
"license": "MIT",
|