-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexample.js
89 lines (72 loc) · 2.21 KB
/
example.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
const fs = require("fs");
const axios = require("axios");
const { Client, Location } = require("./index");
const SESSION_FILE_PATH = "./session.json";
let sessionCfg;
if (fs.existsSync(SESSION_FILE_PATH)) {
sessionCfg = require(SESSION_FILE_PATH);
}
const client = new Client({
puppeteer: { headless: false },
session: sessionCfg,
});
client.initialize();
client.on("qr", (qr) => {});
client.on("authenticated", (session) => {
sessionCfg = session;
fs.writeFile(SESSION_FILE_PATH, JSON.stringify(session), function (err) {
if (err) {
console.error(err);
}
});
});
client.on("auth_failure", (msg) => {});
client.on("ready", () => {});
client.on("message", async (msg) => {
axios
.post("http://localhost:3333/api/whatsapp-message", {
phone: msg.from,
message: msg.body,
})
.then((response) => {
if (response.data.status) {
response.data.messages.map((message) => {
if (message === "*Saude*1. Quiz") {
client.sendMessage(
msg.from,
"*Saude* \n 1. Quiz \n 2. Prevenção ao suícidio \n 3. Teste rápido \n *Segurança* \n 4. Reboque \n 5. Prevenção de acidentes \n *Perfil* \n 6. Meu cadastro \n 7. Meu pontos"
);
} else {
client.sendMessage(msg.from, message);
}
});
}
})
.catch((err) => {
console.log(err);
});
});
client.on("message_create", (msg) => {
if (msg.fromMe) {
}
});
client.on("message_revoke_everyone", async (after, before) => {
if (before) {
}
});
client.on("message_revoke_me", async (msg) => {});
client.on("message_ack", (msg, ack) => {
if (ack == 3) {
}
});
client.on("group_join", (notification) => {
notification.reply("User joined.");
});
client.on("group_leave", (notification) => {
notification.reply("User left.");
});
client.on("group_update", (notification) => {});
client.on("change_battery", (batteryInfo) => {
const { battery, plugged } = batteryInfo;
});
client.on("disconnected", (reason) => {});