@warriorteam/redai-zalo-sdk 1.12.0 → 1.12.1

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.
@@ -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 };