-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
90 lines (81 loc) · 2.6 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
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
import webwhats from 'whatsapp-web.js';
const { Client, LocalAuth } = webwhats;
import qrcode from 'qrcode-terminal';
import { processCommand } from './command_process.js';
import readline from 'node:readline';
import { sendCommand } from './Commands/send.js';
import { retrieveCommand } from './Commands/retrieve.js';
import { chatsCommand } from './Commands/chats.js';
import { readCommand } from './Commands/read.js';
import { scheduleCommand } from './Commands/schedule.js';
import { tasksCommand } from './Commands/tasks.js';
import { timeCommand } from './Commands/time.js';
import { exitCommand } from './Commands/exit.js';
import { logger } from './Commands/logger.js';
import { task_manager } from './task_manager.js';
import { processInput } from './Utils.js';
const wwebVersion = '2.2412.54';
const client = new Client({
puppeteer: {
args: ['--no-sandbox', '--disable-setuid-sandbox'],
},
authStrategy: new LocalAuth({
dataPath: '.data'
}),
webVersionCache: {
type: 'remote',
remotePath: `https://raw.githubusercontent.com/wppconnect-team/wa-version/main/html/${wwebVersion}.html`,
},
});
const taskManager = new task_manager(client);
const message_logger = new logger();
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
client.initialize();
client.on('loading_screen', (percent, message) => {
console.log('LOADING SCREEN', percent, message);
});
//TODO: support matching text to respond
const commandpros = async () =>{
return new Promise((resolve,reject) => {
rl.question('>', async (input) => {
const listOfCommands = [
sendCommand(),
retrieveCommand(),
chatsCommand(),
readCommand(),
scheduleCommand(),
tasksCommand(),
message_logger.loggerCommand(),
timeCommand(),
exitCommand()
];
await processCommand(processInput(input),client,rl,taskManager,listOfCommands);
resolve();
await commandpros();
});
});
}
client.on('ready', () => {
console.log('Welcome to WhatsApp automation, help to get list of commands');
commandpros();
});
client.on('qr', qr => {
qrcode.generate(qr, {small: true});
});
process.on('SIGINT SIGQUT SIGTERM', () => {
process.exit(0);
}); // CTRL+C Keyboard quit `kill` command
process.on('uncaughtException', (err) => {
console.log(err.stack);
process.exit(0);
});
process.on('exit', () => {
console.log(new Date().toLocaleString());
console.log('Destroying Session....');
client.destroy();
console.log('Bye Bye')
process.exit(0);
});