-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
68 lines (58 loc) · 1.48 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
const { Client, LocalAuth } = require("whatsapp-web.js");
const qrcode = require("qrcode-terminal");
const {
ChatAskHandler,
ChatHelpHandler,
ChatEditHandler,
} = require("./components");
const app = new Client({
restartOnAuthFail: true,
puppeteer: {
headless: true,
args: [
"--no-sandbox",
"--disable-setuid-sandbox",
"--disable-dev-shm-usage",
"--disable-accelerated-2d-canvas",
"--no-first-run",
"--no-zygote",
"--single-process", // <- this one doesn't works in Windows
"--disable-gpu",
],
},
authStrategy: new LocalAuth(),
});
app.on("qr", (qr) => {
qrcode.generate(qr, { small: true });
});
app.on("ready", () => {
console.log("Client is ready!");
});
app.on("message", async (msg) => {
const contact = await msg.getContact();
const name = contact.pushname;
console.log("Message from " + name + " with a message " + msg.body);
const text = msg.body.toLowerCase() || "";
// status
if (text === "status") {
msg.reply("Running Normal");
console.log("Send Reply to " + name);
}
// ask
if (text.includes("ask/")) {
await ChatAskHandler(text, msg);
console.log("Send Reply to " + name);
}
// help
if (text.includes("help/")) {
await ChatHelpHandler(text, msg);
console.log("Send Reply to " + name);
}
// edit
if (text.includes("edit/")) {
await ChatEditHandler(text, msg);
console.log("Send Reply to " + name);
}
});
app.initialize();
module.exports = { app };