@warriorteam/redai-zalo-sdk 1.12.2 → 1.12.5
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 +65 -0
- package/README.md +33 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -2
- package/dist/index.js.map +1 -1
- package/dist/services/group-management.service.d.ts +75 -2
- package/dist/services/group-management.service.d.ts.map +1 -1
- package/dist/services/group-management.service.js +315 -1
- package/dist/services/group-management.service.js.map +1 -1
- package/dist/services/oa.service.d.ts +6 -4
- package/dist/services/oa.service.d.ts.map +1 -1
- package/dist/services/oa.service.js +36 -23
- package/dist/services/oa.service.js.map +1 -1
- package/dist/types/group.d.ts +104 -0
- package/dist/types/group.d.ts.map +1 -1
- package/dist/types/webhook.d.ts +24 -0
- package/dist/types/webhook.d.ts.map +1 -1
- package/dist/types/webhook.js +110 -0
- package/dist/types/webhook.js.map +1 -1
- package/docs/AUTHENTICATION.md +4 -3
- package/docs/WEBHOOK_MESSAGE_HELPERS.md +230 -0
- package/examples/oa-auth-with-pkce.ts +3 -3
- package/examples/webhook-message-classification.ts +285 -0
- package/package.json +1 -1
- package/ARCHITECTURE.md +0 -265
- package/SERVICES_ADDED.md +0 -540
- package/UPDATE_ARTICLE_STATUS.md +0 -152
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,71 @@ 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.12.1] - 2025-01-17
|
|
9
|
+
|
|
10
|
+
### 🔧 MAINTENANCE
|
|
11
|
+
|
|
12
|
+
- **Cập nhật**: Tối ưu tài liệu, ví dụ và xuất bản bản vá nhỏ.
|
|
13
|
+
- **Cải thiện**: Đồng bộ hoá typings và mô tả package để phát hành ổn định.
|
|
14
|
+
- **Build**: Đảm bảo `prepublishOnly` chạy `clean` + `build` trước khi publish.
|
|
15
|
+
|
|
16
|
+
## [1.12.0] - 2025-01-17
|
|
17
|
+
|
|
18
|
+
### 🎯 NEW FEATURES
|
|
19
|
+
|
|
20
|
+
#### Webhook Message Classification Helpers
|
|
21
|
+
- **ADDED**: `isUserMessageEvent()` - Phân biệt tin nhắn từ người dùng cá nhân gửi tới OA
|
|
22
|
+
- **ADDED**: `isGroupMessageEvent()` - Phân biệt tin nhắn từ người dùng trong group
|
|
23
|
+
- **ADDED**: `isOAToUserMessageEvent()` - Phân biệt tin nhắn OA gửi cho người dùng cá nhân
|
|
24
|
+
- **ADDED**: `isOAToGroupMessageEvent()` - Phân biệt tin nhắn OA gửi tới group
|
|
25
|
+
- **ADDED**: `getMessageDirection()` - Xác định hướng và đích của tin nhắn với mô tả chi tiết
|
|
26
|
+
|
|
27
|
+
#### Enhanced Type Safety
|
|
28
|
+
- **IMPROVED**: Better type guards cho webhook message classification
|
|
29
|
+
- **ENHANCED**: Comprehensive support cho 38+ message event types
|
|
30
|
+
- **ADDED**: Direction và target classification với Vietnamese descriptions
|
|
31
|
+
|
|
32
|
+
### 📚 DOCUMENTATION
|
|
33
|
+
|
|
34
|
+
#### New Documentation Files
|
|
35
|
+
- **ADDED**: `docs/WEBHOOK_MESSAGE_HELPERS.md` - Comprehensive guide cho message classification
|
|
36
|
+
- **ADDED**: `examples/webhook-message-classification.ts` - Practical usage examples
|
|
37
|
+
- **UPDATED**: README.md với message classification helpers section
|
|
38
|
+
|
|
39
|
+
#### Developer Experience
|
|
40
|
+
- **ENHANCED**: IntelliSense support với detailed JSDoc comments
|
|
41
|
+
- **ADDED**: 13 comprehensive test cases cho message classification helpers
|
|
42
|
+
- **IMPROVED**: Better error handling và unknown event detection
|
|
43
|
+
|
|
44
|
+
### 🔧 TECHNICAL IMPROVEMENTS
|
|
45
|
+
|
|
46
|
+
#### Code Organization
|
|
47
|
+
- **ENHANCED**: Exported helper functions từ main index.ts
|
|
48
|
+
- **IMPROVED**: Type safety với proper TypeScript interfaces
|
|
49
|
+
- **ADDED**: Comprehensive test coverage cho all helper functions
|
|
50
|
+
|
|
51
|
+
#### Supported Event Types
|
|
52
|
+
- **User Message Events** (12 types): `user_send_text`, `user_send_image`, etc.
|
|
53
|
+
- **Group Message Events** (9 types): `user_send_group_text`, `user_send_group_image`, etc.
|
|
54
|
+
- **OA to User Events** (7 types): `oa_send_text`, `oa_send_image`, etc.
|
|
55
|
+
- **OA to Group Events** (10 types): `oa_send_group_text`, `oa_send_group_image`, etc.
|
|
56
|
+
|
|
57
|
+
## [1.11.1] - 2025-01-11
|
|
58
|
+
|
|
59
|
+
### 🔧 API IMPROVEMENTS
|
|
60
|
+
|
|
61
|
+
#### Method Signature Enhancement
|
|
62
|
+
- **IMPROVED**: `createOAAuthUrl()` method signature với better parameter order
|
|
63
|
+
- Changed from: `(redirectUri, state?, usePkce?, pkce?)`
|
|
64
|
+
- Changed to: `(redirectUri, state?, pkce?, usePkce?)`
|
|
65
|
+
- **ENHANCED**: More intuitive API design với PKCE config trước usePkce flag
|
|
66
|
+
- **UPDATED**: All examples và documentation để phù hợp với signature mới
|
|
67
|
+
- **ADDED**: Comprehensive test coverage cho new signature
|
|
68
|
+
|
|
69
|
+
#### Developer Experience
|
|
70
|
+
- **IMPROVED**: Better IntelliSense support với clearer parameter ordering
|
|
71
|
+
- **ENHANCED**: More logical API flow cho PKCE implementation
|
|
72
|
+
|
|
8
73
|
## [1.11.0] - 2025-01-11
|
|
9
74
|
|
|
10
75
|
### 🔐 SECURITY ENHANCEMENTS
|
package/README.md
CHANGED
|
@@ -584,7 +584,39 @@ const handlers: WebhookHandlers = {
|
|
|
584
584
|
- **Anonymous Events** (4 types): Anonymous chat support
|
|
585
585
|
- **Shop Events** (1 type): Order management
|
|
586
586
|
|
|
587
|
-
|
|
587
|
+
### 🎯 Message Classification Helpers
|
|
588
|
+
|
|
589
|
+
The SDK provides helper functions to easily classify webhook message events:
|
|
590
|
+
|
|
591
|
+
```typescript
|
|
592
|
+
import {
|
|
593
|
+
isUserMessageEvent,
|
|
594
|
+
isGroupMessageEvent,
|
|
595
|
+
isOAToUserMessageEvent,
|
|
596
|
+
isOAToGroupMessageEvent,
|
|
597
|
+
getMessageDirection,
|
|
598
|
+
} from "@warriorteam/redai-zalo-sdk";
|
|
599
|
+
|
|
600
|
+
function handleWebhook(event: WebhookEvent) {
|
|
601
|
+
if (isUserMessageEvent(event)) {
|
|
602
|
+
console.log("Message from individual user");
|
|
603
|
+
} else if (isGroupMessageEvent(event)) {
|
|
604
|
+
console.log("Message from group");
|
|
605
|
+
} else if (isOAToUserMessageEvent(event)) {
|
|
606
|
+
console.log("OA sent message to user");
|
|
607
|
+
} else if (isOAToGroupMessageEvent(event)) {
|
|
608
|
+
console.log("OA sent message to group");
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
// Or use the unified helper
|
|
612
|
+
const { direction, target, description } = getMessageDirection(event);
|
|
613
|
+
console.log(`${direction} message to ${target}: ${description}`);
|
|
614
|
+
}
|
|
615
|
+
```
|
|
616
|
+
|
|
617
|
+
For complete webhook documentation, see:
|
|
618
|
+
- **[Webhook Events Guide](./docs/WEBHOOK_EVENTS.md)** - Complete guide for all 70+ webhook event types
|
|
619
|
+
- **[Message Classification Helpers](./docs/WEBHOOK_MESSAGE_HELPERS.md)** - Helper functions for message classification
|
|
588
620
|
|
|
589
621
|
## Changelog
|
|
590
622
|
|
package/dist/index.d.ts
CHANGED
|
@@ -17,8 +17,9 @@ export * from "./types/article";
|
|
|
17
17
|
export * from "./constants/zns.constants";
|
|
18
18
|
export type { BaseMessage, TextMessage, ImageMessage, FileMessage, StickerMessage, TemplateMessage as MessageTemplateMessage, ReactionMessage as MessageReactionMessage, Message, MessageRecipient, SendMessageRequest, SendMessageResponse, UploadFileResponse, MessageStatus, MessageEvent, ConsultationTextMessage, ConsultationImageMessage, ConsultationFileMessage, ConsultationStickerMessage, ConsultationQuoteMessage, ConsultationRequestInfoMessage, TransactionMessage, PromotionMessage, AnonymousTextMessage, AnonymousImageMessage, AnonymousFileMessage, AnonymousStickerMessage, MiniAppMessage, ExtendedMessage, } from "./types/message";
|
|
19
19
|
export * from "./types/webhook";
|
|
20
|
-
export { UserGroupMessageEvent, isUserSendGroupTextEvent, isUserSendGroupImageEvent, isUserSendGroupVideoEvent, isUserSendGroupAudioEvent, isUserSendGroupFileEvent, isUserGroupMessageEvent, isOASendTextEvent, isOASendImageEvent, isOASendFileEvent, isOASendStickerEvent, isOASendGifEvent, isOASendGroupTextEvent, isOASendGroupImageEvent, isOASendGroupFileEvent, isOASendGroupStickerEvent, isOASendGroupGifEvent,
|
|
21
|
-
export
|
|
20
|
+
export { UserGroupMessageEvent, isUserSendGroupTextEvent, isUserSendGroupImageEvent, isUserSendGroupVideoEvent, isUserSendGroupAudioEvent, isUserSendGroupFileEvent, isUserGroupMessageEvent, isOASendTextEvent, isOASendImageEvent, isOASendFileEvent, isOASendStickerEvent, isOASendGifEvent, isOASendGroupTextEvent, isOASendGroupImageEvent, isOASendGroupFileEvent, isOASendGroupStickerEvent, isOASendGroupGifEvent, isFromGroup, isFromPersonal, } from "./utils/type-guards";
|
|
21
|
+
export { isUserMessageEvent, isGroupMessageEvent, isOAToUserMessageEvent, isOAToGroupMessageEvent, getMessageDirection, } from "./types/webhook";
|
|
22
|
+
export type { GroupMessage, GroupTextMessage, GroupImageMessage, GroupFileMessage, GroupStickerMessage, GroupMentionMessage, GroupMessageResult, GroupInfo as GroupManagementInfo, GroupMember, GroupMemberList, GroupSettings, GroupJoinRequest, GroupJoinRequestList, GroupInvitation, GroupActivity, GroupActivityList, GroupStatistics, GroupMessageTemplate, GroupMessageSchedule, GroupBroadcast, GroupPermission, GroupWebhookEvent as GroupManagementWebhookEvent, GroupApiResponse, GroupCreateResponse, GroupUpdateResponse, GroupDeleteResponse, GroupMemberActionResponse, GroupCreateRequest, GroupCreateResult, GroupUpdateRequest, GroupAvatarUpdateRequest, GroupMemberInviteRequest, GroupMemberActionRequest, GroupAdminActionRequest, GroupDeleteRequest, GroupPendingMember, GroupQuota, GroupQuotaAsset, GroupRecentChat, GroupConversationMessage, GroupsOfOAResponse, GroupDetailResponse, GroupPendingMembersResponse, GroupAcceptPendingMembersRequest, GroupAcceptPendingMembersResponse, GroupRemoveMembersRequest, GroupRemoveMembersResponse, GroupMembersResponse, GroupQuotaMessageRequest, GroupQuotaMessageResponse, AllGroupMembersResponse, GetAllMembersProgress, EnhancedGroupMember, AllGroupMembersWithDetailsResponse, GetAllMembersWithDetailsProgress, } from "./types/group";
|
|
22
23
|
export type { UserProfile as UserManagementProfile, UserList as UserManagementList, UserTag, UserTagList, UserNote, UserInteraction, UserAnalytics, UserSegment, UserCustomField, UserCustomFieldValue, UserBehavior, UserJourney, UserPreference, UserActivity, UserExport, UserImport, UserSearch, UserSearchResult, BulkUserOperation, } from "./types/user-management";
|
|
23
24
|
export { BaseClient } from "./clients/base-client";
|
|
24
25
|
export { ZaloClient } from "./clients/zalo-client";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAGhC,cAAc,2BAA2B,CAAC;AAG1C,YAAY,EACV,WAAW,EACX,WAAW,EACX,YAAY,EACZ,WAAW,EACX,cAAc,EACd,eAAe,IAAI,sBAAsB,EACzC,eAAe,IAAI,sBAAsB,EACzC,OAAO,EACP,gBAAgB,EAChB,kBAAkB,EAClB,mBAAmB,EACnB,kBAAkB,EAClB,aAAa,EACb,YAAY,EACZ,uBAAuB,EACvB,wBAAwB,EACxB,uBAAuB,EACvB,0BAA0B,EAC1B,wBAAwB,EACxB,8BAA8B,EAC9B,kBAAkB,EAClB,gBAAgB,EAChB,oBAAoB,EACpB,qBAAqB,EACrB,oBAAoB,EACpB,uBAAuB,EACvB,cAAc,EACd,eAAe,GAChB,MAAM,iBAAiB,CAAC;AAGzB,cAAc,iBAAiB,CAAC;AAGhC,OAAO,EACL,qBAAqB,EACrB,wBAAwB,EACxB,yBAAyB,EACzB,yBAAyB,EACzB,yBAAyB,EACzB,wBAAwB,EACxB,uBAAuB,EACvB,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EACjB,oBAAoB,EACpB,gBAAgB,EAChB,sBAAsB,EACtB,uBAAuB,EACvB,sBAAsB,EACtB,yBAAyB,EACzB,qBAAqB,EACrB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAGhC,cAAc,2BAA2B,CAAC;AAG1C,YAAY,EACV,WAAW,EACX,WAAW,EACX,YAAY,EACZ,WAAW,EACX,cAAc,EACd,eAAe,IAAI,sBAAsB,EACzC,eAAe,IAAI,sBAAsB,EACzC,OAAO,EACP,gBAAgB,EAChB,kBAAkB,EAClB,mBAAmB,EACnB,kBAAkB,EAClB,aAAa,EACb,YAAY,EACZ,uBAAuB,EACvB,wBAAwB,EACxB,uBAAuB,EACvB,0BAA0B,EAC1B,wBAAwB,EACxB,8BAA8B,EAC9B,kBAAkB,EAClB,gBAAgB,EAChB,oBAAoB,EACpB,qBAAqB,EACrB,oBAAoB,EACpB,uBAAuB,EACvB,cAAc,EACd,eAAe,GAChB,MAAM,iBAAiB,CAAC;AAGzB,cAAc,iBAAiB,CAAC;AAGhC,OAAO,EACL,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AAE,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -24,7 +24,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
24
24
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
25
25
|
};
|
|
26
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
-
exports.default = exports.ZaloSDK = exports.MessageManagementService = exports.GeneralMessageService = exports.PromotionService = exports.TransactionService = exports.ConsultationService = exports.VideoUploadService = exports.ArticleService = exports.GroupManagementService = exports.GroupMessageService = exports.ZNSService = exports.UserService = exports.OAService = exports.AuthService = exports.ZaloClient = exports.BaseClient = exports.
|
|
27
|
+
exports.default = exports.ZaloSDK = exports.MessageManagementService = exports.GeneralMessageService = exports.PromotionService = exports.TransactionService = exports.ConsultationService = exports.VideoUploadService = exports.ArticleService = exports.GroupManagementService = exports.GroupMessageService = exports.ZNSService = exports.UserService = exports.OAService = exports.AuthService = exports.ZaloClient = exports.BaseClient = exports.getMessageDirection = exports.isOAToGroupMessageEvent = exports.isOAToUserMessageEvent = exports.isGroupMessageEvent = exports.isUserMessageEvent = exports.isFromPersonal = exports.isFromGroup = exports.isOASendGroupGifEvent = exports.isOASendGroupStickerEvent = exports.isOASendGroupFileEvent = exports.isOASendGroupImageEvent = exports.isOASendGroupTextEvent = exports.isOASendGifEvent = exports.isOASendStickerEvent = exports.isOASendFileEvent = exports.isOASendImageEvent = exports.isOASendTextEvent = exports.isUserGroupMessageEvent = exports.isUserSendGroupFileEvent = exports.isUserSendGroupAudioEvent = exports.isUserSendGroupVideoEvent = exports.isUserSendGroupImageEvent = exports.isUserSendGroupTextEvent = void 0;
|
|
28
28
|
// Export types
|
|
29
29
|
__exportStar(require("./types/common"), exports);
|
|
30
30
|
__exportStar(require("./types/auth"), exports);
|
|
@@ -54,9 +54,15 @@ Object.defineProperty(exports, "isOASendGroupImageEvent", { enumerable: true, ge
|
|
|
54
54
|
Object.defineProperty(exports, "isOASendGroupFileEvent", { enumerable: true, get: function () { return type_guards_1.isOASendGroupFileEvent; } });
|
|
55
55
|
Object.defineProperty(exports, "isOASendGroupStickerEvent", { enumerable: true, get: function () { return type_guards_1.isOASendGroupStickerEvent; } });
|
|
56
56
|
Object.defineProperty(exports, "isOASendGroupGifEvent", { enumerable: true, get: function () { return type_guards_1.isOASendGroupGifEvent; } });
|
|
57
|
-
Object.defineProperty(exports, "isUserMessageEvent", { enumerable: true, get: function () { return type_guards_1.isUserMessageEvent; } });
|
|
58
57
|
Object.defineProperty(exports, "isFromGroup", { enumerable: true, get: function () { return type_guards_1.isFromGroup; } });
|
|
59
58
|
Object.defineProperty(exports, "isFromPersonal", { enumerable: true, get: function () { return type_guards_1.isFromPersonal; } });
|
|
59
|
+
// Export webhook helper functions
|
|
60
|
+
var webhook_1 = require("./types/webhook");
|
|
61
|
+
Object.defineProperty(exports, "isUserMessageEvent", { enumerable: true, get: function () { return webhook_1.isUserMessageEvent; } });
|
|
62
|
+
Object.defineProperty(exports, "isGroupMessageEvent", { enumerable: true, get: function () { return webhook_1.isGroupMessageEvent; } });
|
|
63
|
+
Object.defineProperty(exports, "isOAToUserMessageEvent", { enumerable: true, get: function () { return webhook_1.isOAToUserMessageEvent; } });
|
|
64
|
+
Object.defineProperty(exports, "isOAToGroupMessageEvent", { enumerable: true, get: function () { return webhook_1.isOAToGroupMessageEvent; } });
|
|
65
|
+
Object.defineProperty(exports, "getMessageDirection", { enumerable: true, get: function () { return webhook_1.getMessageDirection; } });
|
|
60
66
|
// Export clients
|
|
61
67
|
var base_client_1 = require("./clients/base-client");
|
|
62
68
|
Object.defineProperty(exports, "BaseClient", { enumerable: true, get: function () { return base_client_1.BaseClient; } });
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;;;;;;;;;;;;;;;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C,yGAAA,UAAU,OAAA;AAEnB,kBAAkB;AAClB,wDAAsD;AAA7C,2GAAA,WAAW,OAAA;AACpB,oDAAkD;AAAzC,uGAAA,SAAS,OAAA;AAClB,2GAA2G;AAC3G,wDAAsD;AAA7C,2GAAA,WAAW,OAAA;AACpB,+DAA+D;AAC/D,sDAAoD;AAA3C,yGAAA,UAAU,OAAA;AACnB,0EAAuE;AAA9D,4HAAA,mBAAmB,OAAA;AAC5B,gFAA6E;AAApE,kIAAA,sBAAsB,OAAA;AAC/B,8DAA4D;AAAnD,iHAAA,cAAc,OAAA;AACvB,wEAAqE;AAA5D,0HAAA,kBAAkB,OAAA;AAE3B,iDAAiD;AACjD,wEAAsE;AAA7D,2HAAA,mBAAmB,OAAA;AAC5B,sEAAoE;AAA3D,yHAAA,kBAAkB,OAAA;AAC3B,kEAAgE;AAAvD,qHAAA,gBAAgB,OAAA;AACzB,8EAA2E;AAAlE,gIAAA,qBAAqB,OAAA;AAC9B,oFAQ+C;AAP7C,sIAAA,wBAAwB,OAAA;AAS1B,wBAAwB;AACxB,uCAAqC;AAA5B,mGAAA,OAAO,OAAA;AAEhB,iBAAiB;AACjB,uCAAgD;AAAvC,mGAAA,OAAO,OAAW"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ZaloClient } from "../clients/zalo-client";
|
|
2
|
-
import { GroupCreateRequest, GroupCreateResult, GroupCreateData, GroupUpdateRequest, GroupUpdateResult, GroupAssetUpdateRequest, GroupAvatarUpdateRequest, GroupMemberInviteRequest, GroupInviteResult, RecentChatsResponse, GroupConversationResponse, GroupsOfOAResponse, GroupDetailResponse, GroupPendingMembersResponse, GroupAcceptPendingMembersResponse, GroupRemoveMembersResponse, GroupMembersResponse, GroupQuotaMessageResponse } from "../types/group";
|
|
2
|
+
import { GroupCreateRequest, GroupCreateResult, GroupCreateData, GroupUpdateRequest, GroupUpdateResult, GroupAssetUpdateRequest, GroupAvatarUpdateRequest, GroupMemberInviteRequest, GroupInviteResult, RecentChatsResponse, GroupConversationResponse, GroupsOfOAResponse, GroupDetailResponse, GroupPendingMembersResponse, GroupAcceptPendingMembersResponse, GroupRemoveMembersResponse, GroupMembersResponse, GroupMemberInfo, GroupQuotaMessageResponse, AllGroupMembersResponse, GetAllMembersProgress, EnhancedGroupMember, AllGroupMembersWithDetailsResponse, GetAllMembersWithDetailsProgress } from "../types/group";
|
|
3
3
|
import { GMFProductType, QuotaType } from "../types/oa";
|
|
4
|
+
import { UserService } from "./user.service";
|
|
4
5
|
/**
|
|
5
6
|
* Service for handling Zalo Official Account Group Management Framework (GMF) APIs
|
|
6
7
|
*
|
|
@@ -38,8 +39,22 @@ import { GMFProductType, QuotaType } from "../types/oa";
|
|
|
38
39
|
*/
|
|
39
40
|
export declare class GroupManagementService {
|
|
40
41
|
private readonly client;
|
|
42
|
+
private readonly userService?;
|
|
41
43
|
private readonly endpoints;
|
|
42
|
-
constructor(client: ZaloClient);
|
|
44
|
+
constructor(client: ZaloClient, userService?: UserService);
|
|
45
|
+
/**
|
|
46
|
+
* Create GroupManagementService with UserService for enhanced member details
|
|
47
|
+
* @param client ZaloClient instance
|
|
48
|
+
* @param userService UserService instance for fetching detailed user info
|
|
49
|
+
* @returns GroupManagementService with enhanced capabilities
|
|
50
|
+
*/
|
|
51
|
+
static withUserService(client: ZaloClient, userService: UserService): GroupManagementService;
|
|
52
|
+
/**
|
|
53
|
+
* Create basic GroupManagementService without UserService
|
|
54
|
+
* @param client ZaloClient instance
|
|
55
|
+
* @returns GroupManagementService with basic capabilities only
|
|
56
|
+
*/
|
|
57
|
+
static basic(client: ZaloClient): GroupManagementService;
|
|
43
58
|
/**
|
|
44
59
|
* Create new group chat with asset_id
|
|
45
60
|
* @param accessToken OA access token
|
|
@@ -297,6 +312,64 @@ export declare class GroupManagementService {
|
|
|
297
312
|
* @returns Group members list
|
|
298
313
|
*/
|
|
299
314
|
getGroupMembers(accessToken: string, groupId: string, offset?: number, count?: number): Promise<GroupMembersResponse>;
|
|
315
|
+
/**
|
|
316
|
+
* Get ALL members of a group (custom function with automatic pagination)
|
|
317
|
+
* @param accessToken OA access token
|
|
318
|
+
* @param groupId Group ID
|
|
319
|
+
* @param maxMembers Maximum number of members to retrieve (default: unlimited)
|
|
320
|
+
* @param progressCallback Optional callback to track progress
|
|
321
|
+
* @returns All group members with pagination info
|
|
322
|
+
*
|
|
323
|
+
* This function automatically handles pagination to retrieve all members,
|
|
324
|
+
* not limited by the 50-member API limit per request.
|
|
325
|
+
*/
|
|
326
|
+
getAllGroupMembers(accessToken: string, groupId: string, maxMembers?: number, progressCallback?: (progress: GetAllMembersProgress) => void): Promise<AllGroupMembersResponse>;
|
|
327
|
+
/**
|
|
328
|
+
* Get ALL members of a group with simple interface (no progress tracking)
|
|
329
|
+
* @param accessToken OA access token
|
|
330
|
+
* @param groupId Group ID
|
|
331
|
+
* @param maxMembers Maximum number of members to retrieve (optional)
|
|
332
|
+
* @returns Array of all group members
|
|
333
|
+
*
|
|
334
|
+
* Simplified version of getAllGroupMembers that returns just the members array
|
|
335
|
+
*/
|
|
336
|
+
getAllGroupMembersSimple(accessToken: string, groupId: string, maxMembers?: number): Promise<GroupMemberInfo[]>;
|
|
337
|
+
/**
|
|
338
|
+
* Get ALL members of a group with DETAILED user information (advanced API)
|
|
339
|
+
* @param accessToken OA access token
|
|
340
|
+
* @param groupId Group ID
|
|
341
|
+
* @param maxMembers Maximum number of members to retrieve (default: unlimited)
|
|
342
|
+
* @param progressCallback Optional callback to track progress
|
|
343
|
+
* @param options Advanced options for fetching details
|
|
344
|
+
* @returns All group members with detailed user information
|
|
345
|
+
*
|
|
346
|
+
* This function:
|
|
347
|
+
* 1. First gets all basic member info using getAllGroupMembers()
|
|
348
|
+
* 2. Then fetches detailed user info for each member using UserService.getUserInfo()
|
|
349
|
+
* 3. Combines both basic and detailed info into EnhancedGroupMember objects
|
|
350
|
+
* 4. If detailed info fails to fetch, falls back to basic info only
|
|
351
|
+
* 5. Provides detailed progress tracking and statistics
|
|
352
|
+
*/
|
|
353
|
+
getAllGroupMembersWithDetails(accessToken: string, groupId: string, maxMembers?: number, progressCallback?: (progress: GetAllMembersWithDetailsProgress) => void, options?: {
|
|
354
|
+
/** Batch size for fetching user details (default: 10) */
|
|
355
|
+
detailBatchSize?: number;
|
|
356
|
+
/** Timeout for each user detail request in ms (default: 5000) */
|
|
357
|
+
detailTimeout?: number;
|
|
358
|
+
/** Whether to continue if UserService is not available (default: true) */
|
|
359
|
+
continueWithoutUserService?: boolean;
|
|
360
|
+
/** Maximum concurrent detail requests (default: 5) */
|
|
361
|
+
maxConcurrentRequests?: number;
|
|
362
|
+
}): Promise<AllGroupMembersWithDetailsResponse>;
|
|
363
|
+
/**
|
|
364
|
+
* Get ALL members of a group with detailed info - Simple interface
|
|
365
|
+
* @param accessToken OA access token
|
|
366
|
+
* @param groupId Group ID
|
|
367
|
+
* @param maxMembers Maximum number of members to retrieve (optional)
|
|
368
|
+
* @returns Array of enhanced group members with detailed info
|
|
369
|
+
*
|
|
370
|
+
* Simplified version that returns just the enhanced members array
|
|
371
|
+
*/
|
|
372
|
+
getAllGroupMembersWithDetailsSimple(accessToken: string, groupId: string, maxMembers?: number): Promise<EnhancedGroupMember[]>;
|
|
300
373
|
private handleGroupManagementError;
|
|
301
374
|
}
|
|
302
375
|
//# sourceMappingURL=group-management.service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"group-management.service.d.ts","sourceRoot":"","sources":["../../src/services/group-management.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,EACf,kBAAkB,EAClB,iBAAiB,EACjB,uBAAuB,EACvB,wBAAwB,EACxB,wBAAwB,EACxB,iBAAiB,EAIjB,mBAAmB,EACnB,yBAAyB,EACzB,kBAAkB,EAClB,mBAAmB,EACnB,2BAA2B,EAE3B,iCAAiC,EAEjC,0BAA0B,EAC1B,oBAAoB,
|
|
1
|
+
{"version":3,"file":"group-management.service.d.ts","sourceRoot":"","sources":["../../src/services/group-management.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,EACf,kBAAkB,EAClB,iBAAiB,EACjB,uBAAuB,EACvB,wBAAwB,EACxB,wBAAwB,EACxB,iBAAiB,EAIjB,mBAAmB,EACnB,yBAAyB,EACzB,kBAAkB,EAClB,mBAAmB,EACnB,2BAA2B,EAE3B,iCAAiC,EAEjC,0BAA0B,EAC1B,oBAAoB,EACpB,eAAe,EAEf,yBAAyB,EACzB,uBAAuB,EACvB,qBAAqB,EACrB,mBAAmB,EACnB,kCAAkC,EAClC,gCAAgC,EACjC,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAG7C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,qBAAa,sBAAsB;IA4B/B,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC;IAzB/B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAqBf;gBAGQ,MAAM,EAAE,UAAU,EAClB,WAAW,CAAC,EAAE,WAAW;IAG5C;;;;;OAKG;IACH,MAAM,CAAC,eAAe,CAAC,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,GAAG,sBAAsB;IAI5F;;;;OAIG;IACH,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,UAAU,GAAG,sBAAsB;IAIxD;;;;;;;OAOG;IACG,WAAW,CACf,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,kBAAkB,GAC5B,OAAO,CAAC,iBAAiB,CAAC;IA+C7B;;;;OAIG;IACH,gBAAg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EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,EACf,UAAU,CAAC,EAAE,MAAM,EACnB,gBAAgB,CAAC,EAAE,CAAC,QAAQ,EAAE,gCAAgC,KAAK,IAAI,EACvE,OAAO,CAAC,EAAE;QACR,yDAAyD;QACzD,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,iEAAiE;QACjE,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,0EAA0E;QAC1E,0BAA0B,CAAC,EAAE,OAAO,CAAC;QACrC,sDAAsD;QACtD,qBAAqB,CAAC,EAAE,MAAM,CAAC;KAChC,GACA,OAAO,CAAC,kCAAkC,CAAC;IA+L9C;;;;;;;;OAQG;IACG,mCAAmC,CACvC,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,EACf,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,mBAAmB,EAAE,CAAC;IAKjC,OAAO,CAAC,0BAA0B;CAuBnC"}
|
|
@@ -38,8 +38,9 @@ const common_1 = require("../types/common");
|
|
|
38
38
|
* - Member invitation frequency: max 500 invitations/day
|
|
39
39
|
*/
|
|
40
40
|
class GroupManagementService {
|
|
41
|
-
constructor(client) {
|
|
41
|
+
constructor(client, userService) {
|
|
42
42
|
this.client = client;
|
|
43
|
+
this.userService = userService;
|
|
43
44
|
// Zalo API endpoints - organized by functionality
|
|
44
45
|
this.endpoints = {
|
|
45
46
|
group: {
|
|
@@ -64,6 +65,23 @@ class GroupManagementService {
|
|
|
64
65
|
},
|
|
65
66
|
};
|
|
66
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Create GroupManagementService with UserService for enhanced member details
|
|
70
|
+
* @param client ZaloClient instance
|
|
71
|
+
* @param userService UserService instance for fetching detailed user info
|
|
72
|
+
* @returns GroupManagementService with enhanced capabilities
|
|
73
|
+
*/
|
|
74
|
+
static withUserService(client, userService) {
|
|
75
|
+
return new GroupManagementService(client, userService);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Create basic GroupManagementService without UserService
|
|
79
|
+
* @param client ZaloClient instance
|
|
80
|
+
* @returns GroupManagementService with basic capabilities only
|
|
81
|
+
*/
|
|
82
|
+
static basic(client) {
|
|
83
|
+
return new GroupManagementService(client);
|
|
84
|
+
}
|
|
67
85
|
/**
|
|
68
86
|
* Create new group chat with asset_id
|
|
69
87
|
* @param accessToken OA access token
|
|
@@ -707,6 +725,302 @@ class GroupManagementService {
|
|
|
707
725
|
throw this.handleGroupManagementError(error, "Failed to get group members");
|
|
708
726
|
}
|
|
709
727
|
}
|
|
728
|
+
/**
|
|
729
|
+
* Get ALL members of a group (custom function with automatic pagination)
|
|
730
|
+
* @param accessToken OA access token
|
|
731
|
+
* @param groupId Group ID
|
|
732
|
+
* @param maxMembers Maximum number of members to retrieve (default: unlimited)
|
|
733
|
+
* @param progressCallback Optional callback to track progress
|
|
734
|
+
* @returns All group members with pagination info
|
|
735
|
+
*
|
|
736
|
+
* This function automatically handles pagination to retrieve all members,
|
|
737
|
+
* not limited by the 50-member API limit per request.
|
|
738
|
+
*/
|
|
739
|
+
async getAllGroupMembers(accessToken, groupId, maxMembers, progressCallback) {
|
|
740
|
+
try {
|
|
741
|
+
// Validate input
|
|
742
|
+
if (!accessToken || accessToken.trim().length === 0) {
|
|
743
|
+
throw new common_1.ZaloSDKError("Access token cannot be empty", -1);
|
|
744
|
+
}
|
|
745
|
+
if (!groupId || groupId.trim().length === 0) {
|
|
746
|
+
throw new common_1.ZaloSDKError("Group ID cannot be empty", -1);
|
|
747
|
+
}
|
|
748
|
+
if (maxMembers !== undefined && maxMembers <= 0) {
|
|
749
|
+
throw new common_1.ZaloSDKError("Max members must be greater than 0", -1);
|
|
750
|
+
}
|
|
751
|
+
const allMembers = [];
|
|
752
|
+
let offset = 0;
|
|
753
|
+
const pageSize = 50; // Maximum allowed by Zalo API
|
|
754
|
+
let totalCount;
|
|
755
|
+
let pagesFetched = 0;
|
|
756
|
+
let hasMore = true;
|
|
757
|
+
// Progress tracking
|
|
758
|
+
const updateProgress = (currentCount, isComplete = false) => {
|
|
759
|
+
if (progressCallback) {
|
|
760
|
+
const percentage = totalCount ? Math.round((currentCount / totalCount) * 100) : undefined;
|
|
761
|
+
progressCallback({
|
|
762
|
+
currentCount,
|
|
763
|
+
totalCount,
|
|
764
|
+
percentage,
|
|
765
|
+
isComplete
|
|
766
|
+
});
|
|
767
|
+
}
|
|
768
|
+
};
|
|
769
|
+
// Initial progress
|
|
770
|
+
updateProgress(0);
|
|
771
|
+
while (hasMore) {
|
|
772
|
+
// Check if we've reached the maximum limit
|
|
773
|
+
if (maxMembers && allMembers.length >= maxMembers) {
|
|
774
|
+
break;
|
|
775
|
+
}
|
|
776
|
+
// Calculate how many members to request in this batch
|
|
777
|
+
const remainingLimit = maxMembers ? maxMembers - allMembers.length : pageSize;
|
|
778
|
+
const currentPageSize = Math.min(pageSize, remainingLimit);
|
|
779
|
+
// Fetch current page
|
|
780
|
+
const response = await this.getGroupMembers(accessToken, groupId, offset, currentPageSize);
|
|
781
|
+
// Handle API errors
|
|
782
|
+
if (response.error !== 0) {
|
|
783
|
+
throw new common_1.ZaloSDKError(`Failed to fetch members at offset ${offset}: ${response.message}`, response.error);
|
|
784
|
+
}
|
|
785
|
+
// Check if we have data
|
|
786
|
+
if (!response.data || !response.data.members) {
|
|
787
|
+
break;
|
|
788
|
+
}
|
|
789
|
+
// Update total count from first response
|
|
790
|
+
if (totalCount === undefined && response.data.total !== undefined) {
|
|
791
|
+
totalCount = response.data.total;
|
|
792
|
+
// If maxMembers is set and less than total, use maxMembers as effective total
|
|
793
|
+
if (maxMembers && maxMembers < totalCount) {
|
|
794
|
+
totalCount = maxMembers;
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
// Add members to our collection
|
|
798
|
+
allMembers.push(...response.data.members);
|
|
799
|
+
pagesFetched++;
|
|
800
|
+
// Update progress
|
|
801
|
+
updateProgress(allMembers.length);
|
|
802
|
+
// Check if we should continue
|
|
803
|
+
const receivedCount = response.data.members.length;
|
|
804
|
+
hasMore = receivedCount === currentPageSize &&
|
|
805
|
+
(!maxMembers || allMembers.length < maxMembers) &&
|
|
806
|
+
(response.data.total === undefined || allMembers.length < response.data.total);
|
|
807
|
+
// Move to next page
|
|
808
|
+
offset += receivedCount;
|
|
809
|
+
// Safety check to prevent infinite loops
|
|
810
|
+
if (pagesFetched > 1000) { // Max 50,000 members (50 * 1000)
|
|
811
|
+
console.warn(`getAllGroupMembers: Reached maximum page limit (${pagesFetched}) for group ${groupId}`);
|
|
812
|
+
break;
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
// Final progress update
|
|
816
|
+
updateProgress(allMembers.length, true);
|
|
817
|
+
// Apply maxMembers limit if specified
|
|
818
|
+
const finalMembers = maxMembers ? allMembers.slice(0, maxMembers) : allMembers;
|
|
819
|
+
// Return enhanced response
|
|
820
|
+
return {
|
|
821
|
+
error: 0,
|
|
822
|
+
message: "Success",
|
|
823
|
+
data: {
|
|
824
|
+
total_members: totalCount || allMembers.length,
|
|
825
|
+
members: finalMembers,
|
|
826
|
+
pages_fetched: pagesFetched,
|
|
827
|
+
is_complete: !maxMembers || allMembers.length <= maxMembers
|
|
828
|
+
}
|
|
829
|
+
};
|
|
830
|
+
}
|
|
831
|
+
catch (error) {
|
|
832
|
+
throw this.handleGroupManagementError(error, "Failed to get all group members");
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
/**
|
|
836
|
+
* Get ALL members of a group with simple interface (no progress tracking)
|
|
837
|
+
* @param accessToken OA access token
|
|
838
|
+
* @param groupId Group ID
|
|
839
|
+
* @param maxMembers Maximum number of members to retrieve (optional)
|
|
840
|
+
* @returns Array of all group members
|
|
841
|
+
*
|
|
842
|
+
* Simplified version of getAllGroupMembers that returns just the members array
|
|
843
|
+
*/
|
|
844
|
+
async getAllGroupMembersSimple(accessToken, groupId, maxMembers) {
|
|
845
|
+
const response = await this.getAllGroupMembers(accessToken, groupId, maxMembers);
|
|
846
|
+
return response.data.members;
|
|
847
|
+
}
|
|
848
|
+
/**
|
|
849
|
+
* Get ALL members of a group with DETAILED user information (advanced API)
|
|
850
|
+
* @param accessToken OA access token
|
|
851
|
+
* @param groupId Group ID
|
|
852
|
+
* @param maxMembers Maximum number of members to retrieve (default: unlimited)
|
|
853
|
+
* @param progressCallback Optional callback to track progress
|
|
854
|
+
* @param options Advanced options for fetching details
|
|
855
|
+
* @returns All group members with detailed user information
|
|
856
|
+
*
|
|
857
|
+
* This function:
|
|
858
|
+
* 1. First gets all basic member info using getAllGroupMembers()
|
|
859
|
+
* 2. Then fetches detailed user info for each member using UserService.getUserInfo()
|
|
860
|
+
* 3. Combines both basic and detailed info into EnhancedGroupMember objects
|
|
861
|
+
* 4. If detailed info fails to fetch, falls back to basic info only
|
|
862
|
+
* 5. Provides detailed progress tracking and statistics
|
|
863
|
+
*/
|
|
864
|
+
async getAllGroupMembersWithDetails(accessToken, groupId, maxMembers, progressCallback, options) {
|
|
865
|
+
try {
|
|
866
|
+
// Validate input
|
|
867
|
+
if (!accessToken || accessToken.trim().length === 0) {
|
|
868
|
+
throw new common_1.ZaloSDKError("Access token cannot be empty", -1);
|
|
869
|
+
}
|
|
870
|
+
if (!groupId || groupId.trim().length === 0) {
|
|
871
|
+
throw new common_1.ZaloSDKError("Group ID cannot be empty", -1);
|
|
872
|
+
}
|
|
873
|
+
// Set default options
|
|
874
|
+
const opts = {
|
|
875
|
+
detailBatchSize: 10,
|
|
876
|
+
detailTimeout: 5000,
|
|
877
|
+
continueWithoutUserService: true,
|
|
878
|
+
maxConcurrentRequests: 5,
|
|
879
|
+
...options
|
|
880
|
+
};
|
|
881
|
+
// Check if UserService is available
|
|
882
|
+
if (!this.userService && !opts.continueWithoutUserService) {
|
|
883
|
+
throw new common_1.ZaloSDKError("UserService is required for fetching detailed member information. " +
|
|
884
|
+
"Please provide UserService in constructor or set continueWithoutUserService to true.", -1);
|
|
885
|
+
}
|
|
886
|
+
// Progress tracking helper
|
|
887
|
+
const updateProgress = (currentCount, totalCount, phase, phaseDetails, isComplete = false) => {
|
|
888
|
+
if (progressCallback) {
|
|
889
|
+
const percentage = totalCount ? Math.round((currentCount / totalCount) * 100) : undefined;
|
|
890
|
+
progressCallback({
|
|
891
|
+
currentCount,
|
|
892
|
+
totalCount,
|
|
893
|
+
percentage,
|
|
894
|
+
isComplete,
|
|
895
|
+
phase,
|
|
896
|
+
phase_details: phaseDetails
|
|
897
|
+
});
|
|
898
|
+
}
|
|
899
|
+
};
|
|
900
|
+
// Phase 1: Get all basic member information
|
|
901
|
+
updateProgress(0, undefined, 'fetching_members');
|
|
902
|
+
const basicMembersResponse = await this.getAllGroupMembers(accessToken, groupId, maxMembers, (basicProgress) => {
|
|
903
|
+
updateProgress(basicProgress.currentCount, basicProgress.totalCount, 'fetching_members');
|
|
904
|
+
});
|
|
905
|
+
const basicMembers = basicMembersResponse.data.members;
|
|
906
|
+
const totalMembers = basicMembers.length;
|
|
907
|
+
// Initialize enhanced members with basic info
|
|
908
|
+
const enhancedMembers = basicMembers.map((member) => ({
|
|
909
|
+
basic_info: member,
|
|
910
|
+
detailed_info: null,
|
|
911
|
+
has_detailed_info: false
|
|
912
|
+
}));
|
|
913
|
+
// Statistics tracking
|
|
914
|
+
let successfulDetails = 0;
|
|
915
|
+
let failedDetails = 0;
|
|
916
|
+
// Phase 2: Fetch detailed user information (if UserService is available)
|
|
917
|
+
if (this.userService && totalMembers > 0) {
|
|
918
|
+
updateProgress(0, totalMembers, 'fetching_details', {
|
|
919
|
+
details_fetched: 0,
|
|
920
|
+
details_failed: 0,
|
|
921
|
+
current_batch: 0,
|
|
922
|
+
total_batches: Math.ceil(totalMembers / opts.detailBatchSize)
|
|
923
|
+
});
|
|
924
|
+
// Process members in batches to avoid overwhelming the API
|
|
925
|
+
for (let i = 0; i < totalMembers; i += opts.detailBatchSize) {
|
|
926
|
+
const batch = enhancedMembers.slice(i, i + opts.detailBatchSize);
|
|
927
|
+
const currentBatch = Math.floor(i / opts.detailBatchSize) + 1;
|
|
928
|
+
const totalBatches = Math.ceil(totalMembers / opts.detailBatchSize);
|
|
929
|
+
// Create promises for current batch with concurrency limit
|
|
930
|
+
const batchPromises = batch.map(async (enhancedMember) => {
|
|
931
|
+
const userId = enhancedMember.basic_info.user_id || enhancedMember.basic_info.oa_id;
|
|
932
|
+
if (!userId) {
|
|
933
|
+
enhancedMember.detail_fetch_error = "No user_id or oa_id available";
|
|
934
|
+
failedDetails++;
|
|
935
|
+
return;
|
|
936
|
+
}
|
|
937
|
+
try {
|
|
938
|
+
// Create timeout promise
|
|
939
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
940
|
+
setTimeout(() => reject(new Error('Timeout')), opts.detailTimeout);
|
|
941
|
+
});
|
|
942
|
+
// Fetch user details with timeout
|
|
943
|
+
const userDetailPromise = this.userService.getUserInfo(accessToken, userId);
|
|
944
|
+
const userDetail = await Promise.race([userDetailPromise, timeoutPromise]);
|
|
945
|
+
enhancedMember.detailed_info = userDetail;
|
|
946
|
+
enhancedMember.has_detailed_info = true;
|
|
947
|
+
successfulDetails++;
|
|
948
|
+
}
|
|
949
|
+
catch (error) {
|
|
950
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
951
|
+
enhancedMember.detail_fetch_error = `Failed to fetch user details: ${errorMessage}`;
|
|
952
|
+
failedDetails++;
|
|
953
|
+
}
|
|
954
|
+
// Update progress for each member processed
|
|
955
|
+
const processedCount = successfulDetails + failedDetails;
|
|
956
|
+
updateProgress(processedCount, totalMembers, 'fetching_details', {
|
|
957
|
+
details_fetched: successfulDetails,
|
|
958
|
+
details_failed: failedDetails,
|
|
959
|
+
current_batch: currentBatch,
|
|
960
|
+
total_batches: totalBatches
|
|
961
|
+
});
|
|
962
|
+
});
|
|
963
|
+
// Process batch with concurrency limit
|
|
964
|
+
const chunks = [];
|
|
965
|
+
for (let j = 0; j < batchPromises.length; j += opts.maxConcurrentRequests) {
|
|
966
|
+
chunks.push(batchPromises.slice(j, j + opts.maxConcurrentRequests));
|
|
967
|
+
}
|
|
968
|
+
for (const chunk of chunks) {
|
|
969
|
+
await Promise.all(chunk);
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
else if (!this.userService) {
|
|
974
|
+
// UserService not available, mark all as failed but continue
|
|
975
|
+
failedDetails = totalMembers;
|
|
976
|
+
enhancedMembers.forEach(member => {
|
|
977
|
+
member.detail_fetch_error = "UserService not available";
|
|
978
|
+
});
|
|
979
|
+
}
|
|
980
|
+
// Final progress update
|
|
981
|
+
updateProgress(totalMembers, totalMembers, 'complete', {
|
|
982
|
+
details_fetched: successfulDetails,
|
|
983
|
+
details_failed: failedDetails
|
|
984
|
+
}, true);
|
|
985
|
+
// Calculate success rate
|
|
986
|
+
const successRate = totalMembers > 0 ? Math.round((successfulDetails / totalMembers) * 100) : 0;
|
|
987
|
+
// Apply maxMembers limit if specified
|
|
988
|
+
const finalMembers = maxMembers ? enhancedMembers.slice(0, maxMembers) : enhancedMembers;
|
|
989
|
+
// Return enhanced response
|
|
990
|
+
return {
|
|
991
|
+
error: 0,
|
|
992
|
+
message: "Success",
|
|
993
|
+
data: {
|
|
994
|
+
total_members: basicMembersResponse.data.total_members,
|
|
995
|
+
members: finalMembers,
|
|
996
|
+
pages_fetched: basicMembersResponse.data.pages_fetched,
|
|
997
|
+
is_complete: basicMembersResponse.data.is_complete,
|
|
998
|
+
detail_fetch_stats: {
|
|
999
|
+
total_processed: totalMembers,
|
|
1000
|
+
successful_details: successfulDetails,
|
|
1001
|
+
failed_details: failedDetails,
|
|
1002
|
+
success_rate: successRate
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
};
|
|
1006
|
+
}
|
|
1007
|
+
catch (error) {
|
|
1008
|
+
throw this.handleGroupManagementError(error, "Failed to get all group members with details");
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
/**
|
|
1012
|
+
* Get ALL members of a group with detailed info - Simple interface
|
|
1013
|
+
* @param accessToken OA access token
|
|
1014
|
+
* @param groupId Group ID
|
|
1015
|
+
* @param maxMembers Maximum number of members to retrieve (optional)
|
|
1016
|
+
* @returns Array of enhanced group members with detailed info
|
|
1017
|
+
*
|
|
1018
|
+
* Simplified version that returns just the enhanced members array
|
|
1019
|
+
*/
|
|
1020
|
+
async getAllGroupMembersWithDetailsSimple(accessToken, groupId, maxMembers) {
|
|
1021
|
+
const response = await this.getAllGroupMembersWithDetails(accessToken, groupId, maxMembers);
|
|
1022
|
+
return response.data.members;
|
|
1023
|
+
}
|
|
710
1024
|
handleGroupManagementError(error, defaultMessage) {
|
|
711
1025
|
if (error instanceof common_1.ZaloSDKError) {
|
|
712
1026
|
return error;
|