feat(album): add album message sending with intelligent retry and adaptive delay
Implements WhatsApp album messages (grouped media) with the following features: - Send 2-10 images/videos grouped as a single album message - Adaptive delay between sends based on media type (videos get 2x delay) - Intelligent retry with exponential backoff for failed items - parentMessageKey reference to album root (as suggested by maintainer) - Complete result structure with success/failure tracking per item - Validation for min (2) and max (10) media items Types added: - AlbumMediaItem: Single image/video with caption, mentions, dimensions - AlbumMessageOptions: Configuration for delay, retry, continueOnFailure - AlbumMediaResult: Per-item result with latency and retry attempts - AlbumSendResult: Complete result with albumKey and statistics Based on PR #2058 from WhiskeySockets/Baileys with improvements. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -286,6 +286,96 @@ export type Carouselable = {
|
||||
}
|
||||
}
|
||||
|
||||
// ========== Album Message Types ==========
|
||||
|
||||
/**
|
||||
* Single media item in an album (image or video)
|
||||
* Each item can have its own caption, thumbnail, and metadata
|
||||
*/
|
||||
export type AlbumMediaItem =
|
||||
| ({
|
||||
image: WAMediaUpload
|
||||
caption?: string
|
||||
jpegThumbnail?: string
|
||||
} & Mentionable &
|
||||
Contextable &
|
||||
WithDimensions)
|
||||
| ({
|
||||
video: WAMediaUpload
|
||||
caption?: string
|
||||
gifPlayback?: boolean
|
||||
jpegThumbnail?: string
|
||||
/** Duration in seconds */
|
||||
seconds?: number
|
||||
} & Mentionable &
|
||||
Contextable &
|
||||
WithDimensions)
|
||||
|
||||
/**
|
||||
* Configuration for album message sending
|
||||
*/
|
||||
export type AlbumMessageOptions = {
|
||||
/** Array of media items (images/videos) - min 2, max 10 */
|
||||
medias: AlbumMediaItem[]
|
||||
/**
|
||||
* Delay strategy between media sends
|
||||
* - 'adaptive': Calculates delay based on media size (recommended)
|
||||
* - number: Fixed delay in milliseconds
|
||||
* @default 'adaptive'
|
||||
*/
|
||||
delay?: 'adaptive' | number
|
||||
/**
|
||||
* Number of retry attempts for failed media items
|
||||
* @default 3
|
||||
*/
|
||||
retryCount?: number
|
||||
/**
|
||||
* Whether to continue sending remaining items if one fails
|
||||
* @default true
|
||||
*/
|
||||
continueOnFailure?: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* Result of a single media item send attempt
|
||||
*/
|
||||
export type AlbumMediaResult = {
|
||||
/** Index in the original medias array */
|
||||
index: number
|
||||
/** Whether this item was sent successfully */
|
||||
success: boolean
|
||||
/** The sent message (if successful) */
|
||||
message?: WAMessage
|
||||
/** Error details (if failed) */
|
||||
error?: Error
|
||||
/** Number of retry attempts made */
|
||||
retryAttempts: number
|
||||
/** Time taken to send this item in ms */
|
||||
latencyMs: number
|
||||
}
|
||||
|
||||
/**
|
||||
* Complete result of album message sending
|
||||
*/
|
||||
export type AlbumSendResult = {
|
||||
/** Key of the album root message */
|
||||
albumKey: WAMessageKey
|
||||
/** Results for each media item */
|
||||
results: AlbumMediaResult[]
|
||||
/** Total number of items */
|
||||
totalItems: number
|
||||
/** Number of successfully sent items */
|
||||
successCount: number
|
||||
/** Number of failed items */
|
||||
failedCount: number
|
||||
/** Indices of failed items (for potential retry) */
|
||||
failedIndices: number[]
|
||||
/** Overall success (all items sent) */
|
||||
success: boolean
|
||||
/** Total time taken in ms */
|
||||
totalLatencyMs: number
|
||||
}
|
||||
|
||||
export type AnyRegularMessageContent = (
|
||||
| ({
|
||||
text: string
|
||||
@@ -338,6 +428,10 @@ export type AnyRegularMessageContent = (
|
||||
body?: string
|
||||
footer?: string
|
||||
}
|
||||
| {
|
||||
/** Album message - send multiple images/videos grouped together */
|
||||
album: AlbumMessageOptions
|
||||
}
|
||||
| SharePhoneNumber
|
||||
| RequestPhoneNumber
|
||||
) &
|
||||
|
||||
Reference in New Issue
Block a user