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 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
f06be3584f
commit
5883801989
+13
-4
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user