diff --git a/backend/api/whatsapp-webhook.php b/backend/api/whatsapp-webhook.php new file mode 100644 index 0000000..a97ab9f --- /dev/null +++ b/backend/api/whatsapp-webhook.php @@ -0,0 +1,170 @@ + false, 'message' => 'unauthorized']); + exit; + } + + $input = json_decode(file_get_contents('php://input'), true); + if ($input && isset($input['state'])) { + $state = $input['state']; + $redis->set("whatsapp:status", $state); + + if ($state === 'waiting_qr' && isset($input['qr_code'])) { + // Store QR code for 60 seconds + $redis->setex("whatsapp:qr", 60, $input['qr_code']); + } elseif ($state === 'connected') { + $redis->del("whatsapp:qr"); + if (isset($input['phone'])) { + $redis->set("whatsapp:phone", $input['phone']); + } + } elseif ($state === 'disconnected') { + $redis->del("whatsapp:qr"); + $redis->del("whatsapp:phone"); + } + } + + echo json_encode(['success' => true]); + exit; +} + +// Handle GET requests (Human Web Interface to scan QR code) +$status = $redis->get("whatsapp:status") ?: 'disconnected'; +$qrCode = $redis->get("whatsapp:qr"); +$phone = $redis->get("whatsapp:phone"); +?> + + +
+ + +البوابة نشطة حالياً ومتصلة بالرقم: +
+يمكنك البدء بإرسال الرسائل الآن!
+ +افتح الواتساب على هاتفك -> الأجهزة المرتبطة -> ربط جهاز، ثم امسح الكود أدناه:
+ + + + + + ++ الرجاء تشغيل الجلسة أولاً عن طريق إرسال طلب البدء للبوابة من بوستمان أو سكريبت التشغيل. +
+ + + +حالة النظام الحالية:
+