-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
52 lines (44 loc) · 1.28 KB
/
main.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
const express = require("express");
const { readFile } = require("fs/promises");
const path = require("path");
const app = express();
const {default: makeWASocket, useSingleFileAuthState} = require("@adiwajshing/baileys");
const { state } = useSingleFileAuthState("./sesi.json");
const pino = require('pino');
const ws = makeWASocket({
logger: pino({ level: 'silent' }),
browser: ["AlertBot", "AlertBot", "1.0"],
auth: state,
});
const main = async () => {
const { connect } = require('./connect.js');
try {
await connect(ws);
} catch {
console.log("Connection Error!");
await connect(ws);
}
}
main();
app.listen(process.env.PORT || 3000);
// _____________________________________
app.get("/", async (req, res) => {
res.status(200).send("AlertBot@2022");
});
app.get("/:name/group", async (req, res) => {
const name = req.params.name.toLowerCase();
const code = await require('./group.js')(ws, name);
// make a link and 302 onto that
if (code){
const link = "https://chat.whatsapp.com/"+code;
res.redirect(link);
}
else {
console.log("Code not generated!")
}
});
app.get("/groupIds", async (req, res) => {
let file = await readFile(path.join(__dirname, "info.json"), "utf-8");
file = await JSON.parse(file);
res.json(file);
});