-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
44 lines (37 loc) · 1.03 KB
/
server.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
import qrcode from 'qrcode-terminal';
import whatsappWeb from 'whatsapp-web.js';
const { LocalAuth, Client } = whatsappWeb;
import { spawn } from 'child_process';
import fs from 'fs';
const client = new Client({
authStrategy: new LocalAuth()
});
client.on('qr', qr => {
qrcode.generate(qr, {small: true});
});
client.on('ready', () => {
console.log('Client is ready!');
});
const handleMessage = async (message) => {
fs.writeFile('./currentMessage.txt', message.body, err => {
if (err) {
console.log(err);
}
})
const python = spawn('python', ['main.py']);
let dataToSend;
python.stdout.on('data', (data) => {
dataToSend = data.toString('utf8').split('|||');
});
python.on('exit', () => {
if (dataToSend) {
dataToSend.forEach(data => {
const response = data.replace(/grey_tick_emoji/g, '☑️').replace(/green_tick_emoji/g, '✅').replace(/right_arrow/g, '▶️');
message.reply(response);
});
}
})
}
client.on('message', handleMessage);
// client.on('message_create', handleMessage);
client.initialize();