feat(messages): add multi-product message support

Add generateProductListMessage function for sending multiple products
from the WhatsApp Business catalog in a single message.

Features:
- ProductListMessageOptions type with full validation
- Support for product sections (categories)
- Optional header image from catalog
- Integration with sendMessage via 'productList' property
- Maximum 30 products limit per WhatsApp specs

Usage:
```typescript
const msg = generateProductListMessage({
  title: 'Our Best Sellers',
  description: 'Check out our products!',
  buttonText: 'View Products',
  businessOwnerJid: '5511999999999@s.whatsapp.net',
  productSections: [
    { title: 'Electronics', products: [{ productId: 'prod_001' }] }
  ]
})
await sock.sendMessage(jid, msg)
```

Note: Requires WhatsApp Business account with catalog configured.
Does NOT require Meta Business Manager integration.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Renato Alcara
2026-01-26 02:02:54 -03:00
parent 4faef75104
commit 15a4cc2962
2 changed files with 216 additions and 0 deletions
+81
View File
@@ -437,6 +437,87 @@ export type Carouselable = {
}
}
// ========== Product List Message Types ==========
/**
* Product reference in a product list
* Uses the product ID from the WhatsApp Business catalog
*/
export type ProductItem = {
/** Product ID from the catalog */
productId: string
}
/**
* Section containing products in a product list message
*/
export type ProductSection = {
/** Section title */
title: string
/** Products in this section */
products: ProductItem[]
}
/**
* Header image configuration for product list
* Can reference a product's image from the catalog
*/
export type ProductListHeaderImage = {
/** Product ID whose image to use as header */
productId: string
/** Optional JPEG thumbnail */
jpegThumbnail?: Buffer
}
/**
* Options for generating a product list message (multi-product)
* Allows sending multiple products from the catalog in a single message
*
* @example
* ```typescript
* const msg = generateProductListMessage({
* title: 'Our Best Sellers',
* description: 'Check out our most popular products!',
* buttonText: 'View Products',
* footerText: 'Tap to browse',
* businessOwnerJid: '5511999999999@s.whatsapp.net',
* productSections: [
* {
* title: 'Electronics',
* products: [
* { productId: 'prod_001' },
* { productId: 'prod_002' }
* ]
* },
* {
* title: 'Accessories',
* products: [
* { productId: 'prod_003' }
* ]
* }
* ],
* headerImage: { productId: 'prod_001' }
* })
* await sock.sendMessage(jid, msg)
* ```
*/
export type ProductListMessageOptions = {
/** Message title */
title: string
/** Message description/body text */
description: string
/** Button text to open the product list */
buttonText: string
/** Footer text (optional) */
footerText?: string
/** Business owner JID (the catalog owner) */
businessOwnerJid: string
/** Sections with products */
productSections: ProductSection[]
/** Header image configuration (optional) */
headerImage?: ProductListHeaderImage
}
// ========== Album Message Types ==========
/**