-
Notifications
You must be signed in to change notification settings - Fork 0
/
connect.js
29 lines (29 loc) · 1.06 KB
/
connect.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
const {jidNormalizedUser} = require("@adiwajshing/baileys");
const connect = async (ws) => {
if (ws.user && ws.user.id) ws.user.jid = jidNormalizedUser(ws.user.id);
// __________________________________________________
ws.ev.on("connection.update", async (update) => {
const { connection } = update;
try {
if (connection === "open") {
console.log("Connection Successful!");
await ws.sendMessage("[email protected]", {
text: "Connected Successfully",
});
}
else if (connection === "close") {
console.log("Connection Closed!");
console.log("attempting connection again...")
await connect(ws);
}
} catch (e) {
console.log("Connection Error!" + e)
console.log("attempting connection again...")
console.log("stop the script if you understand the above error")
await connect(ws);
}
})
}
module.exports = {
connect
}