commit 2248a4c5462e4dbe52122afd435793039c42dee4 Author: AyrisAI Date: Thu May 14 22:17:26 2026 +0300 first commit diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..bb6c3d3 --- /dev/null +++ b/.env.example @@ -0,0 +1,2 @@ +WEBHOOK_SECRET=your_secret_here +PORT=3005 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9f3441d --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +node_modules/ +.env +.DS_Store +package-lock.json diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..db4b42f --- /dev/null +++ b/Dockerfile @@ -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"] \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..586678e --- /dev/null +++ b/README.md @@ -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" +} +``` diff --git a/package.json b/package.json new file mode 100644 index 0000000..d38b235 --- /dev/null +++ b/package.json @@ -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" + } +} \ No newline at end of file diff --git a/whatsapp-worker.js b/whatsapp-worker.js new file mode 100644 index 0000000..1ae668d --- /dev/null +++ b/whatsapp-worker.js @@ -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!`)); \ No newline at end of file