Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: http.createServer is not a function #130

Open
joyboyyyyyy opened this issue Nov 26, 2024 · 0 comments
Open

TypeError: http.createServer is not a function #130

joyboyyyyyy opened this issue Nov 26, 2024 · 0 comments

Comments

@joyboyyyyyy
Copy link

Preciso de uma ajuda urgente!!! ;-;
Estou seguindo um tutorial do youtube para criar um bot de whatsapp, o meu está exatamente identico ao do vídeo mas o meu fica apontando esse erro TypeError: http.createServer is not a function e o do vídeo funciona normalmente, já estou a horas tentando resolver e não consigo, estou usando a versão do node js que o rapaz do video indica (v14) mas não sei mais o que fazer, vou deixar o meu código ai em baixo se alguém puder me dar uma luz por favor!!!

arquivo.js:
// BACKEND DA API
// BIBLIOTECAS UTILIZADAS PARA COMPOSIÇÃO DA API
const { Client, LocalAuth, MessageMedia } = require('whatsapp-web.js');
const express = require('express');
const socketIO = require('socket.io');
const qrcode = require('qrcode');
const http = require('express-fileupload');
const fileUpload = require('express-validator');
const app = express();
const server = http.createServer(app);
const io = socketIO(server);

// PORTA ONDE O SERVIÇO SERÁ INICIADO
const port = 8000;
const idClient = 'bot-reloadskins';

// NUMEROS AUTORIZADOS
const permissaoBot = ["[email protected]"];

// SERVIÇO EXPRESS
app.use(express.json());
app.use(express.urlencoded({
extended: true
}));
app.use(fileUpload({
debug: true
}));
app.use("/", express.static(__dirname + "/"))

app.get('/', (req, res) => {
res.sendFile('index.html', {
root: __dirname
});
});

// PARÂMETROS DO CLIENT DO WPP
const client = new Client({
authStrategy: new LocalAuth({ clientId: idClient }),
puppeteer: {headless: true,
// CAMINHO DO CHROME PARA WINDOWS (REMOVER O COMENTÁRIO ABAIXO)
// executablePath: 'C:\Program Files\Google\Chrome\Application\chrome.exe',
// ==================================================================================
// CAMINHO DO CHROME PARA MAC (REMOVER O COMENTÁRIO ABAIXO)
//executablePath: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
//===================================================================================
// CAMINHO DO CHROME PARA LINUX (REMOVER O COMENTÁRIO ABAIXO)
//executablePath: '/usr/bin/google-chrome-stable',
//===================================================================================
args: [
'--no-sandbox',
'--disable-setuid-sandbox',
'--disable-accelerated-2d-canvas',
'--no-first-run',
'--no-zygote',
'--single-process', // <- this one doesn't works in Windows
'--disable-gpu'
] }
});

// INITIALIZE DO CLIENT DO WPP
client.initialize();

// EVENTOS DE CONEXÃO EXPORTADOS PARA O INDEX.HTML VIA SOCKET
io.on('connection', function(socket) {
socket.emit('message', 'Ⓒ BOT-RELOADSKINS - Iniciado');
socket.emit('qr', './icon.svg');

client.on('qr', (qr) => {
console.log('QR RECEIVED', qr);
qrcode.toDataURL(qr, (err, url) => {
socket.emit('qr', url);
socket.emit('message', 'Ⓒ BOT-RELOADSKINS QRCode recebido, aponte a câmera do seu celular!');
});
});

client.on('ready', async () => {
socket.emit('ready', 'Ⓒ BOT-RELOADSKINS Dispositivo pronto!');
socket.emit('message', 'Ⓒ BOT-RELOADSKINS Dispositivo pronto!');
socket.emit('qr', './check.svg')
console.log('Ⓒ BOT-RELOADSKINS Dispositivo pronto');
const groups = await client.getChats()
for (const group of groups){
if(group.id.server.includes('g.us')){
socket.emit('message', 'Nome: ' + group.name + ' - ID: ' + group.id._serialized.split('@')[0]);
console.log('Nome: ' + group.name + ' - ID: ' + group.id._serialized.split('@')[0])
}
}
});

client.on('authenticated', () => {
socket.emit('authenticated', 'Ⓒ BOT-RELOADSKINS Autenticado!');
socket.emit('message', 'Ⓒ BOT-RELOADSKINS Autenticado!');
console.log('Ⓒ BOT RELOADSKINS Autenticado');
});

client.on('auth_failure', function() {
socket.emit('message', 'Ⓒ BOT-RELOADSKINS Falha na autenticação, reiniciando...');
console.error('Ⓒ BOT-RELOADSKINS Falha na autenticação');
});

client.on('change_state', state => {
console.log('Ⓒ BOT-RELOADSKINS Status de conexão: ', state);
});

client.on('disconnected', (reason) => {
socket.emit('message', 'Ⓒ BOT-RELOADSKINS Cliente desconectado!');
console.log('Ⓒ BOT-RELOADSKINS Cliente desconectado', reason);
client.initialize();
});
});

// EVENTO DE ESCUTA DE MENSAGENS RECEBIDAS PELA API
client.on('message', async msg => {

if (msg.body === null) return;

// REMOVER MENSAGEM DE NÚMEROS NÃO AUTORIZADOS
if (!permissaoBot.includes(msg.author || msg.from)) {
try{
msg.delete(true)
client.sendMessage(msg.from, "😎 Você não tem autorização para enviar mensagens.")
} catch (e){
console.log('Ⓒ Comunidade ZDG')
}
}
});

// INITIALIZE DO SERVIÇO
server.listen(port, function() {
console.log('Ⓒ Comunidade ZDG - Aplicativo rodando na porta *: ' + port);
});

package.json
{
"name": "bot-reloadskins",
"version": "1.0.0",
"description": "bot-reloadskins: based on Whatsapp API",
"main": "app.js",
"scripts": {
"start": "node .\botzdg_typebot_stop.js",
"start:dev": "nodemon app.js",
"test": "echo "Error: no test specified" && exit 1"
},
"keywords": [
"whatsapp-api",
"node.js"
],
"author": "Pedro",
"license": "MIT",
"dependencies": {
"axios": "1.5.0",
"express": "4.17.1",
"express-fileupload": "1.2.0",
"express-validator": "6.9.2",
"http": "0.0.1-security",
"qrcode": "1.4.4",
"qrcode-terminal": "0.12.0",
"socket.io": "2.3.0",
"whatsapp-web.js": "1.23.0"
},
"devDependencies": {
"nodemon": "^2.0.19"
}
}

index.html

<title>WPP API by Pedrinho da NASA</title>
<div id="app">
	<h1>WPP API</h1>
	<h3>Entre agora para comunidade ZDG: <a href="https://comunidadedzdg.com.br/">clique aqui</a></h3>
	<p>ZDG MOD</p>
	<img src="" alt="QR Code" id="qrcode">
	<h3>Logs:</h3>
	<ul class="logs"></ul>
</div>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.min.js" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.3.0/socket.io.js" crossorigin="anonymous"></script>
<script>
	$(document).ready(function() {
		var socket = io ();
		
		socket.on('message', function(msg) {
			$('.logs').append($('<li>').text(msg));
		});
		
		socket.on('qr', function(src) {
			$('#qrcode').attr('src', src);
			$('#qrcode').show();
		});
		
		socket.on('ready', function(data) {
			$('#qrcode').hide();
		});
		
		socket.on('authenticated', function(data) {
			$('#qrcode').hide();
		});
	});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant