-
Notifications
You must be signed in to change notification settings - Fork 8
/
app.js
46 lines (37 loc) · 1.09 KB
/
app.js
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
35
36
37
38
39
40
41
42
43
44
45
46
const qrcode = require("qrcode-terminal");
const { Client, LocalAuth, MessageMedia } = require("whatsapp-web.js");
const client = new Client({
authStrategy: new LocalAuth(),
});
client.initialize();
client.on("qr", (qr) => {
qrcode.generate(qr, { small: true });
});
client.on("authenticated", () => {
console.log("AUTHENTICATED");
});
client.on("ready", () => {
console.log("Client is ready!");
});
//Replying Messages with image from url
client.on("message", async (message) => {
const chat = await message.getChat();
if (!chat.isGroup) {
if (message.body.toLowerCase() === "hello") {
await chat.sendMessage("Hi, I am Tag All bot!");
}
} else if (
(message.body.split(" ").includes("@team") ||
message.body.split(" ").includes("@everyone")) &&
chat.isGroup
) {
let text = "";
let mentions = [];
for (let participant of chat.participants) {
const contact = await client.getContactById(participant.id._serialized);
mentions.push(contact);
text += `@${participant.id.user} `;
}
await chat.sendMessage(text, { mentions });
}
});