['text' => $chat_message]]; } else { $error_message = "Booking ID $booking_id not found."; log_error($error_message); $result = ['data' => ['text' => $error_message]]; } } else { log_error("No matching keyword found for: $keyword"); } if (!empty($result)) { echo json_encode($result); } function get_booking_details_from_api($booking_id) { $api_url = 'https://www.korsanevents.com/wp-json/korsan/v1/booking-details/' . $booking_id; $response = file_get_contents($api_url); if ($response === FALSE) { log_error("Failed to call API: $api_url"); return null; } $booking_details = json_decode($response, true); if (isset($booking_details['code']) && $booking_details['code'] == 'no_booking') { log_error("No booking found for ID: $booking_id"); return null; } log_error("Booking details retrieved: " . print_r($booking_details, true)); return $booking_details; } function send_confirmation_to_customer($booking_details, $status) { $message_text = "Hi! Your booking with Korsan Restaurants has been $status. Here are your booking details:\n\n"; $message_text .= "Restaurant: " . $booking_details['restaurant'] . "\n"; $message_text .= "Date of Reservation: " . $booking_details['reservation_date'] . "\n"; $message_text .= "Time of Reservation: " . $booking_details['reservation_time'] . "\n"; $message_text .= "Booking Name: " . $booking_details['booking_name'] . "\n"; $message_text .= "Persons: " . $booking_details['number_persons'] . "\n"; $message_text .= "Contact Phone Number: " . $booking_details['phone_number'] . "\n"; $message_text .= "Email: " . $booking_details['email'] . "\n\n"; $message_text .= "We look forward to welcoming you at " . $booking_details['restaurant'] . "!"; $nodeurl = 'https://api.kpnotify.com/send'; $data_customer = [ 'receiver' => normalize_phone_number($booking_details['phone_number']), 'msgtext' => $message_text, 'token' => 'your_api_token', // Replace with your actual API token ]; log_error("Sending confirmation to customer: " . print_r($data_customer, true)); $ch = curl_init(); curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/x-www-form-urlencoded']); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data_customer)); curl_setopt($ch, CURLOPT_URL, $nodeurl); curl_setopt($ch, CURLOPT_TIMEOUT, 30); $response_customer = curl_exec($ch); if ($response_customer === FALSE) { log_error("Failed to send message to customer: " . curl_error($ch)); } else { log_error("Customer message response: " . $response_customer); } curl_close($ch); } function normalize_phone_number($phone_number) { // Remove all non-numeric characters except '+' $phone_number = preg_replace('/[^\d+]/', '', $phone_number); // If the phone number starts with '+', assume it's already in international format if (substr($phone_number, 0, 1) === '+') { return $phone_number; } // If the phone number starts with '00', replace it with '+' if (substr($phone_number, 0, 2) === '00') { return '+' . substr($phone_number, 2); } // If the phone number starts with '0', replace it with the default country code (e.g., '+44') if (substr($phone_number, 0, 1) === '0') { // You can change '+44' to your default country code if needed return '+44' . substr($phone_number, 1); } // Default case (assume international format without the '+') return '+' . $phone_number; } ?>