@warriorteam/redai-zalo-sdk 1.6.0 ā 1.6.2
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 +304 -304
- package/UPDATE_ARTICLE_STATUS.md +152 -0
- package/dist/services/article.service.d.ts +10 -1
- package/dist/services/article.service.d.ts.map +1 -1
- package/dist/services/article.service.js +65 -0
- package/dist/services/article.service.js.map +1 -1
- package/docs/ARTICLE_MANAGEMENT.md +60 -1
- package/docs/CONSULTATION_SERVICE.md +512 -512
- package/docs/GROUP_MANAGEMENT.md +232 -232
- package/docs/USER_MANAGEMENT.md +481 -481
- package/docs/WEBHOOK_EVENTS.md +858 -858
- package/examples/article-status-update.ts +178 -0
- package/examples/user-list-post-example.ts +186 -186
- package/package.json +3 -2
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Example: Update Article Status
|
|
3
|
+
*
|
|
4
|
+
* Demonstrates how to update article status using the RedAI Zalo SDK
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { ZaloSDK, ArticleStatus, CommentStatus } from '../src';
|
|
8
|
+
|
|
9
|
+
async function updateArticleStatusExample() {
|
|
10
|
+
// Initialize SDK
|
|
11
|
+
const sdk = new ZaloSDK();
|
|
12
|
+
|
|
13
|
+
// Your access token
|
|
14
|
+
const accessToken = 'YOUR_ACCESS_TOKEN';
|
|
15
|
+
|
|
16
|
+
// Article ID to update
|
|
17
|
+
const articleId = 'YOUR_ARTICLE_ID';
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
console.log('š Updating article status...');
|
|
21
|
+
|
|
22
|
+
// Example 1: Update status to 'show' (publish)
|
|
23
|
+
const publishResult = await sdk.article.updateArticleStatus(
|
|
24
|
+
accessToken,
|
|
25
|
+
articleId,
|
|
26
|
+
ArticleStatus.SHOW
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
console.log('ā
Article published successfully!');
|
|
30
|
+
console.log('Update token:', publishResult.token);
|
|
31
|
+
|
|
32
|
+
// Wait a moment before next update
|
|
33
|
+
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
34
|
+
|
|
35
|
+
// Example 2: Update status to 'hide' (unpublish) and disable comments
|
|
36
|
+
const hideResult = await sdk.article.updateArticleStatus(
|
|
37
|
+
accessToken,
|
|
38
|
+
articleId,
|
|
39
|
+
ArticleStatus.HIDE,
|
|
40
|
+
CommentStatus.HIDE
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
console.log('ā
Article hidden successfully!');
|
|
44
|
+
console.log('Update token:', hideResult.token);
|
|
45
|
+
|
|
46
|
+
// Example 3: Check update progress
|
|
47
|
+
console.log('š Checking update progress...');
|
|
48
|
+
const progress = await sdk.article.checkArticleProcess(
|
|
49
|
+
accessToken,
|
|
50
|
+
hideResult.token
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
console.log('Update progress:', progress);
|
|
54
|
+
|
|
55
|
+
// Example 4: Get updated article details to verify changes
|
|
56
|
+
console.log('š Getting updated article details...');
|
|
57
|
+
const updatedArticle = await sdk.article.getArticleDetail(
|
|
58
|
+
accessToken,
|
|
59
|
+
articleId
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
console.log('Updated article status:', updatedArticle.status);
|
|
63
|
+
console.log('Updated comment status:', updatedArticle.comment);
|
|
64
|
+
|
|
65
|
+
} catch (error) {
|
|
66
|
+
console.error('ā Error updating article status:', error);
|
|
67
|
+
|
|
68
|
+
if (error instanceof Error) {
|
|
69
|
+
console.error('Error message:', error.message);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Advanced example: Batch status update
|
|
75
|
+
async function batchUpdateArticleStatus() {
|
|
76
|
+
const sdk = new ZaloSDK();
|
|
77
|
+
const accessToken = 'YOUR_ACCESS_TOKEN';
|
|
78
|
+
|
|
79
|
+
// List of article IDs to update
|
|
80
|
+
const articleIds = ['ARTICLE_ID_1', 'ARTICLE_ID_2', 'ARTICLE_ID_3'];
|
|
81
|
+
|
|
82
|
+
console.log('š Batch updating article statuses...');
|
|
83
|
+
|
|
84
|
+
const results = [];
|
|
85
|
+
|
|
86
|
+
for (const articleId of articleIds) {
|
|
87
|
+
try {
|
|
88
|
+
console.log(`Updating article ${articleId}...`);
|
|
89
|
+
|
|
90
|
+
const result = await sdk.article.updateArticleStatus(
|
|
91
|
+
accessToken,
|
|
92
|
+
articleId,
|
|
93
|
+
ArticleStatus.SHOW,
|
|
94
|
+
CommentStatus.SHOW
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
results.push({
|
|
98
|
+
articleId,
|
|
99
|
+
success: true,
|
|
100
|
+
token: result.token
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
console.log(`ā
Article ${articleId} updated successfully`);
|
|
104
|
+
|
|
105
|
+
// Add delay to avoid rate limiting
|
|
106
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
107
|
+
|
|
108
|
+
} catch (error) {
|
|
109
|
+
console.error(`ā Failed to update article ${articleId}:`, error);
|
|
110
|
+
|
|
111
|
+
results.push({
|
|
112
|
+
articleId,
|
|
113
|
+
success: false,
|
|
114
|
+
error: error instanceof Error ? error.message : 'Unknown error'
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
console.log('š Batch update results:', results);
|
|
120
|
+
return results;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Example with error handling and retry logic
|
|
124
|
+
async function updateArticleStatusWithRetry() {
|
|
125
|
+
const sdk = new ZaloSDK();
|
|
126
|
+
const accessToken = 'YOUR_ACCESS_TOKEN';
|
|
127
|
+
const articleId = 'YOUR_ARTICLE_ID';
|
|
128
|
+
const maxRetries = 3;
|
|
129
|
+
|
|
130
|
+
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
|
131
|
+
try {
|
|
132
|
+
console.log(`š Attempt ${attempt}/${maxRetries}: Updating article status...`);
|
|
133
|
+
|
|
134
|
+
const result = await sdk.article.updateArticleStatus(
|
|
135
|
+
accessToken,
|
|
136
|
+
articleId,
|
|
137
|
+
ArticleStatus.SHOW
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
console.log('ā
Article status updated successfully!');
|
|
141
|
+
console.log('Update token:', result.token);
|
|
142
|
+
|
|
143
|
+
return result;
|
|
144
|
+
|
|
145
|
+
} catch (error) {
|
|
146
|
+
console.error(`ā Attempt ${attempt} failed:`, error);
|
|
147
|
+
|
|
148
|
+
if (attempt === maxRetries) {
|
|
149
|
+
console.error('š« All retry attempts failed');
|
|
150
|
+
throw error;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Wait before retry (exponential backoff)
|
|
154
|
+
const delay = Math.pow(2, attempt) * 1000;
|
|
155
|
+
console.log(`ā³ Waiting ${delay}ms before retry...`);
|
|
156
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// Run examples
|
|
162
|
+
if (require.main === module) {
|
|
163
|
+
console.log('š Running Article Status Update Examples...\n');
|
|
164
|
+
|
|
165
|
+
// Uncomment the example you want to run:
|
|
166
|
+
|
|
167
|
+
// updateArticleStatusExample();
|
|
168
|
+
// batchUpdateArticleStatus();
|
|
169
|
+
// updateArticleStatusWithRetry();
|
|
170
|
+
|
|
171
|
+
console.log('\nš” Remember to replace YOUR_ACCESS_TOKEN and YOUR_ARTICLE_ID with actual values!');
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export {
|
|
175
|
+
updateArticleStatusExample,
|
|
176
|
+
batchUpdateArticleStatus,
|
|
177
|
+
updateArticleStatusWithRetry
|
|
178
|
+
};
|
|
@@ -1,186 +1,186 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Example: Using POST method to get user list
|
|
3
|
-
* Demonstrates the new postUserList method in UserService
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { ZaloSDK, UserListRequest } from "../src/index";
|
|
7
|
-
|
|
8
|
-
async function demonstratePostUserList() {
|
|
9
|
-
// Initialize SDK
|
|
10
|
-
const zalo = new ZaloSDK({
|
|
11
|
-
appId: "your-app-id",
|
|
12
|
-
appSecret: "your-app-secret"
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
const accessToken = "your-access-token";
|
|
16
|
-
|
|
17
|
-
try {
|
|
18
|
-
console.log("=== POST User List Example ===\n");
|
|
19
|
-
|
|
20
|
-
// Example 1: Basic user list with POST method
|
|
21
|
-
console.log("1. Getting user list with POST method:");
|
|
22
|
-
const basicRequest: UserListRequest = {
|
|
23
|
-
offset: 0,
|
|
24
|
-
count: 10
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
const basicResult = await zalo.user.postUserList(accessToken, basicRequest);
|
|
28
|
-
console.log("Basic POST result:", {
|
|
29
|
-
total: basicResult.total,
|
|
30
|
-
userCount: basicResult.users.length,
|
|
31
|
-
users: basicResult.users.map(user => ({
|
|
32
|
-
user_id: user.user_id,
|
|
33
|
-
display_name: user.display_name,
|
|
34
|
-
user_is_follower: user.user_is_follower
|
|
35
|
-
}))
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
// Example 2: Filtered user list with tag
|
|
39
|
-
console.log("\n2. Getting users with specific tag (POST method):");
|
|
40
|
-
const taggedRequest: UserListRequest = {
|
|
41
|
-
offset: 0,
|
|
42
|
-
count: 20,
|
|
43
|
-
tag_name: "VIP_CUSTOMER"
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
const taggedResult = await zalo.user.postUserList(accessToken, taggedRequest);
|
|
47
|
-
console.log("Tagged users POST result:", {
|
|
48
|
-
total: taggedResult.total,
|
|
49
|
-
userCount: taggedResult.users.length,
|
|
50
|
-
tag_filter: "VIP_CUSTOMER"
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
// Example 3: Followers only with POST method
|
|
54
|
-
console.log("\n3. Getting followers only (POST method):");
|
|
55
|
-
const followersRequest: UserListRequest = {
|
|
56
|
-
offset: 0,
|
|
57
|
-
count: 15,
|
|
58
|
-
is_follower: true
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
const followersResult = await zalo.user.postUserList(accessToken, followersRequest);
|
|
62
|
-
console.log("Followers POST result:", {
|
|
63
|
-
total: followersResult.total,
|
|
64
|
-
userCount: followersResult.users.length,
|
|
65
|
-
followers_only: true
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
// Example 4: Users with recent interaction (POST method)
|
|
69
|
-
console.log("\n4. Getting users with recent interaction (POST method):");
|
|
70
|
-
const recentRequest: UserListRequest = {
|
|
71
|
-
offset: 0,
|
|
72
|
-
count: 25,
|
|
73
|
-
last_interaction_period: "7d" // Last 7 days
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
const recentResult = await zalo.user.postUserList(accessToken, recentRequest);
|
|
77
|
-
console.log("Recent interaction POST result:", {
|
|
78
|
-
total: recentResult.total,
|
|
79
|
-
userCount: recentResult.users.length,
|
|
80
|
-
interaction_period: "7d"
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
// Example 5: Compare GET vs POST methods
|
|
84
|
-
console.log("\n5. Comparing GET vs POST methods:");
|
|
85
|
-
|
|
86
|
-
const compareRequest: UserListRequest = {
|
|
87
|
-
offset: 0,
|
|
88
|
-
count: 5
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
// GET method
|
|
92
|
-
const getResult = await zalo.user.getUserList(accessToken, compareRequest);
|
|
93
|
-
console.log("GET method result:", {
|
|
94
|
-
total: getResult.total,
|
|
95
|
-
userCount: getResult.users.length,
|
|
96
|
-
method: "GET"
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
// POST method
|
|
100
|
-
const postResult = await zalo.user.postUserList(accessToken, compareRequest);
|
|
101
|
-
console.log("POST method result:", {
|
|
102
|
-
total: postResult.total,
|
|
103
|
-
userCount: postResult.users.length,
|
|
104
|
-
method: "POST"
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
console.log("Results should be identical:", {
|
|
108
|
-
totals_match: getResult.total === postResult.total,
|
|
109
|
-
counts_match: getResult.users.length === postResult.users.length
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
} catch (error) {
|
|
113
|
-
console.error("Error in POST user list example:", error);
|
|
114
|
-
|
|
115
|
-
if (error instanceof Error) {
|
|
116
|
-
console.error("Error details:", {
|
|
117
|
-
name: error.name,
|
|
118
|
-
message: error.message,
|
|
119
|
-
stack: error.stack
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// Example usage with pagination using POST method
|
|
126
|
-
async function demonstratePaginationWithPost() {
|
|
127
|
-
const zalo = new ZaloSDK({
|
|
128
|
-
appId: "your-app-id",
|
|
129
|
-
appSecret: "your-app-secret"
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
const accessToken = "your-access-token";
|
|
133
|
-
|
|
134
|
-
try {
|
|
135
|
-
console.log("\n=== POST Method Pagination Example ===\n");
|
|
136
|
-
|
|
137
|
-
let offset = 0;
|
|
138
|
-
const count = 10;
|
|
139
|
-
let allUsers: any[] = [];
|
|
140
|
-
let totalUsers = 0;
|
|
141
|
-
|
|
142
|
-
do {
|
|
143
|
-
const request: UserListRequest = {
|
|
144
|
-
offset,
|
|
145
|
-
count
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
const result = await zalo.user.postUserList(accessToken, request);
|
|
149
|
-
|
|
150
|
-
console.log(`Page ${Math.floor(offset / count) + 1}:`, {
|
|
151
|
-
offset,
|
|
152
|
-
returned: result.users.length,
|
|
153
|
-
total: result.total
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
allUsers.push(...result.users);
|
|
157
|
-
totalUsers = result.total;
|
|
158
|
-
offset += count;
|
|
159
|
-
|
|
160
|
-
// Break if we've got all users or no more users returned
|
|
161
|
-
if (result.users.length < count || allUsers.length >= totalUsers) {
|
|
162
|
-
break;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
} while (true);
|
|
166
|
-
|
|
167
|
-
console.log("\nPagination complete:", {
|
|
168
|
-
total_users: totalUsers,
|
|
169
|
-
fetched_users: allUsers.length,
|
|
170
|
-
method: "POST"
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
} catch (error) {
|
|
174
|
-
console.error("Error in POST pagination example:", error);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
// Run examples
|
|
179
|
-
if (require.main === module) {
|
|
180
|
-
demonstratePostUserList()
|
|
181
|
-
.then(() => demonstratePaginationWithPost())
|
|
182
|
-
.then(() => console.log("\nā
POST User List examples completed!"))
|
|
183
|
-
.catch(error => console.error("ā Example failed:", error));
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
export { demonstratePostUserList, demonstratePaginationWithPost };
|
|
1
|
+
/**
|
|
2
|
+
* Example: Using POST method to get user list
|
|
3
|
+
* Demonstrates the new postUserList method in UserService
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { ZaloSDK, UserListRequest } from "../src/index";
|
|
7
|
+
|
|
8
|
+
async function demonstratePostUserList() {
|
|
9
|
+
// Initialize SDK
|
|
10
|
+
const zalo = new ZaloSDK({
|
|
11
|
+
appId: "your-app-id",
|
|
12
|
+
appSecret: "your-app-secret"
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
const accessToken = "your-access-token";
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
console.log("=== POST User List Example ===\n");
|
|
19
|
+
|
|
20
|
+
// Example 1: Basic user list with POST method
|
|
21
|
+
console.log("1. Getting user list with POST method:");
|
|
22
|
+
const basicRequest: UserListRequest = {
|
|
23
|
+
offset: 0,
|
|
24
|
+
count: 10
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const basicResult = await zalo.user.postUserList(accessToken, basicRequest);
|
|
28
|
+
console.log("Basic POST result:", {
|
|
29
|
+
total: basicResult.total,
|
|
30
|
+
userCount: basicResult.users.length,
|
|
31
|
+
users: basicResult.users.map(user => ({
|
|
32
|
+
user_id: user.user_id,
|
|
33
|
+
display_name: user.display_name,
|
|
34
|
+
user_is_follower: user.user_is_follower
|
|
35
|
+
}))
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// Example 2: Filtered user list with tag
|
|
39
|
+
console.log("\n2. Getting users with specific tag (POST method):");
|
|
40
|
+
const taggedRequest: UserListRequest = {
|
|
41
|
+
offset: 0,
|
|
42
|
+
count: 20,
|
|
43
|
+
tag_name: "VIP_CUSTOMER"
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const taggedResult = await zalo.user.postUserList(accessToken, taggedRequest);
|
|
47
|
+
console.log("Tagged users POST result:", {
|
|
48
|
+
total: taggedResult.total,
|
|
49
|
+
userCount: taggedResult.users.length,
|
|
50
|
+
tag_filter: "VIP_CUSTOMER"
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
// Example 3: Followers only with POST method
|
|
54
|
+
console.log("\n3. Getting followers only (POST method):");
|
|
55
|
+
const followersRequest: UserListRequest = {
|
|
56
|
+
offset: 0,
|
|
57
|
+
count: 15,
|
|
58
|
+
is_follower: true
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const followersResult = await zalo.user.postUserList(accessToken, followersRequest);
|
|
62
|
+
console.log("Followers POST result:", {
|
|
63
|
+
total: followersResult.total,
|
|
64
|
+
userCount: followersResult.users.length,
|
|
65
|
+
followers_only: true
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
// Example 4: Users with recent interaction (POST method)
|
|
69
|
+
console.log("\n4. Getting users with recent interaction (POST method):");
|
|
70
|
+
const recentRequest: UserListRequest = {
|
|
71
|
+
offset: 0,
|
|
72
|
+
count: 25,
|
|
73
|
+
last_interaction_period: "7d" // Last 7 days
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const recentResult = await zalo.user.postUserList(accessToken, recentRequest);
|
|
77
|
+
console.log("Recent interaction POST result:", {
|
|
78
|
+
total: recentResult.total,
|
|
79
|
+
userCount: recentResult.users.length,
|
|
80
|
+
interaction_period: "7d"
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
// Example 5: Compare GET vs POST methods
|
|
84
|
+
console.log("\n5. Comparing GET vs POST methods:");
|
|
85
|
+
|
|
86
|
+
const compareRequest: UserListRequest = {
|
|
87
|
+
offset: 0,
|
|
88
|
+
count: 5
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// GET method
|
|
92
|
+
const getResult = await zalo.user.getUserList(accessToken, compareRequest);
|
|
93
|
+
console.log("GET method result:", {
|
|
94
|
+
total: getResult.total,
|
|
95
|
+
userCount: getResult.users.length,
|
|
96
|
+
method: "GET"
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
// POST method
|
|
100
|
+
const postResult = await zalo.user.postUserList(accessToken, compareRequest);
|
|
101
|
+
console.log("POST method result:", {
|
|
102
|
+
total: postResult.total,
|
|
103
|
+
userCount: postResult.users.length,
|
|
104
|
+
method: "POST"
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
console.log("Results should be identical:", {
|
|
108
|
+
totals_match: getResult.total === postResult.total,
|
|
109
|
+
counts_match: getResult.users.length === postResult.users.length
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
} catch (error) {
|
|
113
|
+
console.error("Error in POST user list example:", error);
|
|
114
|
+
|
|
115
|
+
if (error instanceof Error) {
|
|
116
|
+
console.error("Error details:", {
|
|
117
|
+
name: error.name,
|
|
118
|
+
message: error.message,
|
|
119
|
+
stack: error.stack
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Example usage with pagination using POST method
|
|
126
|
+
async function demonstratePaginationWithPost() {
|
|
127
|
+
const zalo = new ZaloSDK({
|
|
128
|
+
appId: "your-app-id",
|
|
129
|
+
appSecret: "your-app-secret"
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
const accessToken = "your-access-token";
|
|
133
|
+
|
|
134
|
+
try {
|
|
135
|
+
console.log("\n=== POST Method Pagination Example ===\n");
|
|
136
|
+
|
|
137
|
+
let offset = 0;
|
|
138
|
+
const count = 10;
|
|
139
|
+
let allUsers: any[] = [];
|
|
140
|
+
let totalUsers = 0;
|
|
141
|
+
|
|
142
|
+
do {
|
|
143
|
+
const request: UserListRequest = {
|
|
144
|
+
offset,
|
|
145
|
+
count
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
const result = await zalo.user.postUserList(accessToken, request);
|
|
149
|
+
|
|
150
|
+
console.log(`Page ${Math.floor(offset / count) + 1}:`, {
|
|
151
|
+
offset,
|
|
152
|
+
returned: result.users.length,
|
|
153
|
+
total: result.total
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
allUsers.push(...result.users);
|
|
157
|
+
totalUsers = result.total;
|
|
158
|
+
offset += count;
|
|
159
|
+
|
|
160
|
+
// Break if we've got all users or no more users returned
|
|
161
|
+
if (result.users.length < count || allUsers.length >= totalUsers) {
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
} while (true);
|
|
166
|
+
|
|
167
|
+
console.log("\nPagination complete:", {
|
|
168
|
+
total_users: totalUsers,
|
|
169
|
+
fetched_users: allUsers.length,
|
|
170
|
+
method: "POST"
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
} catch (error) {
|
|
174
|
+
console.error("Error in POST pagination example:", error);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// Run examples
|
|
179
|
+
if (require.main === module) {
|
|
180
|
+
demonstratePostUserList()
|
|
181
|
+
.then(() => demonstratePaginationWithPost())
|
|
182
|
+
.then(() => console.log("\nā
POST User List examples completed!"))
|
|
183
|
+
.catch(error => console.error("ā Example failed:", error));
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export { demonstratePostUserList, demonstratePaginationWithPost };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@warriorteam/redai-zalo-sdk",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.2",
|
|
4
4
|
"description": "Comprehensive TypeScript/JavaScript SDK for Zalo APIs - Official Account, ZNS, Consultation Service, Group Messaging, and Social APIs",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -64,7 +64,8 @@
|
|
|
64
64
|
"examples/**/*",
|
|
65
65
|
"ARCHITECTURE.md",
|
|
66
66
|
"SERVICES_ADDED.md",
|
|
67
|
-
"CHANGELOG.md"
|
|
67
|
+
"CHANGELOG.md",
|
|
68
|
+
"UPDATE_ARTICLE_STATUS.md"
|
|
68
69
|
],
|
|
69
70
|
"engines": {
|
|
70
71
|
"node": ">=16.0.0"
|