From 5883801989ef15357aeb038250052b9f79c5ab40 Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Sat, 4 Jul 2026 16:25:10 -0500 Subject: [PATCH] fix: prepend api_base_url to relative endpoint URLs in NormalBot After migration stripped base URLs from DB records, bot was calling relative paths (e.g. /ruta) as-is without the base. buildUrl() helper now prepends api_base_url for all four curl call sites. Co-Authored-By: Claude Sonnet 4.6 --- services/NormalBot.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/services/NormalBot.php b/services/NormalBot.php index 11ae068..155af89 100644 --- a/services/NormalBot.php +++ b/services/NormalBot.php @@ -233,7 +233,7 @@ class NormalBot if (!$ep || empty($ep['url'])) return null; $apiKey = $company['api_key'] ?? ''; - $url = self::substituteUrlVars($ep['url'], $meta); + $url = self::buildUrl(self::substituteUrlVars($ep['url'], $meta), $company); $ch = curl_init($url); curl_setopt_array($ch, [ CURLOPT_RETURNTRANSFER => true, @@ -410,7 +410,7 @@ class NormalBot } $apiKey = $company['api_key'] ?? ''; - $ch = curl_init($ep['url']); + $ch = curl_init(self::buildUrl($ep['url'], $company)); curl_setopt_array($ch, [ CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true, @@ -561,7 +561,7 @@ class NormalBot 'nombre' => $context['name'] ?? '', ]); - $ch = curl_init($ep['url']); + $ch = curl_init(self::buildUrl($ep['url'], $company)); curl_setopt_array($ch, [ CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true, @@ -778,7 +778,10 @@ class NormalBot unset($meta['__ep_vars'], $meta['__ep_vars_flat']); ConversationContext::updateMetadata($ctxId, $meta); - $url = self::substituteUrlVars($ep['url'], array_merge($meta, ['__ep_vars_combined' => $meta['__ep_vars_combined'] ?? []])); + $url = self::buildUrl( + self::substituteUrlVars($ep['url'], array_merge($meta, ['__ep_vars_combined' => $meta['__ep_vars_combined'] ?? []])), + $company + ); $method = strtoupper($ep['method'] ?? 'GET'); $apiKey = $company['api_key'] ?? ''; @@ -1072,6 +1075,12 @@ class NormalBot return is_array($config) ? $config : []; } + private static function buildUrl(string $relOrAbs, array $company): string + { + if ($relOrAbs === '' || str_starts_with($relOrAbs, 'http')) return $relOrAbs; + return rtrim($company['api_base_url'] ?? '', '/') . '/' . ltrim($relOrAbs, '/'); + } + private static function normalize(string $input): string { $input = mb_strtolower(trim($input));