wabot-openai
v1.0.3
Published
Whastapp Bot OpenAI (HyTech Group)
Downloads
3
Maintainers
Readme
Whatsapp Bot OpenAI NodeJS
Turn your WhatsApp into an AI chatbot integrated by OpenAI
NPM Installation
npm i wabot-openai
Setting .env
API_KEY = "you apiKey"
MODEL = "gpt-3.5-turbo-1106"
COMMAND = "Command for AI."
PHONE = "628xxxxxxx"
PREFIX = ".gpt"
Implementation index.js
require('dotenv').config();
const { HyWaBot, HytechMessages, HytechHandle } = require('wabot-openai');
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)) {
const messageToProcess = cmd.replace(process.env.PREFIX, '').trim();
const response = await HytechHandle(messageToProcess);
sock.sendMessage(result.remoteJid, { text: response });
}
} catch (error) {
console.error('Error processing message:', error);
}
});
})
.catch(error => {
console.error('Error starting bot:', error);
});
Run
node index.js
Get ApiKey
Official Site OpenAI: https://openai.com/
Don't forget to give stars
Follow Me: FOLLOW