-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver_v2.js
73 lines (60 loc) · 1.3 KB
/
server_v2.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
const WebSocket = require("ws");
const { Client } = require("whatsapp-web.js");
const client = new Client();
const fs = require('fs');
const wss = new WebSocket.Server({ port: 8080 });
let estado = "";
let qrtemp = "";
wss.on("connection", ws => {
ws.on("message", message => {
comando = "";
try {
comando = JSON.parse(message);
} catch (e) {
ws.send("Comando inválido");
return;
}
switch (comando.comando) {
case "conectado":
k = conectado("Cliente Conectato com sucesso");
console.log(k);
//ws.send(k);
break;
case "conectar":
conectar();
break;
case "enviar":
enviar();
break;
case "entrarGrupo":
entrarGrupo();
break;
default:
console.log(
"default comando desconhecido",
JSON.parse(JSON.stringify(message)).comando
);
}
});
client.on("qr", qr => {
//console.log(qr);
ws.send(qr);
});
client.on("ready", () => {
console.log("Client is ready!");
});
client.on("message", msg => {
if (msg.body == "!ping") {
msg.reply("pong");
}
});
});
function conectado(x) {
console.log(x);
return x;
}
function conectar() {
client.initialize();
}
function enviar() {}
function entrarGrupo() {}