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