forked from amosayomide05/chatgpt-whatsapp-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
51 lines (41 loc) · 1.08 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
const qrcode = require("qrcode-terminal");
const { Client, LocalAuth, MessageMedia } = require("whatsapp-web.js");
const client = new Client({
puppeteer: {
executablePath: '/usr/bin/google-chrome-stable',
headless: true
},
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!");
});
(async () => {
const { ChatGPTAPI, getOpenAIAuth } = await import('chatgpt');
const openAIAuth = await getOpenAIAuth({
email: ,
password:
});
const api = new ChatGPTAPI({ ...openAIAuth });
try{
await api.initSession();
}
catch(error){
console.error("ChatGPT Auth Failed: " + error.message);
}
})();
const sleep = (waitTimeInMs) => new Promise(resolve => setTimeout(resolve, waitTimeInMs));
client.on("message", (message) => {
(async () => {
var response = await api.sendMessage(message);
await sleep(5000);
message.reply(response);
})();
});