@php $user = $session->user; $avatar = $user->avatar ?? 'uploads/avatars/avatar.png'; if ($avatar && !preg_match('/^https?:\/\//i', $avatar)) { $avatar = asset(ltrim($avatar, '/')); } $botSetting = \App\Models\BotSetting::first(); $toAssetUrl = function ($path, $fallback = 'frontend/img/bot.png') { $value = $path ?: $fallback; if (preg_match('/^https?:\/\//i', $value)) { return $value; } return asset(ltrim($value, '/')); }; $botNameForMessage = function ($msg) use ($botSetting) { if (!empty($msg->sender_name)) { return $msg->sender_name; } if ($msg->bot_key === 'openai') { return $botSetting->openai_name ?? 'Ms. Tuli'; } if ($msg->bot_key === 'gemini') { return $botSetting->sumi_name ?? 'Ms. Sumi'; } if ($msg->bot_key === 'aira') { return $botSetting->aira_name ?? 'Ms. Aira'; } return 'AI Assistant'; }; $botAvatarForMessage = function ($msg) use ($botSetting, $toAssetUrl) { if (!empty($msg->sender_avatar)) { return $toAssetUrl($msg->sender_avatar); } if ($msg->bot_key === 'openai') { return $toAssetUrl($botSetting->openai_avatar ?? null, 'frontend/img/openai.png'); } if ($msg->bot_key === 'gemini') { return $toAssetUrl($botSetting->sumi_avatar ?? null, 'frontend/img/sumi.png'); } if ($msg->bot_key === 'aira') { return $toAssetUrl($botSetting->aira_avatar ?? null, 'frontend/img/aira.png'); } return $toAssetUrl(null, 'frontend/img/bot.png'); }; @endphp
@foreach($session->messages as $msg) @php $isUser = $msg->sender_type === 'user'; $isAdmin = $msg->sender_type === 'admin'; $isBot = $msg->sender_type === 'bot'; $displayBotName = $isBot ? $botNameForMessage($msg) : null; $displayBotAvatar = $isBot ? $botAvatarForMessage($msg) : null; $rawText = $msg->message ? trim($msg->message) : ''; $firstUrl = null; $formattedText = ''; if ($rawText) { $pattern = '/\b(?:https?:\/\/|www\.)[^\s<]+|\b[a-zA-Z0-9][-a-zA-Z0-9]*\.(?:com|org|net|gov|edu|mil|biz|info|mobi|name|aero|asia|jobs|museum|co|io|ai|app|dev|shop|site|xyz|me|top|online|tech|store|vip|cloud|live|pro|club|link|space|icu|agency|digital)(?:\/[^\s<]*)?/i'; if (preg_match($pattern, $rawText, $match)) { $firstUrl = $match[0]; if (!preg_match('/^https?:\/\//i', $firstUrl)) { $firstUrl = 'https://' . $firstUrl; } } $formattedText = preg_replace_callback($pattern, function($matches) { $href = $matches[0]; if (!preg_match('/^https?:\/\//i', $href)) { $href = 'https://' . $href; } return ''.$matches[0].''; }, e($rawText)); $formattedText = nl2br($formattedText); } @endphp
@if(!$isAdmin) @if($isBot) {{ $displayBotName }} @else User @endif @endif
@if($isBot) {{ $displayBotName }} @endif @if($msg->message_type === 'image' && $msg->media_path) @elseif($msg->message_type === 'video' && $msg->media_path)
@elseif($msg->message_type === 'audio' && $msg->media_path)
@php $bars = [35, 60, 40, 85, 95, 70, 45, 90, 100, 60, 75, 40, 65, 80, 50, 90, 40, 30]; @endphp @foreach($bars as $h)
@endforeach
0:00
@endif @if($formattedText)
{!! $formattedText !!}
@if($firstUrl) @php $domain = parse_url($firstUrl, PHP_URL_HOST) ?? $firstUrl; @endphp @endif @endif
@endforeach