-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
774 lines (690 loc) · 23.7 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
const makeWASocket = require("@whiskeysockets/baileys").default;
const axios = require("axios");
const nodeCron = require("node-cron");
const {
uploadFolder,
downloadFolder,
initializeFirebase,
} = require("./firebase.js");
const {
MessageType,
MessageOptions,
Mimetype,
useMultiFileAuthState,
getUrlInfo,
} = require("@whiskeysockets/baileys");
// const { MongoClient } = require("mongodb");
// const useMongoDBAuthState = require("./mongoAuthState.js");
// const { useMongoDBAuthState } = require("mongo-baileys");
const { DisconnectReason } = require("@whiskeysockets/baileys");
const express = require("express");
// const chokidar = require('chokidar');
require("dotenv").config();
const fs = require("fs");
const path = require("path");
const app = express();
const mongoURL = process.env.MONGO_URL;
const port = process.env.PORT || 3000;
const MAX_SENT_ARTICLES = 50;
let stopSpam = false;
let spamInitiatorId = null;
let sentArticles = [];
const authorizedParticipants = [
process.env.SUHANI_ID,
process.env.KEVIN_ID,
process.env.RAUNAK_ID,
process.env.SWATI_ID,
process.env.AADHISHREE_ID,
process.env.ASTERIN_ID,
process.env.RIDHIMA_ID,
];
const localFolderPath = path.normalize(
path.join(__dirname, "auth_info_baileys")
); // Path to the local folder you want to sync
console.log(localFolderPath);
let bucket;
async function uploadToFirebase(bucket) {
try {
console.log("Uploading local folder to Firebase...");
await uploadFolder(localFolderPath, bucket); // Upload the folder
console.log("Folder uploaded to Firebase successfully.");
} catch (err) {
console.error("Error uploading folder:", err);
}
}
async function downloadFromFirebase(bucket) {
try {
console.log("Downloading folder from Firebase...");
await downloadFolder(localFolderPath, bucket); // Download the folder
console.log("Folder downloaded from Firebase successfully.");
} catch (err) {
console.error("Error downloading folder:", err);
}
}
async function connectToWhatsApp() {
try {
//Wait for Firebase initialization and get the bucket
if(!bucket) {
console.log("Bucket not found, initializing");
bucket = await initializeFirebase();
}
if (fs.existsSync(localFolderPath)) {
console.log("Local folder found, proceeding with bot setup...");
} else {
// If the local folder doesn't exist, download it from Firebase
console.log("Local folder not found, downloading from Firebase...");
await downloadFromFirebase(bucket);
const { state, saveCreds } = await useMultiFileAuthState(localFolderPath);
await saveCreds(); // Save the credentials after loading
console.log("Credentials saved successfully after download.");
await delay(3000);
}
} catch (error) {
console.log("Error in connectToWhatsApp", error);
}
try {
const downloadedFiles = fs
.readdirSync(localFolderPath)
.map((file) => path.join(localFolderPath, file)) // Combine the full path
.map((fullPath) => path.normalize(fullPath)); // Normalize the full path
console.log("Contents after download:", downloadedFiles);
} catch (err) {
console.error("Error downloading folder:", err);
}
const { state, saveCreds } = await useMultiFileAuthState(localFolderPath); // this will be called as soon as the credentials are updated
// const collection = mongoClient.db("Cluster1").collection("authState");
// const { state, saveCreds } = await useMongoDBAuthState(collection);
const sock = makeWASocket({
//make connection to whatsapp backend
// can provide additional config here
printQRInTerminal: true,
auth: state,
keepAliveIntervalMs: 20000,
defaultQueryTimeoutMs: 0,
generateHighQualityLinkPreview: true,
});
sock.ev.on("connection.update", (update) =>
handleConnectionUpdate(update, sock)
);
async function updateProfileName(sock, newName) {
try {
await sock.updateProfileName(newName);
console.log(`Profile name updated to ${newName}`);
} catch (error) {
console.error("Error updating profile name:", error);
}
}
sock.ev.on("creds.update", saveCreds);
// sock.ev.on("creds.update", async () => {
// await saveCreds();
// const newProfileName = "~Asterin041";
// await updateProfileName(sock, newProfileName);
// });
//handle incoming messages
sock.ev.on("messages.upsert", async (messageUpdate) =>
handleMessagesUpsert(messageUpdate, sock)
);
console.log("Connected to WhatsApp");
}
function handleConnectionUpdate(update, sock) {
const { connection, lastDisconnect, qr } = update || {};
if (qr) {
console.log(qr);
}
if (connection === "close") {
const shouldReconnect =
lastDisconnect?.error?.output?.statusCode !== DisconnectReason.loggedOut;
if (shouldReconnect) {
connectToWhatsApp();
}
} else if (connection == "open") {
console.log("opened connection");
try {
nodeCron.schedule("0 11 * * *", async () => {
console.log("Cron job triggered for news!");
// Check if socket is open before sending a message
if (sock.ws?.readyState === sock.ws.OPEN) {
try {
await sendDailyNews(sock, process.env.CODE_ON_REMOTEJ_ID);
} catch (sendError) {
console.error("Error sending message:", sendError);
}
} else {
console.error("Socket is not open. Unable to send message.");
}
}, {
scheduled: true,
timezone: "Asia/Kolkata"
});
nodeCron.schedule("0 9 * * *", async () => {
console.log("Cron job triggered for quotes!");
// Check if socket is open before sending a message
if (sock.ws?.readyState === sock.ws.OPEN) {
try {
await sendDailyQuote(sock, process.env.CODE_ON_REMOTEJ_ID);
} catch (sendError) {
console.error("Error sending message:", sendError);
}
} else {
console.error("Socket is not open. Unable to send message.");
}
}, {
scheduled: true,
timezone: "Asia/Kolkata"
});
console.log("Cron job scheduled successfully!");
} catch (error) {
console.error("Error during cron job setup:", error);
}
}
}
async function handleMessagesUpsert(messageUpdate, sock) {
try {
const messageZero = messageUpdate.messages[0];
const { key, message } = messageZero;
if (!message) return;
const { remoteJid } = key;
// if(remoteJid !== process.env.JINDAGI_JHAND_REMOTEJ_ID) return;
const messageText =
message.conversation || message.extendedTextMessage?.text;
// console.log("messageUpdate", messageUpdate);
// console.log("remoteJid", remoteJid);
// console.log("messageText", messageText);
if (!messageText) {
return;
}
//if participant not authorized then enter || if the message is not from me then also enter
if (!(authorizedParticipants.includes(key.participant) || key.fromMe)) {
if (!key.participant) return;
// Inform the user if they are not authorized
// const notAuthorizedMessage = "You are not authorized to use this command.";
// await sock.sendMessage(remoteJid, {
// text: notAuthorizedMessage,
// });
return;
}
const myPhone = sock.user.id.split(":")[0];
const myId = myPhone + "@s.whatsapp.net";
const mentions =
message.extendedTextMessage?.contextInfo?.mentionedJid || [];
//mentionedJid = ids of all the members that have been tagged in the current message
if (messageText.toLowerCase().includes("stop") && mentions.includes(myId)) {
if (!spamInitiatorId) {
console.log("No spam initiator found.");
return;
}
if (spamInitiatorId === key.participant) {
stopSpam = true; // Set flag to stop spamming
console.log("Spam stopped by initiator.");
} else {
console.log("Only the spam initiator can stop the spam.");
}
return; // Exit function
}
if (messageText.includes("!tagAll") || messageText.includes("!TagAll")) {
await tagAllMembers(remoteJid, sock, key);
} else if (messageText.includes("!tag") || messageText.includes("!Tag")) {
await tagAllExceptOne(
remoteJid,
sock,
process.env.SUHANI_ID,
"@suhani",
key
);
}
// if (messageText === "@" + myPhone) {
// await sendTaggedReply(remoteJid, sock, key);
// return;
// }
if (mentions.includes(myId)) {
// const numberPattern = /\s\d+\s/;
const doubleQuotesPattern = /“([^“]+)”|"([^"]+)"/; // Adjusted pattern to directly capture text inside quotes
const newMessageText = messageText.replace(`@${myPhone}`, "");
const extractedTextMatch = newMessageText.match(doubleQuotesPattern);
if (!extractedTextMatch) {
//case to prevent err if the message is for getting "YEAH"
await sendTaggedReply(remoteJid, sock, key);
return;
}
if (!extractedTextMatch[1]) {
extractedTextMatch[1] = extractedTextMatch[0].replaceAll('"', "");
}
const extractedTextAfterQuotes = newMessageText
.substring(
newMessageText.indexOf(extractedTextMatch[0]) +
extractedTextMatch[0].length
)
.trim();
// Check if the extracted text contains a number pattern
const numberPattern = /\d+/; // Pattern to match numbers
const extractedNumberMatch =
extractedTextAfterQuotes.match(numberPattern);
if (
(messageText.includes("Spam") || messageText.includes("spam")) &&
extractedNumberMatch &&
extractedTextMatch
) {
console.log("I can spam now");
await spamMessage(
remoteJid,
sock,
extractedNumberMatch[0],
extractedTextMatch[1],
key
);
} else {
console.log("No spam detected");
await sendTaggedReply(remoteJid, sock, key);
}
}
if (messageText.includes("!help") || messageText.includes("!Help")) {
await help(remoteJid, sock, key);
}
if (
messageText.includes("Good morning") ||
messageText.includes("good morning") ||
messageText.includes("Good Morning") ||
messageText.includes("Good night") ||
messageText.includes("good night") ||
messageText.includes("Goodnight")
) {
await reactToMessage(remoteJid, sock, key);
}
} catch (error) {
console.log("Error in handleMessagesUpsert", error);
}
}
function delay(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
async function spamMessage(
remoteJid,
sock,
extractedNumber,
extractedText,
messageKey
) {
try {
console.log("Extracted number:", extractedNumber);
console.log("Extracted text:", extractedText);
spamInitiatorId = messageKey.participant;
const groupMetadata = await sock.groupMetadata(remoteJid);
const myId = `${sock.user.id.split(":")[0]}@s.whatsapp.net`;
const filteredParticipants = groupMetadata.participants.filter(
(participant) =>
participant.id !== myId && participant.id !== messageKey.participant
);
let mentionIds = [];
const mentionText = filteredParticipants
.map((p) => `@${p.id.split("@")[0]}`)
.join(" ");
//check if my extracted text contains a tag, by tallying it with mentionText
// const sampleMentionText = "@919999999999 @919999999998 @919999999997";
// const sampleExtractedText = "Hello @91999999999123 @91999999999123 @91999999999123";
const phoneNumberPattern = /@(\d+)/g;
const phoneNumberMatches = [...extractedText.matchAll(phoneNumberPattern)]; //found a @tag in " "
phoneNumberMatches.forEach((match) => {
const phoneNumber = match[1]; // Extracted phone number
if (mentionText.includes(phoneNumber)) {
mentionIds.push(`${phoneNumber}@s.whatsapp.net`);
}
});
console.log("mentionIds:", mentionIds);
let count = parseInt(extractedNumber);
for (let i = 0; i < count; i++) {
try {
if (stopSpam) {
stopSpam = false; // Reset the flag after stopping
spamInitiatorId = null; // Reset the initiator ID
break;
}
await sock.sendMessage(remoteJid, {
text: extractedText,
mentions: mentionIds,
});
await delay(500); // Adding delay between messages
} catch (error) {
console.log("Error while spamming:", error);
if (error.data === 429) {
console.log("Rate limit hit, pausing for a bit...");
await new Promise((resolve) => setTimeout(resolve, 10000)); // 10-second delay before retrying
}
}
}
} catch (error) {
console.log("Error while spamming:", error);
}
}
// async function spamMessage(remoteJid, sock, newMessageText, messageKey) {
// try {
// //extract the message and the number
// const numberPattern = /\s\d+\s/;
// const extractedNumber = newMessageText.match(numberPattern)[0]; // Extract the first matched number
// console.log("Extracted number:", extractedNumber);
// const doubleQuotesPattern = /"([^"]+)"/; // Regular expression to match text enclosed in double quotes
// const quotesMatch = newMessageText.match(doubleQuotesPattern);
// let extractedText = "";
// if (quotesMatch) {
// extractedText = quotesMatch[1]; // Extract the first matched text within double quotes
// console.log("Extracted text:", extractedText);
// } else {
// console.log("No text found in double quotes.");
// }
// const groupMetadata = await sock.groupMetadata(remoteJid);
// const myId = sock.user.id.split(":")[0];
// const participants = groupMetadata.participants;
// const filteredParticipants = participants.filter(
// (participant) =>
// participant.id !== myId + "@s.whatsapp.net" &&
// participant.id !== messageKey.participant
// );
// console.log(filteredParticipants);
// const mentionText = filteredParticipants
// .map((p) => `@${p.id.split("@")[0]}`)
// .join(" ");
// // ----------------------------------------
// const phoneNumberPattern = /@(\d+)/g;
// const phoneNumberMatches = [...extractedText.matchAll(phoneNumberPattern)]; //found a @tag in " "
// let mentionIds = [];
// phoneNumberMatches.forEach(match => {
// const phoneNumber = match[1]; // Extracted phone number
// mentionIds.push(`${phoneNumber}@s.whatsapp.net`);
// });
// if (phoneNumberMatches) {
// // If my extracted text has a tag then just
// if (extractedText.includes(mentionText)) {
// const mentions = filteredParticipants
// .filter((p) => p.id.includes(phoneNumber))
// .map((p) => p.id);
// console.log("Mentions:", mentions);
// }
// }
// // -----------------------------------------------
// let count = parseInt(extractedNumber);
// for (let i = 0; i < count; i++) {
// await sock.sendMessage(remoteJid, {
// text: extractedText,
// mentions: mentionIds,
// });
// await delay(500); // Adding a 1-second delay between messages
// }
// } catch (error) {
// console.log("Error while spamming ", error);
// }
// }
async function help(remoteJid, sock, messageKey) {
try {
if (!messageKey.participant) return;
const responseText =
`I can help you with the following commands:\n\n` +
`1. *!tagAll* or *!TagAll* - Tag all members in the group.\n\n` +
`2. *!tag* or *!Tag* - Tag all members in the group, excluding Suhani madam🫡.\n\n` +
`3. *"Good morning"* or *"Good night"* - React with a flower emoji🌸.\n\n` +
`4. "*@Asterin041 Spam \"<text to spam>\" <number>*" - Tag me and provide a number and a message in double quotes to spam the group.\n\n` +
`5. "*Stop @Asterin041*" - Tag me and I will stop spamming only the person who initiated the spam can make it stop.`;
const quotedMessage = {
key: messageKey,
message: {
conversation: messageKey.conversation || "Quoted text",
},
};
const options = {
quoted: quotedMessage,
};
await sock.sendMessage(
remoteJid,
{
text: responseText,
},
options
);
} catch (error) {
console.log("Error sending response:", error);
}
}
async function tagAllMembers(remoteJid, sock, messageKey) {
try {
if (!messageKey.participant) return;
const groupMetadata = await sock.groupMetadata(remoteJid);
const myId = sock.user.id.split(":")[0];
const participants = groupMetadata.participants;
const filteredParticipants = participants.filter(
(participant) =>
participant.id !== myId + "@s.whatsapp.net" &&
participant.id !== messageKey.participant
);
// console.log(filteredParticipants);
const mentions = filteredParticipants.map((p) => p.id);
//join is just joining all the elements of the array seperated by a space
const mentionText = filteredParticipants
.map((p) => `@${p.id.split("@")[0]}`)
.join(" ");
const quotedMessage = {
key: messageKey,
message: {
conversation: messageKey.conversation || "Quoted text",
},
};
const options = {
quoted: quotedMessage,
};
await sock.sendMessage(
remoteJid,
{ text: mentionText, mentions: mentions },
options
);
console.log("Tagged all members in the group, excluding yourself");
} catch (error) {
console.log("Error tagging all members:", error);
}
}
async function sendTaggedReply(remoteJid, sock, messageKey) {
try {
if (!messageKey.participant) return;
const responseText = "Yeah! 😃☺️";
const quotedMessage = {
key: messageKey,
message: {
conversation: messageKey.conversation || "Quoted text",
},
};
const options = {
quoted: quotedMessage,
};
await sock.sendMessage(
remoteJid,
{
text: responseText,
},
options
);
} catch (error) {
console.log("Error sending response:", error);
}
}
async function reactToMessage(remoteJid, sock, messageKey) {
if (!messageKey.participant) return;
const reactionMessage = {
react: {
text: "🌸", // use an empty string to remove the reaction
key: messageKey,
},
};
await sock.sendMessage(remoteJid, reactionMessage);
}
async function tagAllExceptOne(
remoteJid,
sock,
excludeId,
extraMention,
messageKey
) {
try {
if (!messageKey.participant) return;
const groupMetadata = await sock.groupMetadata(remoteJid);
const myId = sock.user.id.split(":")[0];
const participants = groupMetadata.participants;
const filteredParticipants = participants.filter(
(participant) =>
participant.id !== myId + "@s.whatsapp.net" &&
participant.id !== excludeId &&
participant.id !== messageKey.participant
);
// console.log(filteredParticipants);
const mentions = filteredParticipants.map((p) => p.id);
const isSuhaniId = participants.find((p) => p.id === excludeId); // Check if suhani is in the group
const addExtraMention =
messageKey.participant === excludeId || !isSuhaniId ? "" : extraMention;
//join is just joining all the elements of the array seperated by a space
const mentionText =
filteredParticipants.map((p) => `@${p.id.split("@")[0]}`).join(" ") +
" " +
addExtraMention;
const quotedMessage = {
key: messageKey,
message: {
conversation: messageKey.conversation || "Quoted text",
},
};
const options = {
quoted: quotedMessage,
};
await sock.sendMessage(
remoteJid,
{
text: mentionText,
mentions: mentions,
},
options
);
console.log("Tagged all members in the group, excluding yourself");
} catch (error) {
console.log("Error tagging all members:", error);
}
}
async function fetchNews() {
try {
const res = await axios.get(
`https://newsapi.org/v2/everything?q=technology+AI&domains=techcrunch.com,thenextweb.com&apiKey=${process.env.NEWS_API_KEY}`
);
const articles = res.data.articles;
let articleToSend = null;
for (let article of articles) {
if (
!sentArticles.find((sentArticle) => sentArticle.url === article.url)
) {
articleToSend = article;
break;
}
}
if (!articleToSend) {
console.log("No new articles to send.");
return "No new articles to send.";
}
console.log("Sending article:", articleToSend.title);
sentArticles.push({
url: articleToSend.url,
timestamp: articleToSend.publishedAt,
});
if (sentArticles.length > MAX_SENT_ARTICLES) {
sentArticles.shift(); // Remove the oldest article
}
console.log("Sent Articles:", sentArticles);
return articleToSend;
} catch (e) {
console.log("Error fetching news", e);
return "Unable to fetch news.";
}
}
async function fetchQuotes() {
try {
const res = await axios.get("https://zenquotes.io/api/today");
const quote = res.data[0];
const message = `"` + quote.q + `"` + " — " + quote.a;
console.log("Fetching quote:" + `"` + quote.q + `"` + " — " + quote.a);
return message;
} catch (e) {
console.log("Error fetching quote", e);
return "Unable to fetch quote.";
}
}
async function sendDailyQuote(sock, jid) {
try {
const quote = await fetchQuotes();
if (sock.ws?.readyState !== sock.ws.OPEN) {
console.error("Socket is not open. Retrying in 5 seconds...");
await new Promise((resolve) => setTimeout(resolve, 5000));
if (sock.ws?.readyState !== sock.ws.OPEN) {
console.error("Socket still not open. Skipping message send.");
return;
}
}
await sock.sendMessage(jid, { text: quote });
console.log("Quote sent successfully!");
} catch (error) {
console.error("Error sending daily quote:", error);
// Optionally, I will add retry logic here if needed
}
};
async function sendDailyNews(sock, jid) {
try {
const news = await fetchNews();
const urlFromText = news.url;
const message = news.title + " - " + news.url;
let linkPreview = null;
if (urlFromText) {
try {
// Fetch link preview
linkPreview = await getUrlInfo(urlFromText, {
thumbnailWidth: 1200,
fetchOpts: {
timeout: 5000, // 5-second timeout
},
uploadImage: sock.waUploadToServer,
});
} catch (error) {
console.error("Error fetching link preview:", error);
}
}
if (sock.ws?.readyState !== sock.ws.OPEN) {
console.error("Socket is not open. Retrying in 5 seconds...");
await new Promise(resolve => setTimeout(resolve, 5000));
if (sock.ws?.readyState !== sock.ws.OPEN) {
console.error("Socket still not open. Skipping daily news send.");
return;
}
}
// Send the news message
await sock.sendMessage(jid, {
text: message,
linkPreview,
});
console.log("News sent successfully!");
} catch (error) {
console.error("Error sending daily news:", error);
}
}
connectToWhatsApp();
// Upload periodically to Firebase (in case the folder keeps getting updated)
setInterval(async () => {
console.log("Periodic upload to Firebase...");
await uploadToFirebase(bucket);
}, 60 * 60 * 1000); // Every hour
// if (localFolderPath) {
// try {
// chokidar.watch(localFolderPath, { persistent: true }).on('all', async (event, path) => {
// console.log(`Change detected: ${event} on ${path}`);
// if (['add', 'change'].includes(event)) {
// console.log("Triggering upload to Firebase...");
// await uploadToFirebase(bucket);
// }
// }); } catch(error) {
// console.log("Error while watching auth_info_baileys: " + error);
// }
// }
app.get("/", (req, res) => {
res.send("WhatsApp bot is running");
});
app.listen(port, () => {
console.log(`Server is listening on port ${port}`);
});