// Solid color images generated in the browser, for testing
const img = (color, label) => {
const c = document.createElement('canvas');
c.width = c.height = 400;
const g = c.getContext('2d');
g.fillStyle = color;
g.fillRect(0, 0, 400, 400);
g.fillStyle = '#fff';
g.font = 'bold 60px sans-serif';
g.textAlign = 'center';
g.fillText(label, 200, 220);
return c.toDataURL('image/jpeg', 0.9);
};
await WPP.chat.sendCarouselMessage('[number]@c.us', {
body: 'Choose a product',
footer: 'Swipe to see more options',
cards: [
{
image: img('#d93232', 'Product 1'),
title: 'Product 1',
description: 'First product',
footer: 'In stock',
buttons: [{ id: 'product-1', text: 'Choose' }]
},
{
image: img('#3264dc', 'Product 2'),
title: 'Product 2',
description: 'Second product',
footer: 'In stock',
buttons: [{ id: 'product-2', text: 'Choose' }]
}
]
});
Send an image carousel. Images can be data URLs, base64, Blob, File, or IDs/models of existing WhatsApp image messages. External HTTP URLs are not accepted because WhatsApp Web can block them through its CSP.