Deploy: 2026-05-21 18:06:46
This commit is contained in:
@@ -52,7 +52,10 @@ class WhatsAppController extends BaseController
|
|||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
curl_setopt($ch, CURLOPT_POST, true);
|
curl_setopt($ch, CURLOPT_POST, true);
|
||||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
|
||||||
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
|
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||||
|
'Content-Type: application/json',
|
||||||
|
'X-Webhook-Secret: ' . getenv('WEBHOOK_SECRET')
|
||||||
|
]);
|
||||||
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
|
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
|
||||||
$result = curl_exec($ch);
|
$result = curl_exec($ch);
|
||||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||||
@@ -92,7 +95,10 @@ class WhatsAppController extends BaseController
|
|||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
curl_setopt($ch, CURLOPT_POST, true);
|
curl_setopt($ch, CURLOPT_POST, true);
|
||||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
|
||||||
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
|
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||||
|
'Content-Type: application/json',
|
||||||
|
'X-Webhook-Secret: ' . getenv('WEBHOOK_SECRET')
|
||||||
|
]);
|
||||||
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
|
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
|
||||||
curl_exec($ch);
|
curl_exec($ch);
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ if (!fs.existsSync(SESSIONS_DIR)) {
|
|||||||
fs.mkdirSync(SESSIONS_DIR, { recursive: true });
|
fs.mkdirSync(SESSIONS_DIR, { recursive: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
const WEBHOOK_SECRET = process.env.WEBHOOK_SECRET || 'YOUR_SECRET_KEY_HERE';
|
const WEBHOOK_SECRET = process.env.WEBHOOK_SECRET;
|
||||||
|
|
||||||
async function sendWebhook(webhook_url, payload) {
|
async function sendWebhook(webhook_url, payload) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -28,11 +28,20 @@ app.use(express.json());
|
|||||||
|
|
||||||
const PORT = process.env.PORT || 3722;
|
const PORT = process.env.PORT || 3722;
|
||||||
|
|
||||||
// Health check endpoint
|
// Health check endpoint (Public)
|
||||||
app.get('/health', (req, res) => {
|
app.get('/health', (req, res) => {
|
||||||
res.json({ status: 'healthy', service: 'Nabeh WhatsApp Gateway' });
|
res.json({ status: 'healthy', service: 'Nabeh WhatsApp Gateway' });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Security Middleware: Protect all /api/ routes
|
||||||
|
app.use('/api', (req, res, next) => {
|
||||||
|
const secret = req.header('X-Webhook-Secret');
|
||||||
|
if (!process.env.WEBHOOK_SECRET || secret !== process.env.WEBHOOK_SECRET) {
|
||||||
|
return res.status(403).json({ error: 'Unauthorized gateway access' });
|
||||||
|
}
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
|
||||||
// Start or retrieve a session
|
// Start or retrieve a session
|
||||||
app.post('/api/sessions/start', async (req, res) => {
|
app.post('/api/sessions/start', async (req, res) => {
|
||||||
const { session_key, webhook_url } = req.body;
|
const { session_key, webhook_url } = req.body;
|
||||||
|
|||||||
Reference in New Issue
Block a user