@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
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,167 @@ 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
|
+
|
|
91
|
+
## [1.18.0] - 2025-08-29
|
|
92
|
+
|
|
93
|
+
### 🚀 NEW FEATURES
|
|
94
|
+
|
|
95
|
+
#### Message Sequence APIs - Gửi Chuỗi Tin Nhắn Tự Động
|
|
96
|
+
- **ADDED**: `sendMessageSequence()` - Gửi chuỗi tin nhắn tư vấn với delay tùy chỉnh
|
|
97
|
+
- **ADDED**: `sendMessageSequenceToMultipleUsers()` - Gửi chuỗi tin nhắn tới nhiều users cùng lúc
|
|
98
|
+
- **SUPPORT**: Hỗ trợ đầy đủ 6 loại tin nhắn: text, image, gif, file, sticker, request_user_info
|
|
99
|
+
- **FLEXIBLE**: Delay riêng cho từng tin nhắn + delay mặc định cho toàn bộ chuỗi
|
|
100
|
+
- **SMART**: Tự động loại bỏ user IDs trùng lặp và validation đầy đủ
|
|
101
|
+
|
|
102
|
+
#### Real-time Progress Tracking
|
|
103
|
+
- **CALLBACK**: `onProgress` callback để tracking real-time từng user
|
|
104
|
+
- **DETAILED**: Thống kê chi tiết thành công/thất bại cho từng tin nhắn và user
|
|
105
|
+
- **ISOLATION**: Error của 1 user không ảnh hưởng đến users khác
|
|
106
|
+
- **METRICS**: Tracking thời gian thực hiện, success rate, và message statistics
|
|
107
|
+
|
|
108
|
+
#### Rate Limiting Protection
|
|
109
|
+
- **PROTECTION**: `delayBetweenUsers` để tránh hit rate limit của Zalo
|
|
110
|
+
- **SEQUENTIAL**: Gửi tuần tự từng user để đảm bảo stability
|
|
111
|
+
- **CONFIGURABLE**: Delay linh hoạt theo từng use case
|
|
112
|
+
|
|
113
|
+
### 📊 NEW INTERFACES
|
|
114
|
+
|
|
115
|
+
#### Message Sequence Types
|
|
116
|
+
- **ADDED**: `MessageItem` - Interface cho từng tin nhắn trong chuỗi
|
|
117
|
+
- **ADDED**: `SendMessageSequenceRequest` - Request cho single user
|
|
118
|
+
- **ADDED**: `SendMessageSequenceResponse` - Response với detailed results
|
|
119
|
+
- **ADDED**: `SendMessageSequenceToMultipleUsersRequest` - Request cho multiple users
|
|
120
|
+
- **ADDED**: `SendMessageSequenceToMultipleUsersResponse` - Response với user statistics
|
|
121
|
+
- **ADDED**: `UserProgressInfo` - Interface cho progress tracking callback
|
|
122
|
+
|
|
123
|
+
### 📚 DOCUMENTATION & EXAMPLES
|
|
124
|
+
|
|
125
|
+
#### New Documentation
|
|
126
|
+
- **ADDED**: `docs/message-sequence-api.md` - Comprehensive guide cho Message Sequence APIs
|
|
127
|
+
- **UPDATED**: Hướng dẫn chi tiết từng loại tin nhắn và use cases
|
|
128
|
+
- **ADDED**: So sánh API đơn user vs nhiều users với bảng feature comparison
|
|
129
|
+
|
|
130
|
+
#### New Examples
|
|
131
|
+
- **ADDED**: `examples/send-message-sequence.ts` - Ví dụ gửi chuỗi tin nhắn cho 1 user
|
|
132
|
+
- **ADDED**: `examples/send-message-sequence-multiple-users.ts` - Ví dụ gửi cho nhiều users
|
|
133
|
+
- **INCLUDED**: Marketing campaigns, customer support, VIP customer care examples
|
|
134
|
+
|
|
135
|
+
### 🎯 USE CASES
|
|
136
|
+
|
|
137
|
+
#### Marketing & Campaigns
|
|
138
|
+
- **CAMPAIGN**: Gửi chuỗi tin nhắn marketing tới danh sách khách hàng
|
|
139
|
+
- **PROMOTION**: Flash sales, khuyến mãi với hình ảnh và call-to-action
|
|
140
|
+
- **TRACKING**: Real-time tracking delivery success rate
|
|
141
|
+
|
|
142
|
+
#### Customer Support
|
|
143
|
+
- **NOTIFICATION**: Thông báo hệ thống, bảo trì tới tất cả users
|
|
144
|
+
- **SUPPORT**: Gửi hướng dẫn, tài liệu hỗ trợ với file attachments
|
|
145
|
+
- **CARE**: Chăm sóc khách hàng VIP với tin nhắn cá nhân hóa
|
|
146
|
+
|
|
147
|
+
#### Business Automation
|
|
148
|
+
- **ONBOARDING**: Chuỗi tin nhắn chào mừng khách hàng mới
|
|
149
|
+
- **FOLLOW-UP**: Theo dõi sau bán hàng với stickers và images
|
|
150
|
+
- **SURVEY**: Thu thập feedback với request user info messages
|
|
151
|
+
|
|
152
|
+
### 🔧 TECHNICAL IMPROVEMENTS
|
|
153
|
+
|
|
154
|
+
#### Error Handling
|
|
155
|
+
- **ROBUST**: Comprehensive error handling cho từng tin nhắn và user
|
|
156
|
+
- **CONTINUE**: Tiếp tục gửi khi gặp lỗi thay vì dừng toàn bộ process
|
|
157
|
+
- **DETAILED**: Error messages chi tiết với context information
|
|
158
|
+
|
|
159
|
+
#### Performance
|
|
160
|
+
- **EFFICIENT**: Sequential processing để tránh overwhelming Zalo servers
|
|
161
|
+
- **MEMORY**: Optimized memory usage cho large user lists
|
|
162
|
+
- **TIMEOUT**: Proper timeout handling và cleanup
|
|
163
|
+
|
|
164
|
+
#### Type Safety
|
|
165
|
+
- **TYPESCRIPT**: Full TypeScript support với strict typing
|
|
166
|
+
- **VALIDATION**: Runtime validation cho tất cả input parameters
|
|
167
|
+
- **INTELLISENSE**: Complete IDE support với detailed JSDoc comments
|
|
168
|
+
|
|
8
169
|
## [1.17.2] - 2025-08-29
|
|
9
170
|
|
|
10
171
|
### 🐛 BUG FIXES
|
|
@@ -1,5 +1,152 @@
|
|
|
1
1
|
import { ZaloClient } from "../clients/zalo-client";
|
|
2
2
|
import { MessageRecipient, SendMessageResponse, TextMessage, ConsultationQuoteMessage } from "../types/message";
|
|
3
|
+
/**
|
|
4
|
+
* Interface cho từng tin nhắn trong chuỗi tin nhắn
|
|
5
|
+
*/
|
|
6
|
+
export interface MessageItem {
|
|
7
|
+
/** Loại tin nhắn */
|
|
8
|
+
type: "text" | "image" | "gif" | "file" | "sticker" | "request_user_info";
|
|
9
|
+
/** Nội dung tin nhắn (cho text message) */
|
|
10
|
+
text?: string;
|
|
11
|
+
/** URL hình ảnh (cho image/gif message) */
|
|
12
|
+
imageUrl?: string;
|
|
13
|
+
/** URL GIF (cho gif message) */
|
|
14
|
+
gifUrl?: string;
|
|
15
|
+
/** Chiều rộng GIF (bắt buộc cho gif) */
|
|
16
|
+
width?: number;
|
|
17
|
+
/** Chiều cao GIF (bắt buộc cho gif) */
|
|
18
|
+
height?: number;
|
|
19
|
+
/** Token file (cho file message) */
|
|
20
|
+
fileToken?: string;
|
|
21
|
+
/** Attachment ID (cho image/sticker message) */
|
|
22
|
+
attachmentId?: string;
|
|
23
|
+
/** Sticker attachment ID (cho sticker message) */
|
|
24
|
+
stickerAttachmentId?: string;
|
|
25
|
+
/** Tiêu đề (cho request_user_info message) */
|
|
26
|
+
title?: string;
|
|
27
|
+
/** Tiêu đề phụ (cho request_user_info message) */
|
|
28
|
+
subtitle?: string;
|
|
29
|
+
/** Delay sau khi gửi tin nhắn này (milliseconds) */
|
|
30
|
+
delay?: number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Interface cho request gửi chuỗi tin nhắn
|
|
34
|
+
*/
|
|
35
|
+
export interface SendMessageSequenceRequest {
|
|
36
|
+
/** Access token của Official Account */
|
|
37
|
+
accessToken: string;
|
|
38
|
+
/** ID người nhận */
|
|
39
|
+
userId: string;
|
|
40
|
+
/** Danh sách tin nhắn */
|
|
41
|
+
messages: MessageItem[];
|
|
42
|
+
/** Delay mặc định giữa các tin nhắn (milliseconds) - nếu không có delay riêng */
|
|
43
|
+
defaultDelay?: number;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Interface cho response gửi chuỗi tin nhắn
|
|
47
|
+
*/
|
|
48
|
+
export interface SendMessageSequenceResponse {
|
|
49
|
+
/** Tổng số tin nhắn đã gửi thành công */
|
|
50
|
+
successCount: number;
|
|
51
|
+
/** Tổng số tin nhắn thất bại */
|
|
52
|
+
failureCount: number;
|
|
53
|
+
/** Chi tiết kết quả từng tin nhắn */
|
|
54
|
+
results: Array<{
|
|
55
|
+
/** Index của tin nhắn trong danh sách */
|
|
56
|
+
index: number;
|
|
57
|
+
/** Loại tin nhắn */
|
|
58
|
+
type: string;
|
|
59
|
+
/** Trạng thái gửi */
|
|
60
|
+
success: boolean;
|
|
61
|
+
/** Thông tin response nếu thành công */
|
|
62
|
+
response?: SendMessageResponse;
|
|
63
|
+
/** Thông tin lỗi nếu thất bại */
|
|
64
|
+
error?: string;
|
|
65
|
+
/** Thời gian gửi */
|
|
66
|
+
timestamp: number;
|
|
67
|
+
}>;
|
|
68
|
+
/** Tổng thời gian thực hiện (milliseconds) */
|
|
69
|
+
totalDuration: number;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Interface cho request gửi chuỗi tin nhắn tới nhiều users
|
|
73
|
+
*/
|
|
74
|
+
export interface SendMessageSequenceToMultipleUsersRequest {
|
|
75
|
+
/** Access token của Official Account */
|
|
76
|
+
accessToken: string;
|
|
77
|
+
/** Danh sách user IDs */
|
|
78
|
+
userIds: string[];
|
|
79
|
+
/** Danh sách tin nhắn */
|
|
80
|
+
messages: MessageItem[];
|
|
81
|
+
/** Delay mặc định giữa các tin nhắn (milliseconds) */
|
|
82
|
+
defaultDelay?: number;
|
|
83
|
+
/** Delay giữa các user (milliseconds) để tránh rate limit */
|
|
84
|
+
delayBetweenUsers?: number;
|
|
85
|
+
/** Callback function để tracking tiến trình */
|
|
86
|
+
onProgress?: (progress: UserProgressInfo) => void;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Interface cho thông tin tiến trình từng user
|
|
90
|
+
*/
|
|
91
|
+
export interface UserProgressInfo {
|
|
92
|
+
/** User ID hiện tại */
|
|
93
|
+
userId: string;
|
|
94
|
+
/** Index của user trong danh sách (bắt đầu từ 0) */
|
|
95
|
+
userIndex: number;
|
|
96
|
+
/** Tổng số users */
|
|
97
|
+
totalUsers: number;
|
|
98
|
+
/** Trạng thái: 'started' | 'completed' | 'failed' */
|
|
99
|
+
status: 'started' | 'completed' | 'failed';
|
|
100
|
+
/** Kết quả gửi tin nhắn (nếu đã hoàn thành) */
|
|
101
|
+
result?: SendMessageSequenceResponse;
|
|
102
|
+
/** Thông tin lỗi (nếu thất bại) */
|
|
103
|
+
error?: string;
|
|
104
|
+
/** Thời gian bắt đầu */
|
|
105
|
+
startTime: number;
|
|
106
|
+
/** Thời gian kết thúc (nếu đã hoàn thành) */
|
|
107
|
+
endTime?: number;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Interface cho response gửi chuỗi tin nhắn tới nhiều users
|
|
111
|
+
*/
|
|
112
|
+
export interface SendMessageSequenceToMultipleUsersResponse {
|
|
113
|
+
/** Tổng số users */
|
|
114
|
+
totalUsers: number;
|
|
115
|
+
/** Số users gửi thành công */
|
|
116
|
+
successfulUsers: number;
|
|
117
|
+
/** Số users gửi thất bại */
|
|
118
|
+
failedUsers: number;
|
|
119
|
+
/** Chi tiết kết quả từng user */
|
|
120
|
+
userResults: Array<{
|
|
121
|
+
/** User ID */
|
|
122
|
+
userId: string;
|
|
123
|
+
/** Index của user trong danh sách */
|
|
124
|
+
userIndex: number;
|
|
125
|
+
/** Trạng thái gửi cho user này */
|
|
126
|
+
success: boolean;
|
|
127
|
+
/** Kết quả chi tiết gửi tin nhắn */
|
|
128
|
+
messageSequenceResult?: SendMessageSequenceResponse;
|
|
129
|
+
/** Thông tin lỗi nếu thất bại */
|
|
130
|
+
error?: string;
|
|
131
|
+
/** Thời gian bắt đầu gửi */
|
|
132
|
+
startTime: number;
|
|
133
|
+
/** Thời gian kết thúc */
|
|
134
|
+
endTime: number;
|
|
135
|
+
/** Thời gian thực hiện (milliseconds) */
|
|
136
|
+
duration: number;
|
|
137
|
+
}>;
|
|
138
|
+
/** Tổng thời gian thực hiện (milliseconds) */
|
|
139
|
+
totalDuration: number;
|
|
140
|
+
/** Thống kê tin nhắn tổng cộng */
|
|
141
|
+
messageStats: {
|
|
142
|
+
/** Tổng số tin nhắn đã gửi thành công */
|
|
143
|
+
totalSuccessfulMessages: number;
|
|
144
|
+
/** Tổng số tin nhắn thất bại */
|
|
145
|
+
totalFailedMessages: number;
|
|
146
|
+
/** Tổng số tin nhắn */
|
|
147
|
+
totalMessages: number;
|
|
148
|
+
};
|
|
149
|
+
}
|
|
3
150
|
/**
|
|
4
151
|
* Service xử lý các API tin nhắn tư vấn của Zalo Official Account
|
|
5
152
|
*
|
|
@@ -133,5 +280,25 @@ export declare class ConsultationService {
|
|
|
133
280
|
* Xem video hướng dẫn: https://vimeo.com/649330161
|
|
134
281
|
*/
|
|
135
282
|
sendStickerMessage(accessToken: string, userId: string, stickerAttachmentId: string): Promise<SendMessageResponse>;
|
|
283
|
+
/**
|
|
284
|
+
* Gửi chuỗi tin nhắn tư vấn với delay tùy chỉnh
|
|
285
|
+
* Hỗ trợ tất cả các loại tin nhắn: text, image, gif, file, sticker, request_user_info
|
|
286
|
+
*
|
|
287
|
+
* @param request Thông tin request gửi chuỗi tin nhắn
|
|
288
|
+
* @returns Kết quả gửi từng tin nhắn
|
|
289
|
+
*/
|
|
290
|
+
sendMessageSequence(request: SendMessageSequenceRequest): Promise<SendMessageSequenceResponse>;
|
|
291
|
+
/**
|
|
292
|
+
* Gửi chuỗi tin nhắn tư vấn tới nhiều users với callback tracking
|
|
293
|
+
*
|
|
294
|
+
* @param request Thông tin request gửi chuỗi tin nhắn tới nhiều users
|
|
295
|
+
* @returns Kết quả gửi tin nhắn cho tất cả users
|
|
296
|
+
*/
|
|
297
|
+
sendMessageSequenceToMultipleUsers(request: SendMessageSequenceToMultipleUsersRequest): Promise<SendMessageSequenceToMultipleUsersResponse>;
|
|
298
|
+
/**
|
|
299
|
+
* Utility method để sleep/delay
|
|
300
|
+
* @param ms Thời gian delay tính bằng milliseconds
|
|
301
|
+
*/
|
|
302
|
+
private sleep;
|
|
136
303
|
}
|
|
137
304
|
//# sourceMappingURL=consultation.service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consultation.service.d.ts","sourceRoot":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M,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,IAAI,CAAC,EAAE,MAAM,GACZ,OAAO,CAAC,mBAAmB,CAAC;IAqE/B;;;;;;;;;;;OAWG;IACU,eAAe,CAC1B,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,mBAAmB,CAAC;IAiD/B;;;;;;;;;;;OAWG;IACU,0BAA0B,CACrC,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,mBAAmB,CAAC;IAyE/B;;;;;;;;;;;;OAYG;IACU,kBAAkB,CAC7B,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,MAAM,EACd,mBAAmB,EAAE,MAAM,GAC1B,OAAO,CAAC,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"consultation.service.d.ts","sourceRoot":"","sources":["../../src/services/consultation.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EACnB,WAAW,EACX,wBAAwB,EACzB,MAAM,kBAAkB,CAAC;AAG1B;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,oBAAoB;IACpB,IAAI,EAAE,MAAM,GAAG,OAAO,GAAG,KAAK,GAAG,MAAM,GAAG,SAAS,GAAG,mBAAmB,CAAC;IAC1E,2CAA2C;IAC3C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,2CAA2C;IAC3C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,gCAAgC;IAChC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,wCAAwC;IACxC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,uCAAuC;IACvC,MAAM,CAAC,EAAE,MAAM,CAAC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;;;;;;;;;;;;OAYG;IACU,cAAc,CACzB,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,IAAI,CAAC,EAAE,MAAM,GACZ,OAAO,CAAC,mBAAmB,CAAC;IAqE/B;;;;;;;;;;;OAWG;IACU,eAAe,CAC1B,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,mBAAmB,CAAC;IAiD/B;;;;;;;;;;;OAWG;IACU,0BAA0B,CACrC,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,mBAAmB,CAAC;IAyE/B;;;;;;;;;;;;OAYG;IACU,kBAAkB,CAC7B,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,MAAM,EACd,mBAAmB,EAAE,MAAM,GAC1B,OAAO,CAAC,mBAAmB,CAAC;IAyD/B;;;;;;OAMG;IACU,mBAAmB,CAC9B,OAAO,EAAE,0BAA0B,GAClC,OAAO,CAAC,2BAA2B,CAAC;IA4KvC;;;;;OAKG;IACU,kCAAkC,CAC7C,OAAO,EAAE,yCAAyC,GACjD,OAAO,CAAC,0CAA0C,CAAC;IAqKtD;;;OAGG;IACH,OAAO,CAAC,KAAK;CAGd"}
|
|
@@ -484,6 +484,280 @@ class ConsultationService {
|
|
|
484
484
|
throw new common_1.ZaloSDKError(`Failed to send consultation sticker message: ${error.message}`, -1, error);
|
|
485
485
|
}
|
|
486
486
|
}
|
|
487
|
+
/**
|
|
488
|
+
* Gửi chuỗi tin nhắn tư vấn với delay tùy chỉnh
|
|
489
|
+
* Hỗ trợ tất cả các loại tin nhắn: text, image, gif, file, sticker, request_user_info
|
|
490
|
+
*
|
|
491
|
+
* @param request Thông tin request gửi chuỗi tin nhắn
|
|
492
|
+
* @returns Kết quả gửi từng tin nhắn
|
|
493
|
+
*/
|
|
494
|
+
async sendMessageSequence(request) {
|
|
495
|
+
const startTime = Date.now();
|
|
496
|
+
const results = [];
|
|
497
|
+
let successCount = 0;
|
|
498
|
+
let failureCount = 0;
|
|
499
|
+
try {
|
|
500
|
+
// Validate input
|
|
501
|
+
if (!request.accessToken || request.accessToken.trim().length === 0) {
|
|
502
|
+
throw new common_1.ZaloSDKError("Access token không được để trống", -1);
|
|
503
|
+
}
|
|
504
|
+
if (!request.userId || request.userId.trim().length === 0) {
|
|
505
|
+
throw new common_1.ZaloSDKError("User ID không được để trống", -1);
|
|
506
|
+
}
|
|
507
|
+
if (!request.messages || request.messages.length === 0) {
|
|
508
|
+
throw new common_1.ZaloSDKError("Danh sách tin nhắn không được để trống", -1);
|
|
509
|
+
}
|
|
510
|
+
// Gửi từng tin nhắn theo thứ tự
|
|
511
|
+
for (let i = 0; i < request.messages.length; i++) {
|
|
512
|
+
const message = request.messages[i];
|
|
513
|
+
const messageResult = {
|
|
514
|
+
index: i,
|
|
515
|
+
type: message.type,
|
|
516
|
+
success: false,
|
|
517
|
+
timestamp: Date.now(),
|
|
518
|
+
};
|
|
519
|
+
try {
|
|
520
|
+
let response;
|
|
521
|
+
// Gửi tin nhắn theo loại
|
|
522
|
+
switch (message.type) {
|
|
523
|
+
case "text":
|
|
524
|
+
if (!message.text) {
|
|
525
|
+
throw new Error("Text không được để trống cho text message");
|
|
526
|
+
}
|
|
527
|
+
response = await this.sendTextMessage(request.accessToken, { user_id: request.userId }, { type: "text", text: message.text });
|
|
528
|
+
break;
|
|
529
|
+
case "image":
|
|
530
|
+
if (message.imageUrl) {
|
|
531
|
+
response = await this.sendImageMessage(request.accessToken, request.userId, message.imageUrl, message.text);
|
|
532
|
+
}
|
|
533
|
+
else if (message.attachmentId) {
|
|
534
|
+
response = await this.sendImageByAttachmentId(request.accessToken, request.userId, message.attachmentId, message.text);
|
|
535
|
+
}
|
|
536
|
+
else {
|
|
537
|
+
throw new Error("imageUrl hoặc attachmentId là bắt buộc cho image message");
|
|
538
|
+
}
|
|
539
|
+
break;
|
|
540
|
+
case "gif":
|
|
541
|
+
if (!message.gifUrl || !message.width || !message.height) {
|
|
542
|
+
throw new Error("gifUrl, width và height là bắt buộc cho gif message");
|
|
543
|
+
}
|
|
544
|
+
response = await this.sendGifMessage(request.accessToken, request.userId, message.gifUrl, message.width, message.height, message.text);
|
|
545
|
+
break;
|
|
546
|
+
case "file":
|
|
547
|
+
if (!message.fileToken) {
|
|
548
|
+
throw new Error("fileToken là bắt buộc cho file message");
|
|
549
|
+
}
|
|
550
|
+
response = await this.sendFileMessage(request.accessToken, request.userId, message.fileToken);
|
|
551
|
+
break;
|
|
552
|
+
case "sticker":
|
|
553
|
+
if (!message.stickerAttachmentId) {
|
|
554
|
+
throw new Error("stickerAttachmentId là bắt buộc cho sticker message");
|
|
555
|
+
}
|
|
556
|
+
response = await this.sendStickerMessage(request.accessToken, request.userId, message.stickerAttachmentId);
|
|
557
|
+
break;
|
|
558
|
+
case "request_user_info":
|
|
559
|
+
if (!message.title || !message.subtitle || !message.imageUrl) {
|
|
560
|
+
throw new Error("title, subtitle và imageUrl là bắt buộc cho request_user_info message");
|
|
561
|
+
}
|
|
562
|
+
response = await this.sendRequestUserInfoMessage(request.accessToken, request.userId, message.title, message.subtitle, message.imageUrl);
|
|
563
|
+
break;
|
|
564
|
+
default:
|
|
565
|
+
throw new Error(`Loại tin nhắn không được hỗ trợ: ${message.type}`);
|
|
566
|
+
}
|
|
567
|
+
// Ghi nhận thành công
|
|
568
|
+
messageResult.success = true;
|
|
569
|
+
messageResult.response = response;
|
|
570
|
+
successCount++;
|
|
571
|
+
}
|
|
572
|
+
catch (error) {
|
|
573
|
+
// Ghi nhận thất bại
|
|
574
|
+
messageResult.success = false;
|
|
575
|
+
messageResult.error = error instanceof Error ? error.message : String(error);
|
|
576
|
+
failureCount++;
|
|
577
|
+
}
|
|
578
|
+
results.push(messageResult);
|
|
579
|
+
// Delay trước khi gửi tin nhắn tiếp theo (trừ tin nhắn cuối cùng)
|
|
580
|
+
if (i < request.messages.length - 1) {
|
|
581
|
+
const delayTime = message.delay ?? request.defaultDelay ?? 0;
|
|
582
|
+
if (delayTime > 0) {
|
|
583
|
+
await this.sleep(delayTime);
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
const totalDuration = Date.now() - startTime;
|
|
588
|
+
return {
|
|
589
|
+
successCount,
|
|
590
|
+
failureCount,
|
|
591
|
+
results,
|
|
592
|
+
totalDuration,
|
|
593
|
+
};
|
|
594
|
+
}
|
|
595
|
+
catch (error) {
|
|
596
|
+
// Lỗi tổng quát
|
|
597
|
+
const totalDuration = Date.now() - startTime;
|
|
598
|
+
if (error instanceof common_1.ZaloSDKError) {
|
|
599
|
+
throw error;
|
|
600
|
+
}
|
|
601
|
+
throw new common_1.ZaloSDKError(`Failed to send message sequence: ${error.message}`, -1, {
|
|
602
|
+
successCount,
|
|
603
|
+
failureCount,
|
|
604
|
+
results,
|
|
605
|
+
totalDuration,
|
|
606
|
+
});
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
/**
|
|
610
|
+
* Gửi chuỗi tin nhắn tư vấn tới nhiều users với callback tracking
|
|
611
|
+
*
|
|
612
|
+
* @param request Thông tin request gửi chuỗi tin nhắn tới nhiều users
|
|
613
|
+
* @returns Kết quả gửi tin nhắn cho tất cả users
|
|
614
|
+
*/
|
|
615
|
+
async sendMessageSequenceToMultipleUsers(request) {
|
|
616
|
+
const startTime = Date.now();
|
|
617
|
+
const userResults = [];
|
|
618
|
+
let successfulUsers = 0;
|
|
619
|
+
let failedUsers = 0;
|
|
620
|
+
let totalSuccessfulMessages = 0;
|
|
621
|
+
let totalFailedMessages = 0;
|
|
622
|
+
try {
|
|
623
|
+
// Validate input
|
|
624
|
+
if (!request.accessToken || request.accessToken.trim().length === 0) {
|
|
625
|
+
throw new common_1.ZaloSDKError("Access token không được để trống", -1);
|
|
626
|
+
}
|
|
627
|
+
if (!request.userIds || request.userIds.length === 0) {
|
|
628
|
+
throw new common_1.ZaloSDKError("Danh sách user IDs không được để trống", -1);
|
|
629
|
+
}
|
|
630
|
+
if (!request.messages || request.messages.length === 0) {
|
|
631
|
+
throw new common_1.ZaloSDKError("Danh sách tin nhắn không được để trống", -1);
|
|
632
|
+
}
|
|
633
|
+
// Loại bỏ user IDs trùng lặp và rỗng
|
|
634
|
+
const uniqueUserIds = [...new Set(request.userIds.filter(id => id && id.trim().length > 0))];
|
|
635
|
+
if (uniqueUserIds.length === 0) {
|
|
636
|
+
throw new common_1.ZaloSDKError("Không có user ID hợp lệ nào", -1);
|
|
637
|
+
}
|
|
638
|
+
// Gửi tin nhắn cho từng user tuần tự
|
|
639
|
+
for (let i = 0; i < uniqueUserIds.length; i++) {
|
|
640
|
+
const userId = uniqueUserIds[i];
|
|
641
|
+
const userStartTime = Date.now();
|
|
642
|
+
// Callback: Bắt đầu gửi cho user
|
|
643
|
+
if (request.onProgress) {
|
|
644
|
+
request.onProgress({
|
|
645
|
+
userId,
|
|
646
|
+
userIndex: i,
|
|
647
|
+
totalUsers: uniqueUserIds.length,
|
|
648
|
+
status: 'started',
|
|
649
|
+
startTime: userStartTime,
|
|
650
|
+
});
|
|
651
|
+
}
|
|
652
|
+
const userResult = {
|
|
653
|
+
userId,
|
|
654
|
+
userIndex: i,
|
|
655
|
+
success: false,
|
|
656
|
+
startTime: userStartTime,
|
|
657
|
+
endTime: 0,
|
|
658
|
+
duration: 0,
|
|
659
|
+
};
|
|
660
|
+
try {
|
|
661
|
+
// Gửi chuỗi tin nhắn cho user này
|
|
662
|
+
const messageSequenceResult = await this.sendMessageSequence({
|
|
663
|
+
accessToken: request.accessToken,
|
|
664
|
+
userId,
|
|
665
|
+
messages: request.messages,
|
|
666
|
+
defaultDelay: request.defaultDelay,
|
|
667
|
+
});
|
|
668
|
+
// Ghi nhận thành công
|
|
669
|
+
const userEndTime = Date.now();
|
|
670
|
+
userResult.success = true;
|
|
671
|
+
userResult.messageSequenceResult = messageSequenceResult;
|
|
672
|
+
userResult.endTime = userEndTime;
|
|
673
|
+
userResult.duration = userEndTime - userStartTime;
|
|
674
|
+
successfulUsers++;
|
|
675
|
+
totalSuccessfulMessages += messageSequenceResult.successCount;
|
|
676
|
+
totalFailedMessages += messageSequenceResult.failureCount;
|
|
677
|
+
// Callback: Hoàn thành thành công
|
|
678
|
+
if (request.onProgress) {
|
|
679
|
+
request.onProgress({
|
|
680
|
+
userId,
|
|
681
|
+
userIndex: i,
|
|
682
|
+
totalUsers: uniqueUserIds.length,
|
|
683
|
+
status: 'completed',
|
|
684
|
+
result: messageSequenceResult,
|
|
685
|
+
startTime: userStartTime,
|
|
686
|
+
endTime: userEndTime,
|
|
687
|
+
});
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
catch (error) {
|
|
691
|
+
// Ghi nhận thất bại
|
|
692
|
+
const userEndTime = Date.now();
|
|
693
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
694
|
+
userResult.success = false;
|
|
695
|
+
userResult.error = errorMessage;
|
|
696
|
+
userResult.endTime = userEndTime;
|
|
697
|
+
userResult.duration = userEndTime - userStartTime;
|
|
698
|
+
failedUsers++;
|
|
699
|
+
// Với user thất bại, coi như tất cả tin nhắn đều thất bại
|
|
700
|
+
totalFailedMessages += request.messages.length;
|
|
701
|
+
// Callback: Thất bại
|
|
702
|
+
if (request.onProgress) {
|
|
703
|
+
request.onProgress({
|
|
704
|
+
userId,
|
|
705
|
+
userIndex: i,
|
|
706
|
+
totalUsers: uniqueUserIds.length,
|
|
707
|
+
status: 'failed',
|
|
708
|
+
error: errorMessage,
|
|
709
|
+
startTime: userStartTime,
|
|
710
|
+
endTime: userEndTime,
|
|
711
|
+
});
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
userResults.push(userResult);
|
|
715
|
+
// Delay giữa các user (trừ user cuối cùng)
|
|
716
|
+
if (i < uniqueUserIds.length - 1 && request.delayBetweenUsers && request.delayBetweenUsers > 0) {
|
|
717
|
+
await this.sleep(request.delayBetweenUsers);
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
const totalDuration = Date.now() - startTime;
|
|
721
|
+
const totalMessages = uniqueUserIds.length * request.messages.length;
|
|
722
|
+
return {
|
|
723
|
+
totalUsers: uniqueUserIds.length,
|
|
724
|
+
successfulUsers,
|
|
725
|
+
failedUsers,
|
|
726
|
+
userResults,
|
|
727
|
+
totalDuration,
|
|
728
|
+
messageStats: {
|
|
729
|
+
totalSuccessfulMessages,
|
|
730
|
+
totalFailedMessages,
|
|
731
|
+
totalMessages,
|
|
732
|
+
},
|
|
733
|
+
};
|
|
734
|
+
}
|
|
735
|
+
catch (error) {
|
|
736
|
+
const totalDuration = Date.now() - startTime;
|
|
737
|
+
if (error instanceof common_1.ZaloSDKError) {
|
|
738
|
+
throw error;
|
|
739
|
+
}
|
|
740
|
+
throw new common_1.ZaloSDKError(`Failed to send message sequence to multiple users: ${error.message}`, -1, {
|
|
741
|
+
totalUsers: request.userIds?.length || 0,
|
|
742
|
+
successfulUsers,
|
|
743
|
+
failedUsers,
|
|
744
|
+
userResults,
|
|
745
|
+
totalDuration,
|
|
746
|
+
messageStats: {
|
|
747
|
+
totalSuccessfulMessages,
|
|
748
|
+
totalFailedMessages,
|
|
749
|
+
totalMessages: (request.userIds?.length || 0) * (request.messages?.length || 0),
|
|
750
|
+
},
|
|
751
|
+
});
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
/**
|
|
755
|
+
* Utility method để sleep/delay
|
|
756
|
+
* @param ms Thời gian delay tính bằng milliseconds
|
|
757
|
+
*/
|
|
758
|
+
sleep(ms) {
|
|
759
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
760
|
+
}
|
|
487
761
|
}
|
|
488
762
|
exports.ConsultationService = ConsultationService;
|
|
489
763
|
//# sourceMappingURL=consultation.service.js.map
|