lineNotifyToken = $notif['line_notify']['token'] ?? ''; $this->notifyEnabled = $notif['line_notify']['enabled'] ?? true; } /** * Notify when a new queue is assigned via Smart AI */ public function notifyQueueAssigned(array $queueData): bool { if (!$this->notifyEnabled || empty($this->lineNotifyToken)) return false; $msg = "\n🟢 [จัดสรรคิวอัตโนมัติสำเร็จ]\n"; $msg .= "• หมายเลขคิว: {$queueData['queue_no']}\n"; $msg .= "• รหัสหมอนวด: T-{$queueData['assigned_therapist_id']}\n"; $msg .= "• รหัสห้องพัก: R-{$queueData['assigned_room_id']}\n"; $msg .= "• เวลาเริ่มประมาณการ: {$queueData['est_start_time']}\n"; $msg .= "• ข้อความจาก AI: {$queueData['ai_message']}"; return $this->sendLineNotify($msg); } /** * Notify when TV display calls a queue */ public function notifyQueueCalled(string $queueNo, string $roomNo, string $patientName): bool { if (!$this->notifyEnabled || empty($this->lineNotifyToken)) return false; $msg = "\n📣 [เรียกคิวเข้ารับบริการ]\n"; $msg .= "• ขอเชิญคิวหมายเลข: {$queueNo}\n"; $msg .= "• ผู้รับบริการ: {$patientName}\n"; $msg .= "• เข้ารับบริการที่ห้อง: {$roomNo}\n"; return $this->sendLineNotify($msg); } /** * Send raw LINE Notify HTTP POST request */ private function sendLineNotify(string $message): bool { $ch = curl_init("https://notify-api.line.me/api/notify"); curl_setopt_array($ch, [ CURLOPT_POST => true, CURLOPT_POSTFIELDS => http_build_query(['message' => $message]), CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 3, CURLOPT_HTTPHEADER => [ "Authorization: Bearer {$this->lineNotifyToken}", "Content-Type: application/x-www-form-urlencoded", ], CURLOPT_SSL_VERIFYPEER => false, ]); $res = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); return $httpCode === 200; } }