$credentialsPath ]); // Format the session name $session = $sessionsClient->sessionName($projectId, $sessionId); // Create a new text input $textInput = new TextInput(); $textInput->setText($text); $textInput->setLanguageCode($languageCode); // Create a new query input $queryInput = new QueryInput(); $queryInput->setText($textInput); // Detect the intent $response = $sessionsClient->detectIntent($session, $queryInput); $queryResult = $response->getQueryResult(); $fulfillmentText = $queryResult->getFulfillmentText(); // Close the sessions client $sessionsClient->close(); return $fulfillmentText; } catch (Exception $e) { // Return a generic error message error_log($e->getMessage()); return "Error processing your request."; } } // Get the user's message from the POST request $data = json_decode(file_get_contents('php://input'), true); $userMessage = $data['message'] ?? ''; $sessionId = $data['sessionId'] ?? session_id(); // Use PHP session ID as Dialogflow session ID // Your Google Cloud Project ID $projectId = 'chrivia-asxi'; // Get the bot's reply from Dialogflow if (!empty($userMessage)) { $botReply = detect_intent_texts($projectId, $userMessage, $sessionId); } else { $botReply = 'Please say something.'; } // Return the bot's reply as JSON echo json_encode(['reply' => $botReply]);