I made a video explaining how to do Whatsapp automation using Javascript. Someone has asked this question in the comments of that video. Let’s find out!


Here’s the example source code to send a list of products in which users can select one product. After selecting a product, an automatic message will be sent with the message “You’ve select X product”

I’m sending the list to a group named “Source Group” in this example. You can change the group name or modify the code to send it to a contact based on your requirement.
const { Client, LocalAuth, Buttons, List } = require("whatsapp-web.js");
const qrcode = require("qrcode-terminal");
const myGroupName = "Source Group";
const client = new Client({
authStrategy: new LocalAuth(),
});
client.on("qr", (qr) => {
qrcode.generate(qr, { small: true });
});
client.on("ready", () => {
console.log("Client is ready!");
client.getChats().then((chats) => {
myGroup = chats.find((chat) => chat.name === myGroupName);
const productsList = new List(
"Here's our list of products at 50% off",
"View all products",
[
{
title: "Products list",
rows: [
{ id: "apple", title: "Apple" },
{ id: "mango", title: "Mango" },
{ id: "banana", title: "Banana" },
],
},
],
"Please select a product"
);
client.sendMessage(myGroup.id._serialized, productsList);
});
});
client.on("message", (message) => {
if(message.type === 'list_response'){
message.reply(`You've selected ${message.body}`);
}
});
client.initialize();
Latest posts by Ranjith kumar (see all)
- Curved button using Flutter | Can it be done with Flutter? | Custom shapes Flutter | Custom painter - September 21, 2022
- Dynamic Island using Flutter | iPhone 14 Pro | Can it be done with Flutter? - September 14, 2022
- Best practices of scraping website data for beginners (Updated 2022) - September 12, 2022
how to integrate With Google Sheet !! thank you for your Help
Can you explain the requirement clearly?
Hi,
Can you please, Help us to show products in whatsApp
Hi, Did you mean sending products from your business catalogue?
what if each list row has a different answer?
Hi, You can just write a switch case in the line number 40 and return a different answer based on the response. This is related to programming basics and not related to this library.
halo
its good tutorial.
i want to thank you for the detailed tutorial on how to use the whatsapp api. could you also guide us with an example on how to use products,add to cart and orders.? hope to hear from you soon
Thanks Ashley, That’ll be a bit advanced. I’ll try to make a video on that topic.
thanks so much. i will be waiitng
Hi, Are you getting any error?
it does not work for me. I work with buttons using whatsapp-web.js and if I try to send more than three buttons only the first three are sent. So I tried to work with the code you presented here, but it just doesn’t do anything. Not even an error.
hey did you find any fix for this?
Hi, first thank you for the detailed explanation,
I have a problem that the message was sent but not delivered.
any idea why?
Could be some connection issue