first commit
This commit is contained in:
2
.env.example
Normal file
2
.env.example
Normal file
@@ -0,0 +1,2 @@
|
||||
WEBHOOK_SECRET=your_secret_here
|
||||
PORT=3005
|
||||
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
node_modules/
|
||||
.env
|
||||
.DS_Store
|
||||
package-lock.json
|
||||
19
Dockerfile
Normal file
19
Dockerfile
Normal file
@@ -0,0 +1,19 @@
|
||||
FROM node:20-slim
|
||||
|
||||
# Chromium ve gerekli kütüphaneleri kuruyoruz (WhatsApp için şart)
|
||||
RUN apt-get update && apt-get install -y \
|
||||
chromium \
|
||||
fonts-ipafont-gothic \
|
||||
fonts-wqy-zenhei \
|
||||
--no-install-recommends \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
WORKDIR /app
|
||||
COPY package*.json ./
|
||||
RUN npm install
|
||||
COPY . .
|
||||
|
||||
# Puppeteer'ın Docker içinde çalışması için gerekli bayrak
|
||||
ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium
|
||||
|
||||
CMD ["node", "whatsapp-worker.js"]
|
||||
26
README.md
Normal file
26
README.md
Normal file
@@ -0,0 +1,26 @@
|
||||
# AyrisTech WhatsApp Gateway
|
||||
|
||||
A simple WhatsApp Gateway worker using `whatsapp-web.js` and `express`.
|
||||
|
||||
## Features
|
||||
- QR Code generation for authentication
|
||||
- Message sending via HTTP POST
|
||||
- Multi-user support via LocalAuth
|
||||
|
||||
## Setup
|
||||
1. Clone the repository
|
||||
2. Run `npm install`
|
||||
3. Copy `.env.example` to `.env` and configure your settings
|
||||
4. Run `npm start`
|
||||
|
||||
## API
|
||||
### Send Message
|
||||
**POST** `/send-message`
|
||||
```json
|
||||
{
|
||||
"secret": "your_webhook_secret",
|
||||
"userId": "unique_user_id",
|
||||
"to": "phone_number",
|
||||
"message": "your_message"
|
||||
}
|
||||
```
|
||||
19
package.json
Normal file
19
package.json
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"name": "ayristech-whatsapp",
|
||||
"version": "1.0.0",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"start": "node whatsapp-worker.js"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"description": "",
|
||||
"dependencies": {
|
||||
"dotenv": "^16.4.5",
|
||||
"express": "^5.2.1",
|
||||
"qrcode-terminal": "^0.12.0",
|
||||
"whatsapp-web.js": "^1.34.7"
|
||||
}
|
||||
}
|
||||
47
whatsapp-worker.js
Normal file
47
whatsapp-worker.js
Normal file
@@ -0,0 +1,47 @@
|
||||
require('dotenv').config();
|
||||
const { Client, LocalAuth } = require('whatsapp-web.js');
|
||||
const express = require('express');
|
||||
const app = express();
|
||||
app.use(express.json());
|
||||
|
||||
const WEBHOOK_SECRET = process.env.WEBHOOK_SECRET;
|
||||
const PORT = process.env.PORT || 3005;
|
||||
const clients = new Map();
|
||||
|
||||
const getClient = (userId) => {
|
||||
if (clients.has(userId)) return clients.get(userId);
|
||||
|
||||
const client = new Client({
|
||||
authStrategy: new LocalAuth({ clientId: userId }),
|
||||
puppeteer: {
|
||||
headless: true,
|
||||
args: ['--no-sandbox', '--disable-setuid-sandbox']
|
||||
}
|
||||
});
|
||||
|
||||
client.on('qr', (qr) => {
|
||||
// Terminalde boğulma diye link veriyoruz
|
||||
console.log(`\n[QR] KODU BURADAN OKUT: https://api.qrserver.com/v1/create-qr-code/?data=${encodeURIComponent(qr)}\n`);
|
||||
});
|
||||
|
||||
client.on('ready', () => console.log(`[OK] ${userId} oturumu başarıyla açıldı!`));
|
||||
|
||||
client.initialize();
|
||||
clients.set(userId, client);
|
||||
return client;
|
||||
};
|
||||
|
||||
app.post('/send-message', async (req, res) => {
|
||||
const { secret, userId, to, message } = req.body;
|
||||
if (secret !== WEBHOOK_SECRET) return res.status(401).send('Yetkisiz erişim!');
|
||||
|
||||
try {
|
||||
const client = getClient(userId);
|
||||
await client.sendMessage(`${to}@c.us`, message);
|
||||
res.send({ success: true });
|
||||
} catch (err) {
|
||||
res.status(500).send({ success: false, error: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
app.listen(PORT, () => console.log(`WhatsApp Worker ${PORT} portunda aktif!`));
|
||||
Reference in New Issue
Block a user