-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
35 lines (26 loc) · 843 Bytes
/
index.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
const qrcode = require("qrcode-terminal");
const { Client } = require("whatsapp-web.js");
const { fork } = require("node:child_process");
const client = new Client();
client.initialize();
client.on("qr", (qr) => {
qrcode.generate(qr, { small: true });
});
client.on("ready", () => {
console.log("Client is ready!");
});
let chats = [];
client.on("message", (msg) => {
const indexChat = chats.findIndex((chat) => chat.id === msg.from);
if (indexChat > -1) {
chats[indexChat].msg = msg;
chats[indexChat].child.send(msg.body);
return;
}
const child = fork("chatgpt.js", [msg.from, msg.body]);
child.on("message", function (message) {
const indexChat = chats.findIndex((chat) => chat.id === message.chatId);
chats[indexChat].msg.reply(message.text);
});
chats.push({ id: msg.from, child, msg });
});