@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/SERVICES_ADDED.md DELETED
@@ -1,540 +0,0 @@
1
- # Services Added to RedAI Zalo SDK
2
-
3
- This document summarizes all the services that have been added to the RedAI Zalo SDK from the backend `redai-v201-be-app/src/shared/services/zalo` directory.
4
-
5
- ## New Services Added
6
-
7
- ### 1. ConsultationService (`src/services/consultation.service.ts`)
8
-
9
- **Purpose**: Customer Service messaging for sending consultation messages within 48-hour window
10
-
11
- **Key Features**:
12
-
13
- - Send consultation text messages
14
- - Send consultation image messages
15
- - Send consultation file messages
16
- - Send consultation sticker messages
17
- - Send general consultation messages
18
- - Automatic validation of message content
19
- - Built-in error handling and retry logic
20
- - 48-hour interaction window enforcement
21
-
22
- **Main Methods**:
23
-
24
- - `sendTextMessage()` - Send consultation text message (max 2000 characters)
25
- - `sendImageMessage()` - Send consultation image with support content
26
- - `sendFileMessage()` - Send consultation file attachments (guides, manuals)
27
- - `sendStickerMessage()` - Send consultation sticker messages
28
- - `sendMessage()` - Send any type of consultation message
29
-
30
- **Usage Conditions**:
31
-
32
- - Must be sent within 48 hours of last user interaction
33
- - Content must be consultation/support related (no direct advertising)
34
- - User must have followed the OA and not blocked it
35
- - No daily limit but must follow anti-spam guidelines
36
-
37
- **Integration**:
38
-
39
- - Accessible via `zalo.consultation` property
40
- - Quick methods: `zalo.sendConsultationText()`, `zalo.sendConsultationImage()`
41
- - Full webhook integration support
42
- - Comprehensive error handling with ZaloSDKError
43
-
44
- ### 2. ZNSService (`src/services/zns.service.ts`)
45
-
46
- **Purpose**: Zalo Notification Service for sending template-based notifications
47
-
48
- **Key Features**:
49
-
50
- - Send ZNS messages with templates
51
- - Send hash phone messages
52
- - Send development mode messages
53
- - Send RSA encrypted messages
54
- - Send journey messages
55
- - Get message status
56
- - Get quota information
57
- - Template management (create, update, delete, list)
58
- - Image upload for templates
59
-
60
- **Main Methods**:
61
-
62
- - `sendMessage()` - Send ZNS notification
63
- - `sendHashPhoneMessage()` - Send with hashed phone
64
- - `sendDevModeMessage()` - Send in development mode
65
- - `getMessageStatus()` - Check message delivery status
66
- - `getQuotaInfo()` - Get remaining quota
67
- - `getTemplateList()` - List all templates
68
- - `createTemplate()` - Create new template
69
- - `updateTemplate()` - Update existing template
70
- - `deleteTemplate()` - Delete template
71
- - `uploadImage()` - Upload image for template
72
-
73
- ### 2. GroupMessageService (`src/services/group-message.service.ts`)
74
-
75
- **Purpose**: Group Message Framework for sending messages to Zalo groups
76
-
77
- **Key Features**:
78
-
79
- - Send text messages to groups
80
- - Send image messages to groups
81
- - Send file messages to groups
82
- - Send sticker messages to groups
83
- - Send mention messages to groups
84
- - Get group information
85
- - Get group members
86
-
87
- **Main Methods**:
88
-
89
- - `sendTextMessage()` - Send text to group
90
- - `sendImageMessage()` - Send image to group
91
- - `sendFileMessage()` - Send file to group
92
- - `sendStickerMessage()` - Send sticker to group
93
- - `sendMentionMessage()` - Send message with mentions
94
- - `getGroupInfo()` - Get group details
95
- - `getGroupMembers()` - Get group member list
96
-
97
- ### 3. GroupManagementService (`src/services/group-management.service.ts`)
98
-
99
- **Purpose**: Comprehensive group management for Zalo Official Account GMF
100
-
101
- **Key Features**:
102
-
103
- - Create and manage groups with asset_id
104
- - Member management (invite, remove, approve)
105
- - Admin management (add/remove admin rights)
106
- - Group information and settings management
107
- - Quota and asset management
108
- - Conversation history access
109
-
110
- **Main Methods**:
111
-
112
- - `createGroup()` - Create new group with asset_id
113
- - `getGroupInfo()` - Get detailed group information
114
- - `updateGroupInfo()` - Update group information
115
- - `updateGroupAvatar()` - Update group avatar
116
- - `inviteMembers()` - Invite members to group
117
- - `removeMembers()` - Remove members from group
118
- - `getPendingMembers()` - Get pending member requests
119
- - `acceptPendingMembers()` - Accept pending members
120
- - `rejectPendingMembers()` - Reject pending members
121
- - `addAdmins()` - Add admin rights to members
122
- - `removeAdmins()` - Remove admin rights from members
123
- - `deleteGroup()` - Delete/disband group
124
- - `getGroupsOfOA()` - Get list of OA groups
125
- - `getGroupQuota()` - Get group quota information
126
- - `getAssetId()` - Get asset_id for group creation
127
- - `getAssetIds()` - Get list of available asset_ids
128
- - `getRecentChats()` - Get recent chat conversations
129
- - `getGroupConversation()` - Get group conversation history
130
- - `getGroupMembers()` - Get group members list
131
-
132
- ### 4. ArticleService (`src/services/article.service.ts`)
133
-
134
- **Purpose**: Comprehensive article management for Zalo Official Account
135
-
136
- **Key Features**:
137
-
138
- - Create and manage normal articles with rich content
139
- - Create and manage video articles
140
- - Article validation and error handling
141
- - Progress tracking for article creation/updates
142
- - Article listing and detail retrieval
143
-
144
- **Main Methods**:
145
-
146
- - `createNormalArticle()` - Create normal article with rich content
147
- - `createVideoArticle()` - Create video article
148
- - `createArticle()` - Create article (auto-detect type)
149
- - `updateNormalArticle()` - Update normal article
150
- - `updateVideoArticle()` - Update video article
151
- - `updateArticle()` - Update article (auto-detect type)
152
- - `getArticleDetail()` - Get article details
153
- - `getArticleList()` - Get article list with pagination
154
- - `removeArticle()` - Remove/delete article
155
- - `checkArticleProcess()` - Check article creation progress
156
- - `verifyArticle()` - Verify article and get ID
157
-
158
- ### 5. VideoUploadService (`src/services/video-upload.service.ts`)
159
-
160
- **Purpose**: Video upload and management for articles
161
-
162
- **Key Features**:
163
-
164
- - Upload video files for articles
165
- - Video processing status tracking
166
- - Polling for upload completion
167
- - Video upload from URLs
168
- - Video file validation
169
-
170
- **Main Methods**:
171
-
172
- - `uploadVideo()` - Upload video file for articles
173
- - `checkVideoStatus()` - Check video processing status
174
- - `waitForUploadCompletion()` - Wait for upload completion with polling
175
- - `uploadVideoFromUrl()` - Upload video from URL
176
- - `getVideoInfo()` - Get video information by ID
177
-
178
- ### 6. Webhook Event DTOs (`src/types/webhook.ts`)
179
-
180
- **Purpose**: Comprehensive TypeScript types for Zalo webhook events
181
-
182
- **Key Features**:
183
-
184
- - Type-safe webhook event handling
185
- - Specific event types for each webhook event
186
- - Attachment payload types for different media types
187
- - Type guards and utility functions
188
- - Backward compatibility with legacy events
189
-
190
- **Event Types**:
191
-
192
- **User Message Events:**
193
-
194
- - `UserSendTextEvent` - User sends text message
195
- - `UserSendImageEvent` - User sends image message
196
- - `UserSendLocationEvent` - User sends location
197
- - `UserSendLinkEvent` - User sends link
198
- - `UserSendStickerEvent` - User sends sticker
199
- - `UserSendGifEvent` - User sends GIF
200
- - `UserSendAudioEvent` - User sends audio/voice
201
- - `UserSendVideoEvent` - User sends video message
202
- - `UserSendFileEvent` - User sends file attachment
203
- - `UserReceivedMessageEvent` - Message delivery confirmation
204
- - `UserSeenMessageEvent` - Message read confirmation
205
-
206
- **User Action Events:**
207
-
208
- - `UserFollowEvent` - User follows Official Account
209
- - `UserUnfollowEvent` - User unfollows Official Account
210
- - `UserSubmitInfoEvent` - User submits personal information
211
-
212
- **OA Message Events:**
213
-
214
- - `OASendTextEvent` - OA sends text message
215
- - `OASendImageEvent` - OA sends image message
216
- - `OASendGifEvent` - OA sends GIF message
217
- - `OASendListEvent` - OA sends interactive list message
218
- - `OASendFileEvent` - OA sends file attachment
219
- - `OASendStickerEvent` - OA sends sticker message
220
-
221
- **User Interaction Events:**
222
-
223
- - `UserClickChatNowEvent` - User clicks "Chat Now" button
224
- - `UserReactedMessageEvent` - User reacts to message with emoji
225
- - `UserReplyConsentEvent` - User replies to consent request
226
-
227
- **OA Interaction Events:**
228
-
229
- - `OAReactedMessageEvent` - OA reacts to message with emoji
230
- - `OASendConsentEvent` - OA sends consent request for call
231
-
232
- **Anonymous User Events:**
233
-
234
- - `AnonymousSendTextEvent` - Anonymous user sends text message
235
- - `AnonymousSendImageEvent` - Anonymous user sends image message
236
- - `AnonymousSendFileEvent` - Anonymous user sends file attachment
237
-
238
- **Shop Events:**
239
-
240
- - `ShopHasOrderEvent` - New order created
241
-
242
- **ZNS Events:**
243
-
244
- - `ChangeOADailyQuotaEvent` - OA daily quota changed
245
- - `ChangeOATemplateTagsEvent` - OA template tags changed
246
- - `ChangeTemplateQualityEvent` - Template quality changed
247
- - `ChangeTemplateQuotaEvent` - Template quota changed
248
- - `ChangeTemplateStatusEvent` - Template status changed
249
- - `JourneyTimeoutEvent` - Journey timeout
250
- - `JourneyAcknowledgedEvent` - Journey acknowledged/charged
251
- - `ZNSUserReceivedMessageEvent` - User received ZNS message
252
-
253
- **Group Events:**
254
-
255
- - `CreateGroupEvent` - Group created
256
- - `UserJoinGroupEvent` - User joined group
257
- - `UserRequestJoinGroupEvent` - User requested to join group
258
- - `ReactRequestJoinGroupEvent` - Join request approved
259
- - `RejectRequestJoinGroupEvent` - Join request rejected
260
- - `AddGroupAdminEvent` - Group admin added
261
- - `RemoveGroupAdminEvent` - Group admin removed
262
- - `UpdateGroupInfoEvent` - Group info updated
263
- - `UserOutGroupEvent` - User left group
264
- - `OASendGroupTextEvent` - OA sends text to group
265
- - `OASendGroupImageEvent` - OA sends image to group
266
- - `OASendGroupLinkEvent` - OA sends link to group
267
- - `OASendGroupAudioEvent` - OA sends audio to group
268
- - `OASendGroupLocationEvent` - OA sends location to group
269
- - `OASendGroupVideoEvent` - OA sends video to group
270
- - `OASendGroupBusinessCardEvent` - OA sends business card to group
271
- - `OASendGroupStickerEvent` - OA sends sticker to group
272
- - `OASendGroupGifEvent` - OA sends GIF to group
273
- - `OASendGroupFileEvent` - OA sends file to group
274
- - `UserSendGroupTextEvent` - User sends text to group
275
- - `UserSendGroupLinkEvent` - User sends link to group
276
- - `UserSendGroupAudioEvent` - User sends audio to group
277
- - `UserSendGroupLocationEvent` - User sends location to group
278
- - `UserSendGroupVideoEvent` - User sends video to group
279
- - `UserSendGroupBusinessCardEvent` - User sends business card to group
280
- - `UserSendGroupStickerEvent` - User sends sticker to group
281
- - `UserSendGroupGifEvent` - User sends GIF to group
282
- - `UserSendGroupFileEvent` - User sends file to group
283
-
284
- **Widget Events:**
285
-
286
- - `WidgetInteractionAcceptedEvent` - User accepted widget interaction
287
- - `WidgetFailedToSyncUserExternalIdEvent` - Failed to sync user external ID
288
-
289
- **System Events:**
290
-
291
- - `PermissionRevokedEvent` - Permission revoked between app and OA
292
- - `ExtensionPurchasedEvent` - OA purchased extension successfully
293
- - `UpdateUserInfoEvent` - User info updated
294
- - `AddUserToTagEvent` - User added to tag
295
-
296
- **Attachment Types**:
297
-
298
- - `LocationPayload` - GPS coordinates
299
- - `ImagePayload` - Image with thumbnail
300
- - `LinkPayload` - Link with preview
301
- - `StickerPayload` - Sticker with ID and URL
302
- - `GifPayload` - GIF with thumbnail
303
- - `AudioPayload` - Audio file URL
304
- - `VideoPayload` - Video with thumbnail and description
305
- - `FilePayload` - File with metadata (size, name, checksum, type)
306
- - `EnhancedLinkPayload` - Link with title for OA list messages
307
-
308
- **Utility Functions**:
309
-
310
- - `isMessageEvent()` - Type guard for all message events (user + OA + anonymous + group)
311
- - `isFollowEvent()` - Type guard for follow/unfollow events
312
- - `isUserActionEvent()` - Type guard for user action events (follow, click, react, consent, feedback)
313
- - `isShopEvent()` - Type guard for shop events
314
- - `isOAMessageEvent()` - Type guard for OA message events
315
- - `isAnonymousEvent()` - Type guard for anonymous user events
316
- - `isCallEvent()` - Type guard for call events (OA call user, user call OA)
317
- - `isReactionEvent()` - Type guard for reaction events (user + OA)
318
- - `isConsentEvent()` - Type guard for consent events (send + reply)
319
- - `isTemplateEvent()` - Type guard for template events
320
- - `isBusinessCardEvent()` - Type guard for business card events
321
- - `isFeedbackEvent()` - Type guard for feedback events
322
- - `isZNSEvent()` - Type guard for ZNS events (quota, template, journey, status)
323
- - `isGroupEvent()` - Type guard for group events (create, join, admin, all message types)
324
- - `isJourneyEvent()` - Type guard for journey events (timeout, acknowledged)
325
- - `isQuotaTemplateEvent()` - Type guard for quota/template change events
326
- - `isWidgetEvent()` - Type guard for widget events (interaction, sync)
327
- - `isSystemEvent()` - Type guard for system events (permission, extension, user info)
328
- - `isPermissionEvent()` - Type guard for permission events
329
- - `isExtensionEvent()` - Type guard for extension events
330
- - `isUpdateUserInfoEvent()` - Type guard for user info update events
331
- - `hasAttachments()` - Type guard for messages with attachments
332
-
333
- ### 7. SocialService (`src/services/social.service.ts`)
334
-
335
- **Purpose**: Zalo Social API for user authentication and social features
336
-
337
- **Key Features**:
338
-
339
- - PKCE (Proof Key for Code Exchange) support
340
- - OAuth 2.0 authentication flow
341
- - User information retrieval
342
- - Friends list management
343
- - Timeline posting
344
- - Message sending
345
- - Token validation and refresh
346
-
347
- **Main Methods**:
348
-
349
- - `generatePKCEPair()` - Generate PKCE for security
350
- - `generateAuthUrl()` - Create authorization URL
351
- - `getAccessToken()` - Exchange code for token
352
- - `refreshAccessToken()` - Refresh expired token
353
- - `getUserInfo()` - Get user profile
354
- - `getFriendsList()` - Get user's friends
355
- - `postToTimeline()` - Post to user timeline
356
- - `sendMessage()` - Send message to friend
357
- - `validateToken()` - Validate access token
358
-
359
- ### 4. UserManagementService (`src/services/user-management.service.ts`)
360
-
361
- **Purpose**: Comprehensive user management for OA
362
-
363
- **Key Features**:
364
-
365
- - User profile management
366
- - User search by phone
367
- - User tagging and segmentation
368
- - User notes management
369
- - User interaction tracking
370
- - Followers list management
371
-
372
- **Main Methods**:
373
-
374
- - `getUserProfile()` - Get detailed user profile
375
- - `getFollowersList()` - Get OA followers
376
- - `searchUserByPhone()` - Find user by phone number
377
- - `getUserTags()` - Get user's tags
378
- - `tagUser()` - Add tags to user
379
- - `untagUser()` - Remove tags from user
380
- - `getAllTags()` - Get all available tags
381
- - `createTag()` - Create new tag
382
- - `deleteTag()` - Delete tag
383
- - `addUserNote()` - Add note to user
384
- - `getUserNotes()` - Get user notes
385
- - `getUserInteractions()` - Get user interaction history
386
-
387
- ### 5. TagService (`src/services/tag.service.ts`)
388
-
389
- **Purpose**: Dedicated tag management service
390
-
391
- **Key Features**:
392
-
393
- - Tag creation and deletion
394
- - User tagging operations
395
- - Bulk tagging operations
396
- - Tag-based user retrieval
397
-
398
- **Main Methods**:
399
-
400
- - `getAllTags()` - Get all OA tags
401
- - `getUserTags()` - Get specific user's tags
402
- - `createTag()` - Create new tag
403
- - `deleteTag()` - Delete existing tag
404
- - `tagUser()` - Tag a user
405
- - `untagUser()` - Remove tags from user
406
- - `getUsersByTag()` - Get users with specific tag
407
- - `bulkTagUsers()` - Tag multiple users at once
408
- - `bulkUntagUsers()` - Remove tags from multiple users
409
-
410
- ### 6. ContentService (`src/services/content.service.ts`)
411
-
412
- **Purpose**: Content and media management
413
-
414
- **Key Features**:
415
-
416
- - Image, file, and GIF upload
417
- - Article creation and management
418
- - Media information retrieval
419
- - Content sharing
420
-
421
- **Main Methods**:
422
-
423
- - `uploadImage()` - Upload image files
424
- - `uploadFile()` - Upload general files
425
- - `uploadGif()` - Upload GIF files
426
- - `getMediaInfo()` - Get media details
427
- - `createArticle()` - Create article content
428
- - `updateArticle()` - Update article
429
- - `getArticle()` - Get article details
430
- - `getArticleList()` - List all articles
431
- - `deleteArticle()` - Delete article
432
- - `shareArticle()` - Share article to user
433
-
434
- ### 7. VideoUploadService (`src/services/video-upload.service.ts`)
435
-
436
- **Purpose**: Video upload and management
437
-
438
- **Key Features**:
439
-
440
- - Video file upload
441
- - Upload status tracking
442
- - Video information management
443
- - Video message sending
444
- - Video analytics
445
- - Thumbnail generation
446
-
447
- **Main Methods**:
448
-
449
- - `uploadVideo()` - Upload video file
450
- - `getUploadStatus()` - Check upload progress
451
- - `getVideoInfo()` - Get video details
452
- - `sendVideoMessage()` - Send video to user
453
- - `uploadVideoFromUrl()` - Upload from URL
454
- - `getVideoList()` - List uploaded videos
455
- - `deleteVideo()` - Delete video
456
- - `generateThumbnail()` - Create video thumbnail
457
- - `getVideoAnalytics()` - Get video metrics
458
- - `waitForUploadCompletion()` - Wait for processing
459
-
460
- ## Type Definitions Added
461
-
462
- ### 1. ZNS Types (`src/types/zns.ts`)
463
-
464
- - `ZNSMessage`, `ZNSHashPhoneMessage`, `ZNSDevModeMessage`
465
- - `ZNSRsaMessage`, `ZNSJourneyMessage`
466
- - `ZNSSendResult`, `ZNSTemplate`, `ZNSTemplateList`
467
- - `ZNSCreateTemplateRequest`, `ZNSUpdateTemplateRequest`
468
- - `ZNSUploadImageResult`, `ZNSStatusInfo`, `ZNSMessageStatusInfo`
469
- - `ZNSQuotaInfo`, `ZNSQualityInfo`, `ZNSAnalytics`
470
-
471
- ### 2. Group Types (`src/types/group.ts`)
472
-
473
- - `GroupMessage`, `GroupTextMessage`, `GroupImageMessage`
474
- - `GroupFileMessage`, `GroupStickerMessage`, `GroupMentionMessage`
475
- - `GroupMessageResult`, `GroupInfo`, `GroupMember`
476
- - `GroupSettings`, `GroupStatistics`, `GroupBroadcast`
477
-
478
- ### 3. Social Types (`src/types/social.ts`)
479
-
480
- - `AccessToken`, `RefreshTokenResponse`, `SocialUserInfo`
481
- - `SocialProfile`, `SocialFriend`, `SocialPost`
482
- - `SocialMessage`, `SocialConversation`
483
- - `PKCEConfig`, `OAuthConfig`, `AuthorizationRequest`
484
-
485
- ### 4. User Management Types (`src/types/user-management.ts`)
486
-
487
- - `UserProfile`, `UserList`, `UserTag`, `UserTagList`
488
- - `UserNote`, `UserInteraction`, `UserAnalytics`
489
- - `UserSegment`, `UserCustomField`, `UserBehavior`
490
- - `UserJourney`, `UserPreference`, `BulkUserOperation`
491
-
492
- ## Integration with Main SDK
493
-
494
- All services have been integrated into the main `ZaloSDK` class:
495
-
496
- ```typescript
497
- const sdk = new ZaloSDK(config);
498
-
499
- // Access services
500
- sdk.zns.sendMessage(...)
501
- sdk.groupMessage.sendTextMessage(...)
502
- sdk.social.getUserInfo(...)
503
- sdk.userManagement.getUserProfile(...)
504
- sdk.tag.createTag(...)
505
- sdk.content.uploadImage(...)
506
- sdk.videoUpload.uploadVideo(...)
507
- ```
508
-
509
- ## Export Structure
510
-
511
- All services and types are properly exported from the main index file:
512
-
513
- ```typescript
514
- // Services
515
- export { ZNSService } from "./services/zns.service";
516
- export { GroupMessageService } from "./services/group-message.service";
517
- export { SocialService } from "./services/social.service";
518
- export { UserManagementService } from "./services/user-management.service";
519
- export { TagService } from "./services/tag.service";
520
- export { ContentService } from "./services/content.service";
521
- export { VideoUploadService } from "./services/video-upload.service";
522
-
523
- // Types
524
- export * from "./types/zns";
525
- export * from "./types/group";
526
- export * from "./types/social";
527
- export * from "./types/user-management";
528
- ```
529
-
530
- ## Benefits
531
-
532
- 1. **Complete API Coverage**: All major Zalo APIs are now supported
533
- 2. **Type Safety**: Full TypeScript support with comprehensive type definitions
534
- 3. **Consistent Interface**: All services follow the same patterns and error handling
535
- 4. **Easy Integration**: Services are accessible through the main SDK instance
536
- 5. **Comprehensive Documentation**: Each service includes detailed JSDoc comments
537
- 6. **Error Handling**: Consistent error handling across all services
538
- 7. **Future-Proof**: Easy to extend and maintain
539
-
540
- This comprehensive SDK now provides complete coverage of Zalo's API ecosystem, making it easy for developers to integrate all Zalo features into their applications.
@@ -1,152 +0,0 @@
1
- # Update Article Status - New Feature
2
-
3
- ## Tổng quan
4
-
5
- Method `updateArticleStatus` mới được thêm vào `ArticleService` cho phép cập nhật trạng thái bài viết một cách đơn giản mà không cần thay đổi nội dung bài viết.
6
-
7
- ## Tính năng
8
-
9
- ✅ **Cập nhật trạng thái đơn giản**: Chỉ cần article ID và trạng thái mới
10
- ✅ **Bảo toàn dữ liệu**: Giữ nguyên tất cả nội dung hiện có
11
- ✅ **Tự động phát hiện loại**: Hỗ trợ cả bài viết thường và video
12
- ✅ **Kiểm soát comment**: Tùy chọn cập nhật trạng thái bình luận
13
- ✅ **Validation đầy đủ**: Kiểm tra tham số đầu vào
14
-
15
- ## Cách sử dụng
16
-
17
- ### Cơ bản
18
-
19
- ```typescript
20
- import { ZaloSDK, ArticleStatus, CommentStatus } from 'redai-zalo-sdk';
21
-
22
- const sdk = new ZaloSDK();
23
-
24
- // Xuất bản bài viết (show)
25
- const result = await sdk.article.updateArticleStatus(
26
- accessToken,
27
- 'article_id',
28
- ArticleStatus.SHOW
29
- );
30
-
31
- // Ẩn bài viết và tắt bình luận
32
- const result2 = await sdk.article.updateArticleStatus(
33
- accessToken,
34
- 'article_id',
35
- ArticleStatus.HIDE,
36
- CommentStatus.HIDE
37
- );
38
- ```
39
-
40
- ### Theo dõi tiến trình
41
-
42
- ```typescript
43
- // Cập nhật trạng thái
44
- const updateResult = await sdk.article.updateArticleStatus(
45
- accessToken,
46
- articleId,
47
- ArticleStatus.SHOW
48
- );
49
-
50
- // Kiểm tra tiến trình
51
- const progress = await sdk.article.checkArticleProcess(
52
- accessToken,
53
- updateResult.token
54
- );
55
-
56
- console.log('Trạng thái cập nhật:', progress.status);
57
- ```
58
-
59
- ### Cập nhật hàng loạt
60
-
61
- ```typescript
62
- const articleIds = ['id1', 'id2', 'id3'];
63
-
64
- for (const id of articleIds) {
65
- try {
66
- await sdk.article.updateArticleStatus(
67
- accessToken,
68
- id,
69
- ArticleStatus.SHOW
70
- );
71
- console.log(`✅ Đã cập nhật bài viết ${id}`);
72
- } catch (error) {
73
- console.error(`❌ Lỗi cập nhật bài viết ${id}:`, error);
74
- }
75
-
76
- // Tránh rate limiting
77
- await new Promise(resolve => setTimeout(resolve, 1000));
78
- }
79
- ```
80
-
81
- ## Tham số
82
-
83
- | Tham số | Loại | Bắt buộc | Mô tả |
84
- |---------|------|----------|-------|
85
- | `accessToken` | string | ✅ | Token truy cập OA |
86
- | `articleId` | string | ✅ | ID bài viết cần cập nhật |
87
- | `status` | ArticleStatus | ✅ | Trạng thái mới (`'show'` hoặc `'hide'`) |
88
- | `comment` | CommentStatus | ❌ | Trạng thái bình luận (`'show'` hoặc `'hide'`) |
89
-
90
- ## Cách hoạt động
91
-
92
- 1. **Lấy thông tin bài viết**: Gọi `getArticleDetail()` để lấy dữ liệu hiện tại
93
- 2. **Bảo toàn dữ liệu**: Giữ nguyên tất cả thông tin (title, content, cover, v.v.)
94
- 3. **Cập nhật trạng thái**: Chỉ thay đổi `status` và `comment` (nếu có)
95
- 4. **Gọi API cập nhật**: Sử dụng `updateArticle()` với dữ liệu đầy đủ
96
-
97
- ## Ưu điểm so với updateArticle()
98
-
99
- | Tiêu chí | updateArticleStatus() | updateArticle() |
100
- |----------|----------------------|-----------------|
101
- | **Đơn giản** | ✅ Chỉ cần ID + status | ❌ Cần toàn bộ dữ liệu |
102
- | **An toàn** | ✅ Bảo toàn dữ liệu tự động | ⚠️ Có thể ghi đè dữ liệu |
103
- | **Hiệu quả** | ✅ Ít tham số | ❌ Nhiều tham số phức tạp |
104
- | **Dễ sử dụng** | ✅ API đơn giản | ❌ Cần chuẩn bị nhiều data |
105
-
106
- ## Xử lý lỗi
107
-
108
- ```typescript
109
- try {
110
- const result = await sdk.article.updateArticleStatus(
111
- accessToken,
112
- articleId,
113
- ArticleStatus.SHOW
114
- );
115
- console.log('Cập nhật thành công:', result.token);
116
- } catch (error) {
117
- if (error.message.includes('Article ID cannot be empty')) {
118
- console.error('Lỗi: ID bài viết trống');
119
- } else if (error.message.includes('Invalid status')) {
120
- console.error('Lỗi: Trạng thái không hợp lệ');
121
- } else {
122
- console.error('Lỗi khác:', error.message);
123
- }
124
- }
125
- ```
126
-
127
- ## Ví dụ thực tế
128
-
129
- Xem file `examples/article-status-update.ts` để có ví dụ chi tiết về:
130
- - Cập nhật trạng thái cơ bản
131
- - Cập nhật hàng loạt
132
- - Xử lý lỗi và retry logic
133
- - Theo dõi tiến trình cập nhật
134
-
135
- ## Test
136
-
137
- Chạy test để đảm bảo method hoạt động đúng:
138
-
139
- ```bash
140
- npm test -- article-status-update.test.ts
141
- ```
142
-
143
- ## Tương thích
144
-
145
- - ✅ Hỗ trợ cả bài viết thường (normal) và video
146
- - ✅ Tương thích với tất cả phiên bản hiện tại
147
- - ✅ Không ảnh hưởng đến các method khác
148
- - ✅ TypeScript support đầy đủ
149
-
150
- ---
151
-
152
- **Lưu ý**: Method này là bổ sung cho `updateArticle()` hiện có, không thay thế. Sử dụng `updateArticleStatus()` khi chỉ cần thay đổi trạng thái, và `updateArticle()` khi cần cập nhật nội dung.