feat: add Product Carousel message support

- Add ProductCarouselCard and ProductCarouselMessageOptions types
- Add productCarousel to AnyRegularMessageContent union type
- Create generateProductCarouselMessage function with validation
- Add productCarousel support in generateWAMessageContent
- Uses viewOnceMessage wrapper for iOS/Android compatibility
- Requires WhatsApp Business account with configured catalog

Usage:
await sock.sendMessage(jid, {
  productCarousel: {
    catalogId: '123456789',
    products: [
      { productId: 'produto_001' },
      { productId: 'produto_002' }
    ]
  },
  body: 'Confira nossos produtos!'
})

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Renato Alcara
2026-01-26 17:43:35 -03:00
parent 8c8e228525
commit 3d4fa3e007
2 changed files with 152 additions and 1 deletions
+62
View File
@@ -613,6 +613,45 @@ export type AlbumSendResult = {
totalLatencyMs: number
}
// ========== Product Carousel Message Types ==========
/**
* Single product card in a product carousel
* References a product from WhatsApp Business catalog
*/
export type ProductCarouselCard = {
/** Product retailer ID from the catalog */
productId: string
}
/**
* Options for generating a product carousel message
* Uses products from WhatsApp Business catalog
*
* @example
* ```typescript
* await sock.sendMessage(jid, {
* productCarousel: {
* catalogId: '123456789',
* products: [
* { productId: 'iphone_15' },
* { productId: 'macbook_air' },
* { productId: 'apple_watch' }
* ]
* },
* body: 'Check out our featured products!'
* })
* ```
*/
export type ProductCarouselMessageOptions = {
/** Catalog ID from WhatsApp Business */
catalogId: string
/** Products to display (2-10 cards required) */
products: ProductCarouselCard[]
/** Body text for the message */
body?: string
}
export type AnyRegularMessageContent = (
| ({
text: string
@@ -747,6 +786,29 @@ export type AnyRegularMessageContent = (
title?: string
footer?: string
}
| {
/**
* Product Carousel Message - Swipeable product cards from WhatsApp Business catalog
* Requires: WhatsApp Business account with configured catalog
*
* @example
* ```typescript
* await sock.sendMessage(jid, {
* productCarousel: {
* catalogId: '123456789',
* products: [
* { productId: 'produto_001' },
* { productId: 'produto_002' },
* { productId: 'produto_003' }
* ]
* },
* body: 'Confira nossos produtos em destaque!'
* })
* ```
*/
productCarousel: ProductCarouselMessageOptions
body?: string
}
| {
/**
* Album message - send multiple images/videos grouped together