Add files via upload
This commit is contained in:
commit
10cf8e4e9f
|
@ -0,0 +1,15 @@
|
|||
# WHATSAPP CHATGPT
|
||||
This is a source code to build a WhatsApp bot using OpenAI bot and Node.js. The bot is capable of understanding natural language and providing information on various topics. It can be used to answer questions, provide advice, and even have conversations with users. With this source code, you can create a powerful bot that can be used for a variety of purposes. <br>
|
||||
|
||||
NOTE: DON'T MESS UP WITH INDEX.JS FILE. <br>
|
||||
|
||||
# How to Install?
|
||||
$ git clone https://github.com/ShadowHackrs/Whatsapp-Bot <br>
|
||||
$ cd whatsapp-chatgpt <br>
|
||||
$ npm install <br>
|
||||
$ node index.js <br>
|
||||
|
||||
Visit: https://shadowhackr.com <br>
|
||||
|
||||
# How to get OpenAI API?
|
||||
Visit: https://beta.openai.com/account/api-keys
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"keyopenai": "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",
|
||||
"autoAI": true,
|
||||
"donasi": "HEY, I'M ADIL SADQI, VISIT: HTTPS://adil.asadqi.com"
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
{
|
||||
"name": "Whatsapp-chatgpt",
|
||||
"version": "1",
|
||||
"description": "WHATSAPP CHATGPT BOT, USING OPENAI",
|
||||
"main": "index.js",
|
||||
"type": "commonjs",
|
||||
"scripts": {
|
||||
"start": "node index.js"
|
||||
},
|
||||
"keywords": [
|
||||
"termux",
|
||||
"whatsapp-openai",
|
||||
"whatsapp-openai",
|
||||
"whatsapp-bot",
|
||||
"whatsapp-baileys",
|
||||
"baileys-md",
|
||||
"bot-wa",
|
||||
"bot-md",
|
||||
"whatsapp-multi-device"
|
||||
],
|
||||
"base": "https://github.com/ShadowHackrs",
|
||||
"author": "ShadowHackrs",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@adiwajshing/baileys": "4.4.0",
|
||||
"@adiwajshing/keyed-db": "^0.2.4",
|
||||
"awesome-phonenumber": "^2.64.0",
|
||||
"chalk": "^4.1.2",
|
||||
"crypto": "^1.0.1",
|
||||
"figlet": "^1.5.2",
|
||||
"fs": "0.0.1-security",
|
||||
"lodash": "^4.17.21",
|
||||
"openai": "^3.1.0",
|
||||
"pino": "^7.0.5",
|
||||
"qrcode-terminal": "^0.12.0",
|
||||
"util": "^0.12.4"
|
||||
},
|
||||
"directories": {
|
||||
"lib": "lib",
|
||||
"src": "src"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/ShadowHackrs/Whatsapp-Bot.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/ShadowHackrs/Whatsapp-Bot/issues"
|
||||
},
|
||||
"homepage": "https://github.com/ShadowHackrs/Whatsapp-Bot#readme"
|
||||
}
|
|
@ -0,0 +1,141 @@
|
|||
const { BufferJSON, WA_DEFAULT_EPHEMERAL, generateWAMessageFromContent, proto, generateWAMessageContent, generateWAMessage, prepareWAMessageMedia, areJidsSameUser, getContentType } = require('@adiwajshing/baileys')
|
||||
const fs = require('fs')
|
||||
const util = require('util')
|
||||
const chalk = require('chalk')
|
||||
const { Configuration, OpenAIApi } = require("openai")
|
||||
let setting = require('./key.json')
|
||||
|
||||
module.exports = sansekai = async (client, m, chatUpdate, store) => {
|
||||
try {
|
||||
var body = (m.mtype === 'conversation') ? m.message.conversation : (m.mtype == 'imageMessage') ? m.message.imageMessage.caption : (m.mtype == 'videoMessage') ? m.message.videoMessage.caption : (m.mtype == 'extendedTextMessage') ? m.message.extendedTextMessage.text : (m.mtype == 'buttonsResponseMessage') ? m.message.buttonsResponseMessage.selectedButtonId : (m.mtype == 'listResponseMessage') ? m.message.listResponseMessage.singleSelectReply.selectedRowId : (m.mtype == 'templateButtonReplyMessage') ? m.message.templateButtonReplyMessage.selectedId : (m.mtype === 'messageContextInfo') ? (m.message.buttonsResponseMessage?.selectedButtonId || m.message.listResponseMessage?.singleSelectReply.selectedRowId || m.text) : ''
|
||||
var budy = (typeof m.text == 'string' ? m.text : '')
|
||||
// var prefix = /^[\\/!#.]/gi.test(body) ? body.match(/^[\\/!#.]/gi) : "/"
|
||||
var prefix = /^[\\/!#.]/gi.test(body) ? body.match(/^[\\/!#.]/gi) : "/"
|
||||
const isCmd2 = body.startsWith(prefix)
|
||||
const command = body.replace(prefix, '').trim().split(/ +/).shift().toLowerCase()
|
||||
const args = body.trim().split(/ +/).slice(1)
|
||||
const pushname = m.pushName || "No Name"
|
||||
const botNumber = await client.decodeJid(client.user.id)
|
||||
const itsMe = m.sender == botNumber ? true : false
|
||||
let text = q = args.join(" ")
|
||||
const arg = budy.trim().substring(budy.indexOf(' ') + 1 )
|
||||
const arg1 = arg.trim().substring(arg.indexOf(' ') + 1 )
|
||||
|
||||
const from = m.chat
|
||||
const reply = m.reply
|
||||
const sender = m.sender
|
||||
const mek = chatUpdate.messages[0]
|
||||
|
||||
const color = (text, color) => {
|
||||
return !color ? chalk.green(text) : chalk.keyword(color)(text)
|
||||
}
|
||||
|
||||
// Group
|
||||
const groupMetadata = m.isGroup ? await client.groupMetadata(m.chat).catch(e => {}) : ''
|
||||
const groupName = m.isGroup ? groupMetadata.subject : ''
|
||||
|
||||
// Push Message To Console
|
||||
let argsLog = (budy.length > 30) ? `${q.substring(0, 30)}...` : budy
|
||||
|
||||
if (setting.autoAI) {
|
||||
// Push Message To Console && Auto Read
|
||||
if (argsLog && !m.isGroup) {
|
||||
// client.sendReadReceipt(m.chat, m.sender, [m.key.id])
|
||||
console.log(chalk.black(chalk.bgWhite('[ LOGS ]')), color(argsLog, 'turquoise'), chalk.magenta('From'), chalk.green(pushname), chalk.yellow(`[ ${m.sender.replace('@s.whatsapp.net', '')} ]`))
|
||||
} else if (argsLog && m.isGroup) {
|
||||
// client.sendReadReceipt(m.chat, m.sender, [m.key.id])
|
||||
console.log(chalk.black(chalk.bgWhite('[ LOGS ]')), color(argsLog, 'turquoise'), chalk.magenta('From'), chalk.green(pushname), chalk.yellow(`[ ${m.sender.replace('@s.whatsapp.net', '')} ]`), chalk.blueBright('IN'), chalk.green(groupName))
|
||||
}
|
||||
} else if (!setting.autoAI) {
|
||||
if (isCmd2 && !m.isGroup) {
|
||||
console.log(chalk.black(chalk.bgWhite('[ LOGS ]')), color(argsLog, 'turquoise'), chalk.magenta('From'), chalk.green(pushname), chalk.yellow(`[ ${m.sender.replace('@s.whatsapp.net', '')} ]`))
|
||||
} else if (isCmd2 && m.isGroup) {
|
||||
console.log(chalk.black(chalk.bgWhite('[ LOGS ]')), color(argsLog, 'turquoise'), chalk.magenta('From'), chalk.green(pushname), chalk.yellow(`[ ${m.sender.replace('@s.whatsapp.net', '')} ]`), chalk.blueBright('IN'), chalk.green(groupName))
|
||||
}
|
||||
}
|
||||
|
||||
if (setting.autoAI) {
|
||||
if (budy) {
|
||||
try {
|
||||
if (setting.keyopenai === 'ISI_APIKEY_OPENAI_DISINI') return reply('Apikey belum diisi\n\nSilahkan isi terlebih dahulu apikeynya di file key.json\n\nApikeynya bisa dibuat di website: https://beta.openai.com/account/api-keys')
|
||||
const configuration = new Configuration({
|
||||
apiKey: setting.keyopenai,
|
||||
});
|
||||
const openai = new OpenAIApi(configuration);
|
||||
|
||||
const response = await openai.createCompletion({
|
||||
model: "text-davinci-003",
|
||||
prompt: budy,
|
||||
temperature: 0.3,
|
||||
max_tokens: 3000,
|
||||
top_p: 1.0,
|
||||
frequency_penalty: 0.0,
|
||||
presence_penalty: 0.0,
|
||||
});
|
||||
m.reply(`${response.data.choices[0].text}\n\n`)
|
||||
} catch(err) {
|
||||
console.log(err)
|
||||
m.reply('Maaf, sepertinya ada yang error')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!setting.autoAI) {
|
||||
if (isCmd2) {
|
||||
switch(command) {
|
||||
case 'ai':
|
||||
try {
|
||||
if (setting.keyopenai === 'ISI_APIKEY_OPENAI_DISINI') return reply('Api key has not been filled in\n\nPlease fill in the apikey first in the key.json file\n\nThe apikey can be created in website: https://beta.openai.com/account/api-keys')
|
||||
if (!text) return reply(`Chat dengan AI.\n\nContoh:\n${prefix}${command} Apa itu resesi`)
|
||||
const configuration = new Configuration({
|
||||
apiKey: setting.keyopenai,
|
||||
});
|
||||
const openai = new OpenAIApi(configuration);
|
||||
|
||||
const response = await openai.createCompletion({
|
||||
model: "text-davinci-003",
|
||||
prompt: text,
|
||||
temperature: 0.3,
|
||||
max_tokens: 3000,
|
||||
top_p: 1.0,
|
||||
frequency_penalty: 0.0,
|
||||
presence_penalty: 0.0,
|
||||
});
|
||||
m.reply(`${response.data.choices[0].text}\n\n`)
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
m.reply('Maaf, sepertinya ada yang error')
|
||||
}
|
||||
break
|
||||
default:{
|
||||
|
||||
if (isCmd2 && budy.toLowerCase() != undefined) {
|
||||
if (m.chat.endsWith('broadcast')) return
|
||||
if (m.isBaileys) return
|
||||
if (!(budy.toLowerCase())) return
|
||||
if (argsLog || isCmd2 && !m.isGroup) {
|
||||
// client.sendReadReceipt(m.chat, m.sender, [m.key.id])
|
||||
console.log(chalk.black(chalk.bgRed('[ ERROR ]')), color('command', 'turquoise'), color(argsLog, 'turquoise'), color('tidak tersedia', 'turquoise'))
|
||||
} else if (argsLog || isCmd2 && m.isGroup) {
|
||||
// client.sendReadReceipt(m.chat, m.sender, [m.key.id])
|
||||
console.log(chalk.black(chalk.bgRed('[ ERROR ]')), color('command', 'turquoise'), color(argsLog, 'turquoise'), color('tidak tersedia', 'turquoise'))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
m.reply(util.format(err))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let file = require.resolve(__filename)
|
||||
fs.watchFile(file, () => {
|
||||
fs.unwatchFile(file)
|
||||
console.log(chalk.redBright(`Update ${__filename}`))
|
||||
delete require.cache[file]
|
||||
require(file)
|
||||
})
|
Loading…
Reference in New Issue