fix(album): address code review feedback

Fixes all issues identified in PR #44 review:

1. **Album root message now relayed to server** (Critical)
   - Before: Only generated root message, never sent it
   - After: Calls relayMessage() on albumRootMsg before sending media items
   - Also emits own event if emitOwnEvents is enabled

2. **Fixed messageId collision**
   - Before: Spread ...options could pass same messageId to all items
   - After: Explicitly pass only safe options (timestamp, quoted, etc.)
   - Each media item now gets a fresh ID from generateWAMessage

3. **Fixed proto structure for album association**
   - Before: Used non-existent messageContextInfo.messageAddOnType
   - After: Uses correct messageContextInfo.messageAssociation with:
     - associationType: proto.MessageAssociation.AssociationType.MEDIA_ALBUM
     - parentMessageKey: albumKey

4. **Added runtime error for sendMessage misuse**
   - sendMessage() now throws clear error if called with { album: ... }
   - Forces users to use sendAlbumMessage() for proper behavior

5. **Fixed documentation**
   - delay: Changed "based on media size" to "based on media type"
   - retryAttempts: Clarified it's "total attempts" not just retries

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Renato Alcara
2026-01-23 15:09:31 -03:00
parent 6e0694e72a
commit 54549c4fc1
2 changed files with 56 additions and 13 deletions
+9 -3
View File
@@ -319,7 +319,8 @@ export type AlbumMessageOptions = {
medias: AlbumMediaItem[]
/**
* Delay strategy between media sends
* - 'adaptive': Calculates delay based on media size (recommended)
* - 'adaptive': Calculates delay based on media type (videos get 2x delay),
* position in album, and random jitter (recommended)
* - number: Fixed delay in milliseconds
* @default 'adaptive'
*/
@@ -348,7 +349,7 @@ export type AlbumMediaResult = {
message?: WAMessage
/** Error details (if failed) */
error?: Error
/** Number of retry attempts made */
/** Total number of attempts made (1 = success on first try, >1 = retries occurred) */
retryAttempts: number
/** Time taken to send this item in ms */
latencyMs: number
@@ -429,7 +430,12 @@ export type AnyRegularMessageContent = (
footer?: string
}
| {
/** Album message - send multiple images/videos grouped together */
/**
* Album message - send multiple images/videos grouped together
* ⚠️ WARNING: Do NOT use with sendMessage() - use sendAlbumMessage() instead!
* sendMessage only relays the root message and won't send individual media items
* @internal Used internally by generateWAMessage
*/
album: AlbumMessageOptions
}
| SharePhoneNumber