forked from amosayomide05/chatgpt-whatsapp-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
41 lines (32 loc) · 938 Bytes
/
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
const qrcode = require("qrcode-terminal");
const { Client, LocalAuth, MessageMedia } = require("whatsapp-web.js");
const client = new Client({
puppeteer: {
executablePath: '/usr/bin/google-chrome-stable',
},
authStrategy: new LocalAuth()
});
client.initialize();
client.on("qr", (qr) => {
qrcode.generate(qr, { small: true });
});
client.on("authenticated", () => {
console.log("Auth Completed!");
});
client.on("ready", () => {
console.log("Bot is ready!");
});
const sleep = (waitTimeInMs) => new Promise(resolve => setTimeout(resolve, waitTimeInMs));
client.on("message", (message) => {
(async () => {
const { ChatGPTAPI } = await import('chatgpt');
const api = new ChatGPTAPI({
sessionToken: process.env.SESSION_TOKEN,
markdown: false
});
await api.ensureAuth();
const response = await api.sendMessage(message);
await sleep(5000);
message.reply(response);
})();
});