Skip to content

Instantly share code, notes, and snippets.

@infysumanta
Last active June 6, 2023 06:44
Show Gist options
  • Save infysumanta/01506ad7ccb8b1f0c90cbdaa9c1462a0 to your computer and use it in GitHub Desktop.
Save infysumanta/01506ad7ccb8b1f0c90cbdaa9c1462a0 to your computer and use it in GitHub Desktop.
wharsapp-web.js
const { Client } = require("whatsapp-web.js");
const qrcode = require("qrcode-terminal");
const client = new Client();
client.on("qr", (qr) => {
qrcode.generate(qr, { small: true });
});
client.on("ready", () => {
console.log("Client is ready!");
});
client.on("message", async (message) => {
if (message.body === "Hi") {
client.sendMessage(message.from, "Hello");
}
if (message.body === "Hello") {
const chat = await message.getChat();
const contact = await message.getContact();
await chat.sendMessage(`Hello @${contact.id.user}`, {
mentions: [contact],
});
}
});
client.initialize();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment