forked from HyTech-Group/wabot-ai
-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
49 lines (47 loc) · 2.09 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
require('dotenv').config();
const { HyWaBot, HytechMessages, HytechHandle, HytechHandleGemini } = require('wabot-ai');
const data = {
phoneNumber: process.env.PHONE,
sessionId: 'session',
useStore: true,
};
const bot = new HyWaBot(data);
bot.start()
.then(sock => {
sock.ev.on('messages.upsert', async chatUpdate => {
try {
let m = chatUpdate.messages[0];
if (!m.message) return;
const result = await HytechMessages(m);
console.log('Processed message:', result);
let cmd;
if (result.chatsFrom === 'private') {
cmd = result.message;
} else if (result.chatsFrom === 'group') {
cmd = result.participant ? result.participant.message : result.message;
}
if (cmd.startsWith(process.env.PREFIX_OPENAI)) {
const messageToProcess = cmd.replace(process.env.PREFIX_OPENAI, '').trim();
const response = await HytechHandle(messageToProcess);
sock.sendMessage(result.remoteJid, { text: response });
}
if (cmd.startsWith(process.env.PREFIX_GEMINI)) {
const messageToProcess = cmd.replace(process.env.PREFIX_GEMINI, '').trim();
const response = await HytechHandleGemini(messageToProcess);
sock.sendMessage(result.remoteJid, { text: response });
}
if (cmd.startsWith('.source')) {
sock.sendMessage(result.remoteJid, { text: `*Whastapp Bot OpenAI*
WhatsApp Chatbot is our project for AI-based conversations on WhatsApp messages using openAI technology.
- Github: https://github.com/HyTech-Group/wabot-ai
- Npm: https://www.npmjs.com/package/wabot-ai
- Official Website: https://hy-tech.my.id/` });
}
} catch (error) {
console.error('Error processing message:', error);
}
});
})
.catch(error => {
console.error('Error starting bot:', error);
});