-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.js
32 lines (26 loc) · 903 Bytes
/
bot.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
// Required Libraries
const qrcode = require('qrcode-terminal');
const { Client } = require('whatsapp-web.js');
const { generateMeta } = require('./controllers/openaicontroller');
// Use this to interact with wpp account
const client = new Client();
// Generates QR-Code for authentication
client.on('qr', qr => {
qrcode.generate(qr, {small: true});
});
// Listens for all created messages (including you own)
client.on('message_create', async message => {
text_received = message.body.toLowerCase();
response = ""
// For connection tests
if(text_received === "ping") {
message.reply("pong");
}
// ChatGPT will only respond when it receives a message that starts with '#'
if(text_received[0] === "#") {
prompt = text_received.slice(1);
response = await generateMeta(prompt);
message.reply(response);
}
});
client.initialize();