diff --git a/backend/app/Controllers/CampaignController.php b/backend/app/Controllers/CampaignController.php index a85acf7..23f587b 100644 --- a/backend/app/Controllers/CampaignController.php +++ b/backend/app/Controllers/CampaignController.php @@ -145,8 +145,12 @@ class CampaignController extends BaseController return; } - $gatewayUrl = getenv('WHATSAPP_GATEWAY_URL') ?: 'http://localhost:3722'; - $sendUrl = $gatewayUrl . '/api/messages/send'; + $gatewayUrl = rtrim(getenv('WHATSAPP_GATEWAY_URL') ?: 'http://localhost:3722', '/'); + if (substr($gatewayUrl, -4) === '/api') { + $sendUrl = $gatewayUrl . '/messages/send'; + } else { + $sendUrl = $gatewayUrl . '/api/messages/send'; + } foreach ($contacts as $rawContact) { // Decrypt contact data diff --git a/backend/app/Controllers/GroupController.php b/backend/app/Controllers/GroupController.php index 37bd615..d168973 100644 --- a/backend/app/Controllers/GroupController.php +++ b/backend/app/Controllers/GroupController.php @@ -14,11 +14,10 @@ class GroupController extends BaseController public function index(Request $request, Response $response) { $groupModel = new ContactGroup(); - // Since ContactGroup extends BaseModel we can access the DB connection - $groups = $groupModel->db->query( + $groups = \App\Core\Database::select( "SELECT * FROM contact_groups WHERE company_id = ? ORDER BY id DESC", [$request->company_id] - )->fetchAll(); + ); $response->json([ 'status' => 'success', diff --git a/backend/app/Controllers/WhatsAppController.php b/backend/app/Controllers/WhatsAppController.php index 6bcd3d1..2690229 100644 --- a/backend/app/Controllers/WhatsAppController.php +++ b/backend/app/Controllers/WhatsAppController.php @@ -244,8 +244,12 @@ class WhatsAppController extends BaseController if (!empty($replyText)) { // Send reply back to the contact via Node.js Gateway - $gatewayUrl = getenv('WHATSAPP_GATEWAY_URL') ?: 'http://localhost:3722'; - $sendUrl = $gatewayUrl . '/api/messages/send'; + $gatewayUrl = rtrim(getenv('WHATSAPP_GATEWAY_URL') ?: 'http://localhost:3722', '/'); + if (substr($gatewayUrl, -4) === '/api') { + $sendUrl = $gatewayUrl . '/messages/send'; + } else { + $sendUrl = $gatewayUrl . '/api/messages/send'; + } $payload = json_encode([ 'session_key' => $session['session_key'], diff --git a/backend/public/debug-chatbot.php b/backend/public/debug-chatbot.php new file mode 100644 index 0000000..03f9f71 --- /dev/null +++ b/backend/public/debug-chatbot.php @@ -0,0 +1,24 @@ + $rules, + 'messages_log' => $logs, + 'whatsapp_sessions' => $sessions +], JSON_PRETTY_PRINT);