-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
61 lines (50 loc) · 1.66 KB
/
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
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
global.qrcode = require("qrcode-terminal");
const { Client, LocalAuth, MessageMedia } = require("whatsapp-web.js");
global.fs = require("fs");
global.client = new Client({
puppeteer: {
headless: true,
args: ["--no-sandbox", "--disable-setuid-sandbox"],
},
authStrategy: new LocalAuth(),
webVersionCache: {
type: "remote",
remotePath:
"https://raw.githubusercontent.com/wppconnect-team/wa-version/main/html/2.2412.54.html",
},
});
client.on("qr", (qr) => {
qrcode.generate(qr, { small: true });
});
client.on("ready", async () => {
console.log("Whatsapp Aktif!");
await sendMsg();
});
client.initialize();
const message = `
Merhaba, bu bir test mesajıdır. Lütfen cevap vermeyiniz.
`;
function checkNumber(number) {
if(isNaN(number)) return false;
if(number.length != 12) return false;
return true;
}
async function sendMsg() {
const media = await MessageMedia.fromUrl('https://via.placeholder.com/350x150.png');
let numbers = fs.readFileSync("numbers.txt", "utf-8").split("\n");
console.log(`Toplam ${numbers.length} numara bulundu!`);
let sents = [];
numbers.forEach(async (number) => {
number = number.trim();
if (sents.includes(number)) return console.log(`Zaten gönderildi: ${number}`);
if (!checkNumber(number)) return console.log(`Hatalı numara: ${number}`);
try {
await client.sendMessage(`${number}@c.us`, media);
await client.sendMessage(`${number}@c.us`, message);
sents.push(number);
console.log(`Mesaj gönderildi: ${number}`);
} catch (e) {
console.log(`Mesaj gönderilemedi: ${number}`);
}
});
}