first commit
This commit is contained in:
commit
f7b01e079a
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
node_modules
|
||||
27
Dockerfile
Normal file
27
Dockerfile
Normal file
@ -0,0 +1,27 @@
|
||||
FROM node:20
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY package.json ./
|
||||
COPY yarn.lock ./
|
||||
RUN yarn install
|
||||
|
||||
COPY . .
|
||||
|
||||
# Puppeteer/Chrome deps
|
||||
RUN apt-get update && apt-get install -y \
|
||||
libnss3 \
|
||||
libxss1 \
|
||||
libasound2 \
|
||||
libatk-bridge2.0-0 \
|
||||
libgtk-3-0 \
|
||||
libgbm1 \
|
||||
libx11-xcb1 \
|
||||
libxcomposite1 \
|
||||
libxdamage1 \
|
||||
libxrandr2 \
|
||||
xdg-utils \
|
||||
--no-install-recommends
|
||||
|
||||
EXPOSE 3000
|
||||
CMD ["yarn", "start"]
|
||||
12
docker-compose.yml
Normal file
12
docker-compose.yml
Normal file
@ -0,0 +1,12 @@
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
whatsapp-bot:
|
||||
build: .
|
||||
container_name: whatsapp-bot
|
||||
ports:
|
||||
- "3000:3000"
|
||||
volumes:
|
||||
- ./tokens:/app/tokens
|
||||
- ./session-web-api:/app/session-web-api
|
||||
restart: unless-stopped
|
||||
93
index.js
Normal file
93
index.js
Normal file
@ -0,0 +1,93 @@
|
||||
const { create } = require('venom-bot');
|
||||
const express = require('express');
|
||||
const path = require('path');
|
||||
|
||||
let client;
|
||||
let qrCodeBase64 = null;
|
||||
let isConnected = false;
|
||||
|
||||
const app = express();
|
||||
app.use(express.static('public'));
|
||||
app.use(express.json());
|
||||
|
||||
// 📄 Page avec QR Code
|
||||
app.get('/login', (req, res) => {
|
||||
res.sendFile(path.join(__dirname, 'public', 'login.html'));
|
||||
});
|
||||
|
||||
// 📄 Page "connecté"
|
||||
app.get('/connected', (req, res) => {
|
||||
res.sendFile(path.join(__dirname, 'public', 'connected.html'));
|
||||
});
|
||||
|
||||
// 🔄 QR code en base64 + état de connexion
|
||||
app.get('/api/qrcode', (req, res) => {
|
||||
res.json({ qr: qrCodeBase64, connected: isConnected });
|
||||
});
|
||||
|
||||
// ✅ API POST : envoie message avec boutons
|
||||
app.post('/sendButtons', async (req, res) => {
|
||||
const { phone, title, message, buttons } = req.body;
|
||||
|
||||
console.log('📥 Requête reçue :');
|
||||
console.log('Phone:', phone);
|
||||
console.log('Title:', title);
|
||||
console.log('Message:', message);
|
||||
console.log('Buttons brut:', buttons);
|
||||
|
||||
if (!client) return res.status(500).json({ error: 'Client WhatsApp non initialisé' });
|
||||
if (!phone || !message || !title || !Array.isArray(buttons)) {
|
||||
return res.status(400).json({ error: 'Paramètres manquants ou invalides' });
|
||||
}
|
||||
|
||||
try {
|
||||
const formattedButtons = buttons.map(btn => ({
|
||||
buttonText: { displayText: btn.text }
|
||||
}));
|
||||
|
||||
console.log('✅ Boutons formatés pour Venom :', formattedButtons);
|
||||
|
||||
await client.sendButtons(
|
||||
`${phone}@c.us`,
|
||||
title, // ✅ OBLIGATOIRE en 1er
|
||||
message, // ✅ Description
|
||||
formattedButtons // ✅ Format conforme
|
||||
);
|
||||
|
||||
res.json({ success: true });
|
||||
} catch (error) {
|
||||
console.error('❌ Erreur sendButtons:', error);
|
||||
res.status(500).json({ error: error.message || 'Erreur interne' });
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
// ▶️ Démarrage + QR code init
|
||||
create({
|
||||
session: 'session-web-api',
|
||||
catchQR: (base64Qrimg, asciiQR) => {
|
||||
qrCodeBase64 = base64Qrimg;
|
||||
isConnected = false;
|
||||
},
|
||||
puppeteerOptions: {
|
||||
headless: 'new',
|
||||
args: ['--no-sandbox', '--disable-setuid-sandbox']
|
||||
}
|
||||
}).then((cl) => {
|
||||
client = cl;
|
||||
|
||||
client.onStateChange((state) => {
|
||||
if (state === 'CONNECTED') isConnected = true;
|
||||
});
|
||||
|
||||
client.onStreamChange((state) => {
|
||||
if (state === 'CONNECTED') isConnected = true;
|
||||
});
|
||||
|
||||
}).catch((err) => {
|
||||
console.error('Erreur init Venom:', err);
|
||||
});
|
||||
|
||||
app.listen(3000, () => console.log('🚀 Serveur lancé sur http://localhost:3000/login'));
|
||||
7896
package-lock.json
generated
Normal file
7896
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
14
package.json
Normal file
14
package.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "whatsappServer",
|
||||
"version": "1.0.0",
|
||||
"main": "index.js",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"start": "node index.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"body-parser": "^2.2.0",
|
||||
"express": "^5.1.0",
|
||||
"venom-bot": "^5.3.0"
|
||||
}
|
||||
}
|
||||
12
public/connected.html
Normal file
12
public/connected.html
Normal file
@ -0,0 +1,12 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Connecté !</title>
|
||||
<style>
|
||||
body { font-family: sans-serif; text-align: center; margin-top: 50px; color: green; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>✅ Connexion réussie à WhatsApp !</h1>
|
||||
</body>
|
||||
</html>
|
||||
32
public/login.html
Normal file
32
public/login.html
Normal file
@ -0,0 +1,32 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Connexion WhatsApp</title>
|
||||
<style>
|
||||
body { font-family: sans-serif; text-align: center; margin-top: 50px; }
|
||||
img { width: 300px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Scannez ce QR Code</h1>
|
||||
<div id="qr-container">Chargement du QR Code...</div>
|
||||
|
||||
<script>
|
||||
async function fetchQR() {
|
||||
const res = await fetch('/api/qrcode');
|
||||
const data = await res.json();
|
||||
|
||||
if (data.connected) {
|
||||
window.location.href = '/connected';
|
||||
} else if (data.qr) {
|
||||
document.getElementById('qr-container').innerHTML =
|
||||
`<img src="${data.qr}" alt="QR Code WhatsApp">`;
|
||||
}
|
||||
|
||||
setTimeout(fetchQR, 3000);
|
||||
}
|
||||
|
||||
fetchQR();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
0
tokens/session-web-api/Crashpad/metadata
Normal file
0
tokens/session-web-api/Crashpad/metadata
Normal file
BIN
tokens/session-web-api/Crashpad/settings.dat
Normal file
BIN
tokens/session-web-api/Crashpad/settings.dat
Normal file
Binary file not shown.
BIN
tokens/session-web-api/CrashpadMetrics-active.pma
Normal file
BIN
tokens/session-web-api/CrashpadMetrics-active.pma
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user