Deploy: 2026-05-21 18:21:40
This commit is contained in:
@@ -17,8 +17,7 @@ class WhatsAppController extends BaseController
|
||||
public function status(Request $request, Response $response)
|
||||
{
|
||||
$companyId = $request->company_id; // Added by AuthMiddleware
|
||||
$sessionModel = new WhatsAppSession();
|
||||
$session = $sessionModel->findOrCreate($companyId);
|
||||
$session = WhatsAppSession::findOrCreate($companyId);
|
||||
|
||||
// Strip sensitive/internal data before sending to frontend
|
||||
unset($session['phone_hash']);
|
||||
@@ -35,11 +34,10 @@ class WhatsAppController extends BaseController
|
||||
public function requestQr(Request $request, Response $response)
|
||||
{
|
||||
$companyId = $request->company_id;
|
||||
$sessionModel = new WhatsAppSession();
|
||||
$session = $sessionModel->findOrCreate($companyId);
|
||||
$session = WhatsAppSession::findOrCreate($companyId);
|
||||
|
||||
// Temporarily set to connecting
|
||||
$sessionModel->updateState($session['id'], ['status' => 'connecting']);
|
||||
WhatsAppSession::updateState($session['id'], ['status' => 'connecting']);
|
||||
|
||||
// Call Baileys Node.js Service on port 3722
|
||||
$nodeUrl = 'http://127.0.0.1:3722/api/sessions/start';
|
||||
@@ -69,7 +67,7 @@ class WhatsAppController extends BaseController
|
||||
]);
|
||||
} else {
|
||||
// Revert state on failure
|
||||
$sessionModel->updateState($session['id'], ['status' => 'disconnected']);
|
||||
WhatsAppSession::updateState($session['id'], ['status' => 'disconnected']);
|
||||
$response->status(500)->json([
|
||||
'status' => 'error',
|
||||
'message' => 'Failed to reach WhatsApp Gateway.'
|
||||
@@ -83,8 +81,7 @@ class WhatsAppController extends BaseController
|
||||
public function disconnect(Request $request, Response $response)
|
||||
{
|
||||
$companyId = $request->company_id;
|
||||
$sessionModel = new WhatsAppSession();
|
||||
$session = $sessionModel->findByCompany($companyId);
|
||||
$session = WhatsAppSession::findByCompany($companyId);
|
||||
|
||||
if ($session && $session['status'] !== 'disconnected') {
|
||||
// Call Baileys Node.js Service to disconnect
|
||||
@@ -103,7 +100,7 @@ class WhatsAppController extends BaseController
|
||||
curl_exec($ch);
|
||||
curl_close($ch);
|
||||
|
||||
$sessionModel->updateState($session['id'], [
|
||||
WhatsAppSession::updateState($session['id'], [
|
||||
'status' => 'disconnected',
|
||||
'qr_code' => null,
|
||||
'phone' => null,
|
||||
@@ -132,8 +129,7 @@ class WhatsAppController extends BaseController
|
||||
return;
|
||||
}
|
||||
|
||||
$sessionModel = new WhatsAppSession();
|
||||
$session = $sessionModel->findBySessionKey($body['session_key']);
|
||||
$session = WhatsAppSession::findBySessionKey($body['session_key']);
|
||||
|
||||
if (!$session) {
|
||||
$response->status(404)->json(['error' => 'Session not found']);
|
||||
@@ -155,7 +151,7 @@ class WhatsAppController extends BaseController
|
||||
$updateData['qr_code'] = null;
|
||||
}
|
||||
|
||||
$sessionModel->updateState($session['id'], $updateData);
|
||||
WhatsAppSession::updateState($session['id'], $updateData);
|
||||
|
||||
$response->json(['status' => 'success']);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user