-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.js
More file actions
34 lines (29 loc) · 786 Bytes
/
bot.js
File metadata and controls
34 lines (29 loc) · 786 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const { Client, LocalAuth } = require("whatsapp-web.js");
const qrcode = require("qrcode-terminal");
// Create a new client instance
const client = new Client({
puppeteer: {
args: ["--no-sandbox", "--disable-setuid-sandbox"],
},
authStrategy: new LocalAuth({
dataPath: "session",
}),
});
// When the client is ready, run this code (only once)
client.once("ready", () => {
console.log("Client is ready!");
});
// When the client received QR-Code
client.on("qr", (qr) => {
console.log("QR RECEIVED", qr);
qrcode.generate(qr, { small: true });
});
client.on("message_create", (message) => {
console.log(message.type);
if (message.body === "!ping") {
// reply back "pong" directly to the message
message.reply("pong");
}
});
// Start your client
client.initialize();