@warriorteam/redai-zalo-sdk 1.12.0 ā 1.12.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/ARCHITECTURE.md +265 -0
- package/CHANGELOG.md +0 -57
- package/README.md +1 -33
- package/SERVICES_ADDED.md +540 -0
- package/UPDATE_ARTICLE_STATUS.md +152 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +22 -8
- package/dist/index.js.map +1 -1
- package/dist/types/webhook.d.ts +19 -25
- package/dist/types/webhook.d.ts.map +1 -1
- package/dist/types/webhook.js +1 -110
- package/dist/types/webhook.js.map +1 -1
- package/dist/utils/type-guards.d.ts +96 -0
- package/dist/utils/type-guards.d.ts.map +1 -0
- package/dist/utils/type-guards.js +192 -0
- package/dist/utils/type-guards.js.map +1 -0
- package/docs/ARTICLE_MANAGEMENT.md +395 -395
- package/docs/AUTHENTICATION.md +852 -853
- 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 -178
- package/examples/oa-auth-with-pkce.ts +179 -179
- package/examples/user-list-post-example.ts +186 -186
- package/examples/video-upload-combined.example.ts +228 -228
- package/examples/zns-template-edit.example.ts +317 -317
- package/package.json +1 -1
- package/docs/WEBHOOK_MESSAGE_HELPERS.md +0 -230
- package/examples/webhook-message-classification.ts +0 -285
|
@@ -1,178 +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
|
+
/**
|
|
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
|
+
};
|