{{-- Widget แชทลอย มุมล่างขวา ต่อกับ /chatbot/ask หมายเหตุสำคัญ: เงื่อนไขด้านล่างนี้ใช้ auth()->check() เป็นตัวอย่าง (แค่เช็คว่า login หรือยัง) ตามที่ตกลงไว้ว่าเมนู Quotation/Invoice ต้อง "login และเช็ค permission เดิมของระบบก่อน" ต้องแก้บรรทัด $canManageSystemMenu นี้ให้เรียกระบบ permission จริงของโปรเจกต์ เช่น auth()->user()->can('manage_quotation') หรือฟังก์ชันที่ PermissionController ใช้อยู่ (รอไฟล์ระบบ permission จริงเพื่อแก้ให้ตรงเป๊ะ) --}} @php $canManageSystemMenu = auth()->check(); // TODO: เปลี่ยนเป็นเช็ค permission จริง // ข้อความเริ่มต้น (โชว์ตอนเปิดแชทครั้งแรก) — ตั้งได้จากแท็บ "Log คำถาม" ในหน้าแอดมิน (สูงสุด 5 ข้อความ) // แต่ละข้อความแนบไฟล์ได้ 1 อย่าง (รูป/PDF/ลิงก์) เดิม hardcode ไว้ข้อความเดียวตรงๆ ใน JS ด้านล่าง // ย้ายมาดึงจาก DB แทนเพื่อให้แก้ได้โดยไม่ต้องแก้โค้ด — รองรับข้อมูลรูปแบบเก่า (array ของ string ล้วนๆ // จากก่อนที่จะเพิ่มฟีเจอร์แนบไฟล์) ด้วย โดยแปลงเป็นรูปแบบใหม่ให้อัตโนมัติตอนอ่าน $chatbotGreetingRaw = \App\Models\ChatbotSetting::get('greeting_messages'); $chatbotGreetingDecoded = $chatbotGreetingRaw ? json_decode($chatbotGreetingRaw, true) : null; if (empty($chatbotGreetingDecoded)) { $chatbotGreetingDecoded = [['text' => 'สวัสดีค่ะ 👋 มีอะไรให้ช่วยไหมคะ พิมพ์คำถาม หรือเลือกหัวข้อด้านล่างได้เลย']]; } // ประกอบ url ของไฟล์แนบให้พร้อมใช้ (รูปแบบเดียวกับ appendAttachment() ที่ใช้อยู่แล้วสำหรับคำตอบ FAQ) // ทำตรงนี้ (ฝั่ง PHP) แทนที่จะให้ JS ประกอบเอง เพราะต้องใช้ url() helper ของ Laravel ให้ได้ base path // ที่ถูกต้องเสมอ ไม่ว่าเว็บจะติดตั้งใน subdirectory หรือไม่ (เหตุผลเดียวกับที่ใช้ทั่วทั้งไฟล์นี้) $chatbotGreetingMessages = collect($chatbotGreetingDecoded)->map(function ($item) { if (is_string($item)) { return ['text' => $item, 'attachment' => null]; } $attachment = null; $type = $item['attachment_type'] ?? null; if ($type === 'link' && !empty($item['attachment_url'])) { $attachment = ['type' => 'link', 'url' => $item['attachment_url']]; } elseif (in_array($type, ['image', 'pdf'], true) && !empty($item['attachment_path'])) { $attachment = [ 'type' => $type, 'url' => url('/chatbot-greeting-attachment/' . basename($item['attachment_path'])), ]; } return ['text' => $item['text'] ?? '', 'attachment' => $attachment]; })->values()->all(); @endphp
สอบถามข้อมูล
{{-- แถบหัวข้อลัด แสดงตลอด ไม่หายไปหลังกดครั้งแรก แก้ไข/เพิ่มหัวข้อได้ในลิสต์ chatbotQuickTopics ด้านล่าง --}}