@warriorteam/redai-zalo-sdk 1.1.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/LICENSE +21 -0
- package/README.md +448 -0
- package/dist/clients/base-client.d.ts +67 -0
- package/dist/clients/base-client.d.ts.map +1 -0
- package/dist/clients/base-client.js +297 -0
- package/dist/clients/base-client.js.map +1 -0
- package/dist/clients/zalo-client.d.ts +131 -0
- package/dist/clients/zalo-client.d.ts.map +1 -0
- package/dist/clients/zalo-client.js +215 -0
- package/dist/clients/zalo-client.js.map +1 -0
- package/dist/index.d.ts +40 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +82 -0
- package/dist/index.js.map +1 -0
- package/dist/services/article.service.d.ts +144 -0
- package/dist/services/article.service.d.ts.map +1 -0
- package/dist/services/article.service.js +518 -0
- package/dist/services/article.service.js.map +1 -0
- package/dist/services/auth.service.d.ts +55 -0
- package/dist/services/auth.service.d.ts.map +1 -0
- package/dist/services/auth.service.js +269 -0
- package/dist/services/auth.service.js.map +1 -0
- package/dist/services/consultation.service.d.ts +73 -0
- package/dist/services/consultation.service.d.ts.map +1 -0
- package/dist/services/consultation.service.js +208 -0
- package/dist/services/consultation.service.js.map +1 -0
- package/dist/services/general-message.service.d.ts +85 -0
- package/dist/services/general-message.service.d.ts.map +1 -0
- package/dist/services/general-message.service.js +248 -0
- package/dist/services/general-message.service.js.map +1 -0
- package/dist/services/group-management.service.d.ts +220 -0
- package/dist/services/group-management.service.d.ts.map +1 -0
- package/dist/services/group-management.service.js +562 -0
- package/dist/services/group-management.service.js.map +1 -0
- package/dist/services/group-message.service.d.ts +102 -0
- package/dist/services/group-message.service.d.ts.map +1 -0
- package/dist/services/group-message.service.js +233 -0
- package/dist/services/group-message.service.js.map +1 -0
- package/dist/services/message-management.service.d.ts +135 -0
- package/dist/services/message-management.service.d.ts.map +1 -0
- package/dist/services/message-management.service.js +237 -0
- package/dist/services/message-management.service.js.map +1 -0
- package/dist/services/oa.service.d.ts +67 -0
- package/dist/services/oa.service.d.ts.map +1 -0
- package/dist/services/oa.service.js +223 -0
- package/dist/services/oa.service.js.map +1 -0
- package/dist/services/promotion.service.d.ts +114 -0
- package/dist/services/promotion.service.d.ts.map +1 -0
- package/dist/services/promotion.service.js +247 -0
- package/dist/services/promotion.service.js.map +1 -0
- package/dist/services/tag.service.d.ts +144 -0
- package/dist/services/tag.service.d.ts.map +1 -0
- package/dist/services/tag.service.js +184 -0
- package/dist/services/tag.service.js.map +1 -0
- package/dist/services/transaction.service.d.ts +110 -0
- package/dist/services/transaction.service.d.ts.map +1 -0
- package/dist/services/transaction.service.js +231 -0
- package/dist/services/transaction.service.js.map +1 -0
- package/dist/services/user-management.service.d.ts +117 -0
- package/dist/services/user-management.service.d.ts.map +1 -0
- package/dist/services/user-management.service.js +239 -0
- package/dist/services/user-management.service.js.map +1 -0
- package/dist/services/user.service.d.ts +84 -0
- package/dist/services/user.service.d.ts.map +1 -0
- package/dist/services/user.service.js +323 -0
- package/dist/services/user.service.js.map +1 -0
- package/dist/services/video-upload.service.d.ts +83 -0
- package/dist/services/video-upload.service.d.ts.map +1 -0
- package/dist/services/video-upload.service.js +267 -0
- package/dist/services/video-upload.service.js.map +1 -0
- package/dist/services/zns.service.d.ts +116 -0
- package/dist/services/zns.service.d.ts.map +1 -0
- package/dist/services/zns.service.js +234 -0
- package/dist/services/zns.service.js.map +1 -0
- package/dist/types/article.d.ts +352 -0
- package/dist/types/article.d.ts.map +1 -0
- package/dist/types/article.js +70 -0
- package/dist/types/article.js.map +1 -0
- package/dist/types/auth.d.ts +233 -0
- package/dist/types/auth.d.ts.map +1 -0
- package/dist/types/auth.js +39 -0
- package/dist/types/auth.js.map +1 -0
- package/dist/types/common.d.ts +237 -0
- package/dist/types/common.d.ts.map +1 -0
- package/dist/types/common.js +42 -0
- package/dist/types/common.js.map +1 -0
- package/dist/types/group.d.ts +523 -0
- package/dist/types/group.d.ts.map +1 -0
- package/dist/types/group.js +6 -0
- package/dist/types/group.js.map +1 -0
- package/dist/types/message.d.ts +333 -0
- package/dist/types/message.d.ts.map +1 -0
- package/dist/types/message.js +17 -0
- package/dist/types/message.js.map +1 -0
- package/dist/types/oa.d.ts +285 -0
- package/dist/types/oa.d.ts.map +1 -0
- package/dist/types/oa.js +25 -0
- package/dist/types/oa.js.map +1 -0
- package/dist/types/social.d.ts +427 -0
- package/dist/types/social.d.ts.map +1 -0
- package/dist/types/social.js +6 -0
- package/dist/types/social.js.map +1 -0
- package/dist/types/user-management.d.ts +280 -0
- package/dist/types/user-management.d.ts.map +1 -0
- package/dist/types/user-management.js +6 -0
- package/dist/types/user-management.js.map +1 -0
- package/dist/types/user.d.ts +365 -0
- package/dist/types/user.d.ts.map +1 -0
- package/dist/types/user.js +17 -0
- package/dist/types/user.js.map +1 -0
- package/dist/types/webhook.d.ts +1972 -0
- package/dist/types/webhook.d.ts.map +1 -0
- package/dist/types/webhook.js +419 -0
- package/dist/types/webhook.js.map +1 -0
- package/dist/types/zns.d.ts +277 -0
- package/dist/types/zns.d.ts.map +1 -0
- package/dist/types/zns.js +6 -0
- package/dist/types/zns.js.map +1 -0
- package/dist/zalo-sdk.d.ts +228 -0
- package/dist/zalo-sdk.d.ts.map +1 -0
- package/dist/zalo-sdk.js +307 -0
- package/dist/zalo-sdk.js.map +1 -0
- package/package.json +59 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { ZaloClient } from "../clients/zalo-client";
|
|
2
|
+
import { GroupTextMessage, GroupImageMessage, GroupFileMessage, GroupStickerMessage, GroupMentionMessage, GroupMessageResult, GroupInfo, GroupMember } from "../types/group";
|
|
3
|
+
/**
|
|
4
|
+
* Service for handling Zalo Official Account Group Message Framework (GMF) APIs
|
|
5
|
+
*
|
|
6
|
+
* CONDITIONS FOR USING ZALO GMF:
|
|
7
|
+
*
|
|
8
|
+
* 1. OPT-IN CONDITIONS FOR SENDING GROUP MESSAGES:
|
|
9
|
+
* - OA must have the group_id of the chat group
|
|
10
|
+
* - OA must be added to the chat group by group admin
|
|
11
|
+
* - OA must have permission to send messages in the group (granted by group admin)
|
|
12
|
+
* - Chat group must be active (not locked or disbanded)
|
|
13
|
+
*
|
|
14
|
+
* 2. ACCESS PERMISSIONS:
|
|
15
|
+
* - Application needs to be granted group chat management permissions
|
|
16
|
+
* - Access token must have "manage_group" scope or equivalent
|
|
17
|
+
* - OA must be authenticated and have active status
|
|
18
|
+
*
|
|
19
|
+
* 3. LIMITS AND CONSTRAINTS:
|
|
20
|
+
* - Can only send messages to groups that OA has joined
|
|
21
|
+
* - Cannot send messages to private groups that OA hasn't been invited to
|
|
22
|
+
* - Must comply with Zalo's message sending frequency limits
|
|
23
|
+
* - Message content must comply with Zalo's content policy
|
|
24
|
+
*
|
|
25
|
+
* 4. SUPPORTED MESSAGE TYPES:
|
|
26
|
+
* - Text message: Plain text messages
|
|
27
|
+
* - Image message: Image messages (JPG, PNG, GIF - max 5MB)
|
|
28
|
+
* - File message: File attachments (max 25MB)
|
|
29
|
+
* - Sticker message: Stickers from Zalo collection
|
|
30
|
+
* - Mention message: Tag/mention specific members
|
|
31
|
+
*
|
|
32
|
+
* 5. TECHNICAL REQUIREMENTS:
|
|
33
|
+
* - Use HTTPS for all API calls
|
|
34
|
+
* - Content-Type: application/json for text/mention messages
|
|
35
|
+
* - Content-Type: multipart/form-data for file/image uploads
|
|
36
|
+
*/
|
|
37
|
+
export declare class GroupMessageService {
|
|
38
|
+
private readonly client;
|
|
39
|
+
private readonly apiUrl;
|
|
40
|
+
constructor(client: ZaloClient);
|
|
41
|
+
/**
|
|
42
|
+
* Send text message to group
|
|
43
|
+
* @param accessToken OA access token
|
|
44
|
+
* @param groupId Group ID
|
|
45
|
+
* @param message Text message content
|
|
46
|
+
* @returns Send result
|
|
47
|
+
*/
|
|
48
|
+
sendTextMessage(accessToken: string, groupId: string, message: GroupTextMessage): Promise<GroupMessageResult>;
|
|
49
|
+
/**
|
|
50
|
+
* Send image message to group
|
|
51
|
+
* @param accessToken OA access token
|
|
52
|
+
* @param groupId Group ID
|
|
53
|
+
* @param message Image message content
|
|
54
|
+
* @returns Send result
|
|
55
|
+
*/
|
|
56
|
+
sendImageMessage(accessToken: string, groupId: string, message: GroupImageMessage): Promise<GroupMessageResult>;
|
|
57
|
+
/**
|
|
58
|
+
* Send file message to group
|
|
59
|
+
* @param accessToken OA access token
|
|
60
|
+
* @param groupId Group ID
|
|
61
|
+
* @param message File message content
|
|
62
|
+
* @returns Send result
|
|
63
|
+
*/
|
|
64
|
+
sendFileMessage(accessToken: string, groupId: string, message: GroupFileMessage): Promise<GroupMessageResult>;
|
|
65
|
+
/**
|
|
66
|
+
* Send sticker message to group
|
|
67
|
+
* @param accessToken OA access token
|
|
68
|
+
* @param groupId Group ID
|
|
69
|
+
* @param message Sticker message content
|
|
70
|
+
* @returns Send result
|
|
71
|
+
*/
|
|
72
|
+
sendStickerMessage(accessToken: string, groupId: string, message: GroupStickerMessage): Promise<GroupMessageResult>;
|
|
73
|
+
/**
|
|
74
|
+
* Send mention message to group
|
|
75
|
+
* @param accessToken OA access token
|
|
76
|
+
* @param groupId Group ID
|
|
77
|
+
* @param message Mention message content
|
|
78
|
+
* @returns Send result
|
|
79
|
+
*/
|
|
80
|
+
sendMentionMessage(accessToken: string, groupId: string, message: GroupMentionMessage): Promise<GroupMessageResult>;
|
|
81
|
+
/**
|
|
82
|
+
* Get group information
|
|
83
|
+
* @param accessToken OA access token
|
|
84
|
+
* @param groupId Group ID
|
|
85
|
+
* @returns Group information
|
|
86
|
+
*/
|
|
87
|
+
getGroupInfo(accessToken: string, groupId: string): Promise<GroupInfo>;
|
|
88
|
+
/**
|
|
89
|
+
* Get group members
|
|
90
|
+
* @param accessToken OA access token
|
|
91
|
+
* @param groupId Group ID
|
|
92
|
+
* @param offset Offset for pagination
|
|
93
|
+
* @param count Number of members to retrieve
|
|
94
|
+
* @returns Group members list
|
|
95
|
+
*/
|
|
96
|
+
getGroupMembers(accessToken: string, groupId: string, offset?: number, count?: number): Promise<{
|
|
97
|
+
members: GroupMember[];
|
|
98
|
+
total: number;
|
|
99
|
+
}>;
|
|
100
|
+
private handleGroupMessageError;
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=group-message.service.d.ts.map
|
|
@@ -0,0 +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;AAExB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,qBAAa,mBAAmB;IAGlB,OAAO,CAAC,QAAQ,CAAC,MAAM;IAFnC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAqC;gBAE/B,MAAM,EAAE,UAAU;IAE/C;;;;;;OAMG;IACG,eAAe,CACnB,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,kBAAkB,CAAC;IAwB9B;;;;;;OAMG;IACG,gBAAgB,CACpB,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,iBAAiB,GACzB,OAAO,CAAC,kBAAkB,CAAC;IAmC9B;;;;;;OAMG;IACG,eAAe,CACnB,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,kBAAkB,CAAC;IA6B9B;;;;;;OAMG;IACG,kBAAkB,CACtB,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,mBAAmB,GAC3B,OAAO,CAAC,kBAAkB,CAAC;IAmC9B;;;;;;OAMG;IACG,kBAAkB,CACtB,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,mBAAmB,GAC3B,OAAO,CAAC,kBAAkB,CAAC;IAyB9B;;;;;OAKG;IACG,YAAY,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;IAmB5E;;;;;;;OAOG;IACG,eAAe,CACnB,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,EACf,MAAM,GAAE,MAAU,EAClB,KAAK,GAAE,MAAW,GACjB,OAAO,CAAC;QAAE,OAAO,EAAE,WAAW,EAAE,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAiBrD,OAAO,CAAC,uBAAuB;CAWhC"}
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GroupMessageService = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Service for handling Zalo Official Account Group Message Framework (GMF) APIs
|
|
6
|
+
*
|
|
7
|
+
* CONDITIONS FOR USING ZALO GMF:
|
|
8
|
+
*
|
|
9
|
+
* 1. OPT-IN CONDITIONS FOR SENDING GROUP MESSAGES:
|
|
10
|
+
* - OA must have the group_id of the chat group
|
|
11
|
+
* - OA must be added to the chat group by group admin
|
|
12
|
+
* - OA must have permission to send messages in the group (granted by group admin)
|
|
13
|
+
* - Chat group must be active (not locked or disbanded)
|
|
14
|
+
*
|
|
15
|
+
* 2. ACCESS PERMISSIONS:
|
|
16
|
+
* - Application needs to be granted group chat management permissions
|
|
17
|
+
* - Access token must have "manage_group" scope or equivalent
|
|
18
|
+
* - OA must be authenticated and have active status
|
|
19
|
+
*
|
|
20
|
+
* 3. LIMITS AND CONSTRAINTS:
|
|
21
|
+
* - Can only send messages to groups that OA has joined
|
|
22
|
+
* - Cannot send messages to private groups that OA hasn't been invited to
|
|
23
|
+
* - Must comply with Zalo's message sending frequency limits
|
|
24
|
+
* - Message content must comply with Zalo's content policy
|
|
25
|
+
*
|
|
26
|
+
* 4. SUPPORTED MESSAGE TYPES:
|
|
27
|
+
* - Text message: Plain text messages
|
|
28
|
+
* - Image message: Image messages (JPG, PNG, GIF - max 5MB)
|
|
29
|
+
* - File message: File attachments (max 25MB)
|
|
30
|
+
* - Sticker message: Stickers from Zalo collection
|
|
31
|
+
* - Mention message: Tag/mention specific members
|
|
32
|
+
*
|
|
33
|
+
* 5. TECHNICAL REQUIREMENTS:
|
|
34
|
+
* - Use HTTPS for all API calls
|
|
35
|
+
* - Content-Type: application/json for text/mention messages
|
|
36
|
+
* - Content-Type: multipart/form-data for file/image uploads
|
|
37
|
+
*/
|
|
38
|
+
class GroupMessageService {
|
|
39
|
+
constructor(client) {
|
|
40
|
+
this.client = client;
|
|
41
|
+
this.apiUrl = "https://openapi.zalo.me/v3.0/oa";
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Send text message to group
|
|
45
|
+
* @param accessToken OA access token
|
|
46
|
+
* @param groupId Group ID
|
|
47
|
+
* @param message Text message content
|
|
48
|
+
* @returns Send result
|
|
49
|
+
*/
|
|
50
|
+
async sendTextMessage(accessToken, groupId, message) {
|
|
51
|
+
try {
|
|
52
|
+
const response = await this.client.apiPost(`${this.apiUrl}/message/group`, accessToken, {
|
|
53
|
+
recipient: {
|
|
54
|
+
group_id: groupId,
|
|
55
|
+
},
|
|
56
|
+
message: {
|
|
57
|
+
text: message.text,
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
return response;
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
throw this.handleGroupMessageError(error, "Failed to send text message to group");
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Send image message to group
|
|
68
|
+
* @param accessToken OA access token
|
|
69
|
+
* @param groupId Group ID
|
|
70
|
+
* @param message Image message content
|
|
71
|
+
* @returns Send result
|
|
72
|
+
*/
|
|
73
|
+
async sendImageMessage(accessToken, groupId, message) {
|
|
74
|
+
try {
|
|
75
|
+
const response = await this.client.apiPost(`${this.apiUrl}/message/group`, accessToken, {
|
|
76
|
+
recipient: {
|
|
77
|
+
group_id: groupId,
|
|
78
|
+
},
|
|
79
|
+
message: {
|
|
80
|
+
attachment: {
|
|
81
|
+
type: "template",
|
|
82
|
+
payload: {
|
|
83
|
+
template_type: "media",
|
|
84
|
+
elements: [
|
|
85
|
+
{
|
|
86
|
+
media_type: "image",
|
|
87
|
+
url: message.imageUrl,
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
return response;
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
throw this.handleGroupMessageError(error, "Failed to send image message to group");
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Send file message to group
|
|
102
|
+
* @param accessToken OA access token
|
|
103
|
+
* @param groupId Group ID
|
|
104
|
+
* @param message File message content
|
|
105
|
+
* @returns Send result
|
|
106
|
+
*/
|
|
107
|
+
async sendFileMessage(accessToken, groupId, message) {
|
|
108
|
+
try {
|
|
109
|
+
const response = await this.client.apiPost(`${this.apiUrl}/message/group`, accessToken, {
|
|
110
|
+
recipient: {
|
|
111
|
+
group_id: groupId,
|
|
112
|
+
},
|
|
113
|
+
message: {
|
|
114
|
+
attachment: {
|
|
115
|
+
type: "file",
|
|
116
|
+
payload: {
|
|
117
|
+
url: message.fileUrl,
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
return response;
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
throw this.handleGroupMessageError(error, "Failed to send file message to group");
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Send sticker message to group
|
|
130
|
+
* @param accessToken OA access token
|
|
131
|
+
* @param groupId Group ID
|
|
132
|
+
* @param message Sticker message content
|
|
133
|
+
* @returns Send result
|
|
134
|
+
*/
|
|
135
|
+
async sendStickerMessage(accessToken, groupId, message) {
|
|
136
|
+
try {
|
|
137
|
+
const response = await this.client.apiPost(`${this.apiUrl}/message/group`, accessToken, {
|
|
138
|
+
recipient: {
|
|
139
|
+
group_id: groupId,
|
|
140
|
+
},
|
|
141
|
+
message: {
|
|
142
|
+
attachment: {
|
|
143
|
+
type: "template",
|
|
144
|
+
payload: {
|
|
145
|
+
template_type: "media",
|
|
146
|
+
elements: [
|
|
147
|
+
{
|
|
148
|
+
media_type: "sticker",
|
|
149
|
+
attachment_id: message.stickerId,
|
|
150
|
+
},
|
|
151
|
+
],
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
});
|
|
156
|
+
return response;
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
throw this.handleGroupMessageError(error, "Failed to send sticker message to group");
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Send mention message to group
|
|
164
|
+
* @param accessToken OA access token
|
|
165
|
+
* @param groupId Group ID
|
|
166
|
+
* @param message Mention message content
|
|
167
|
+
* @returns Send result
|
|
168
|
+
*/
|
|
169
|
+
async sendMentionMessage(accessToken, groupId, message) {
|
|
170
|
+
try {
|
|
171
|
+
const response = await this.client.apiPost(`${this.apiUrl}/message/group`, accessToken, {
|
|
172
|
+
recipient: {
|
|
173
|
+
group_id: groupId,
|
|
174
|
+
},
|
|
175
|
+
message: {
|
|
176
|
+
text: message.text,
|
|
177
|
+
mention: message.mentions,
|
|
178
|
+
},
|
|
179
|
+
});
|
|
180
|
+
return response;
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
throw this.handleGroupMessageError(error, "Failed to send mention message to group");
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Get group information
|
|
188
|
+
* @param accessToken OA access token
|
|
189
|
+
* @param groupId Group ID
|
|
190
|
+
* @returns Group information
|
|
191
|
+
*/
|
|
192
|
+
async getGroupInfo(accessToken, groupId) {
|
|
193
|
+
try {
|
|
194
|
+
const response = await this.client.apiGet(`${this.apiUrl}/group/getinfo`, accessToken, {
|
|
195
|
+
group_id: groupId,
|
|
196
|
+
});
|
|
197
|
+
return response;
|
|
198
|
+
}
|
|
199
|
+
catch (error) {
|
|
200
|
+
throw this.handleGroupMessageError(error, "Failed to get group information");
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Get group members
|
|
205
|
+
* @param accessToken OA access token
|
|
206
|
+
* @param groupId Group ID
|
|
207
|
+
* @param offset Offset for pagination
|
|
208
|
+
* @param count Number of members to retrieve
|
|
209
|
+
* @returns Group members list
|
|
210
|
+
*/
|
|
211
|
+
async getGroupMembers(accessToken, groupId, offset = 0, count = 50) {
|
|
212
|
+
try {
|
|
213
|
+
const response = await this.client.apiGet(`${this.apiUrl}/group/getmembers`, accessToken, {
|
|
214
|
+
group_id: groupId,
|
|
215
|
+
offset,
|
|
216
|
+
count,
|
|
217
|
+
});
|
|
218
|
+
return response;
|
|
219
|
+
}
|
|
220
|
+
catch (error) {
|
|
221
|
+
throw this.handleGroupMessageError(error, "Failed to get group members");
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
handleGroupMessageError(error, defaultMessage) {
|
|
225
|
+
if (error.response?.data) {
|
|
226
|
+
const errorData = error.response.data;
|
|
227
|
+
return new Error(`${defaultMessage}: ${errorData.message || errorData.error || "Unknown error"}`);
|
|
228
|
+
}
|
|
229
|
+
return new Error(`${defaultMessage}: ${error.message || "Unknown error"}`);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
exports.GroupMessageService = GroupMessageService;
|
|
233
|
+
//# sourceMappingURL=group-message.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"group-message.service.js","sourceRoot":"","sources":["../../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M,IAAI,CAAC,MAAM,CAAC,MAAM,CAGtC,GAAG,IAAI,CAAC,MAAM,mBAAmB,EAAE,WAAW,EAAE;gBACjD,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;AAlRD,kDAkRC"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { ZaloClient } from "../clients/zalo-client";
|
|
2
|
+
/**
|
|
3
|
+
* Interface cho thông tin quota tin nhắn
|
|
4
|
+
*/
|
|
5
|
+
export interface MessageQuotaInfo {
|
|
6
|
+
quota: number;
|
|
7
|
+
used: number;
|
|
8
|
+
remaining: number;
|
|
9
|
+
reset_time: number;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Interface cho tin nhắn trong cuộc hội thoại
|
|
13
|
+
*/
|
|
14
|
+
export interface ConversationMessage {
|
|
15
|
+
message_id: string;
|
|
16
|
+
from_id: string;
|
|
17
|
+
to_id: string;
|
|
18
|
+
message: {
|
|
19
|
+
text?: string;
|
|
20
|
+
attachment?: {
|
|
21
|
+
type: string;
|
|
22
|
+
payload: any;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
timestamp: number;
|
|
26
|
+
type: "incoming" | "outgoing";
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Interface cho cuộc hội thoại
|
|
30
|
+
*/
|
|
31
|
+
export interface Conversation {
|
|
32
|
+
conversation_id: string;
|
|
33
|
+
user_id: string;
|
|
34
|
+
last_message: ConversationMessage;
|
|
35
|
+
unread_count: number;
|
|
36
|
+
updated_time: number;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Interface cho kết quả upload file
|
|
40
|
+
*/
|
|
41
|
+
export interface UploadResult {
|
|
42
|
+
attachment_id: string;
|
|
43
|
+
url: string;
|
|
44
|
+
type: string;
|
|
45
|
+
size: number;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Interface cho thông tin phân trang tin nhắn
|
|
49
|
+
*/
|
|
50
|
+
export interface MessagePagination {
|
|
51
|
+
offset: number;
|
|
52
|
+
count: number;
|
|
53
|
+
total: number;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Service xử lý các API quản lý tin nhắn của Zalo Official Account
|
|
57
|
+
*
|
|
58
|
+
* Bao gồm các chức năng:
|
|
59
|
+
* - Kiểm tra hạn mức gửi tin nhắn
|
|
60
|
+
* - Lấy danh sách tin nhắn trong cuộc hội thoại
|
|
61
|
+
* - Lấy danh sách cuộc hội thoại
|
|
62
|
+
* - Upload file và hình ảnh
|
|
63
|
+
* - Quản lý trạng thái tin nhắn
|
|
64
|
+
*
|
|
65
|
+
* ĐIỀU KIỆN SỬ DỤNG:
|
|
66
|
+
*
|
|
67
|
+
* 1. KIỂM TRA HẠN MỨC:
|
|
68
|
+
* - Cần quyền truy cập thông tin quota từ Zalo
|
|
69
|
+
* - Quota được reset hàng ngày vào 00:00 GMT+7
|
|
70
|
+
*
|
|
71
|
+
* 2. LẤY TIN NHẮN:
|
|
72
|
+
* - Chỉ có thể lấy tin nhắn trong vòng 7 ngày gần nhất
|
|
73
|
+
* - Tối đa 50 tin nhắn mỗi lần gọi API
|
|
74
|
+
*
|
|
75
|
+
* 3. UPLOAD FILE:
|
|
76
|
+
* - Kích thước tối đa 25MB
|
|
77
|
+
* - Hỗ trợ các định dạng: PDF, DOC, DOCX, XLS, XLSX, PPT, PPTX
|
|
78
|
+
*
|
|
79
|
+
* 4. UPLOAD HÌNH ẢNH:
|
|
80
|
+
* - Kích thước tối đa 5MB
|
|
81
|
+
* - Hỗ trợ các định dạng: JPG, PNG, GIF
|
|
82
|
+
*/
|
|
83
|
+
export declare class MessageManagementService {
|
|
84
|
+
private readonly client;
|
|
85
|
+
private readonly baseApiUrl;
|
|
86
|
+
private readonly uploadApiUrl;
|
|
87
|
+
constructor(client: ZaloClient);
|
|
88
|
+
/**
|
|
89
|
+
* Kiểm tra hạn mức gửi tin nhắn đến user cụ thể
|
|
90
|
+
* @param accessToken Access token của Official Account
|
|
91
|
+
* @param userId ID của người dùng Zalo
|
|
92
|
+
* @returns Thông tin hạn mức gửi tin nhắn
|
|
93
|
+
*/
|
|
94
|
+
checkMessageQuota(accessToken: string, userId: string): Promise<MessageQuotaInfo>;
|
|
95
|
+
/**
|
|
96
|
+
* Lấy danh sách tin nhắn trong cuộc hội thoại với user
|
|
97
|
+
* @param accessToken Access token của Official Account
|
|
98
|
+
* @param userId ID của người dùng Zalo
|
|
99
|
+
* @param offset Vị trí bắt đầu lấy tin nhắn (mặc định: 0)
|
|
100
|
+
* @param count Số lượng tin nhắn cần lấy (mặc định: 20, tối đa: 50)
|
|
101
|
+
* @returns Danh sách tin nhắn và thông tin phân trang
|
|
102
|
+
*/
|
|
103
|
+
getConversationMessages(accessToken: string, userId: string, offset?: number, count?: number): Promise<{
|
|
104
|
+
messages: ConversationMessage[];
|
|
105
|
+
pagination: MessagePagination;
|
|
106
|
+
}>;
|
|
107
|
+
/**
|
|
108
|
+
* Lấy danh sách cuộc hội thoại gần đây
|
|
109
|
+
* @param accessToken Access token của Official Account
|
|
110
|
+
* @param offset Vị trí bắt đầu lấy cuộc hội thoại (mặc định: 0)
|
|
111
|
+
* @param count Số lượng cuộc hội thoại cần lấy (mặc định: 20, tối đa: 50)
|
|
112
|
+
* @returns Danh sách cuộc hội thoại và thông tin phân trang
|
|
113
|
+
*/
|
|
114
|
+
getRecentConversations(accessToken: string, offset?: number, count?: number): Promise<{
|
|
115
|
+
conversations: Conversation[];
|
|
116
|
+
pagination: MessagePagination;
|
|
117
|
+
}>;
|
|
118
|
+
/**
|
|
119
|
+
* Upload file để sử dụng trong tin nhắn
|
|
120
|
+
* @param accessToken Access token của Official Account
|
|
121
|
+
* @param fileData Dữ liệu file (base64 hoặc buffer)
|
|
122
|
+
* @param fileName Tên file
|
|
123
|
+
* @returns Thông tin file đã upload
|
|
124
|
+
*/
|
|
125
|
+
uploadFile(accessToken: string, fileData: string | Buffer, fileName: string): Promise<UploadResult>;
|
|
126
|
+
/**
|
|
127
|
+
* Upload hình ảnh để sử dụng trong tin nhắn
|
|
128
|
+
* @param accessToken Access token của Official Account
|
|
129
|
+
* @param imageData Dữ liệu hình ảnh (base64 hoặc buffer)
|
|
130
|
+
* @param fileName Tên file hình ảnh
|
|
131
|
+
* @returns Thông tin hình ảnh đã upload
|
|
132
|
+
*/
|
|
133
|
+
uploadImage(accessToken: string, imageData: string | Buffer, fileName: string): Promise<UploadResult>;
|
|
134
|
+
}
|
|
135
|
+
//# sourceMappingURL=message-management.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message-management.service.d.ts","sourceRoot":"","sources":["../../src/services/message-management.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAGpD;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;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