$reply]); exit; } // STEP 2: Process User's Response - Option Selection $reply = ""; switch (strtolower($userMessage)) { case '1': case 'work orders': $reply = "You selected Work Orders. What would you like to do?\n1. View Today's Work Orders\n2. Search by Status\n\nPlease select an option."; break; case '2': case 'work requests': $reply = "You selected Work Requests. What would you like to do?\n1. View Pending Requests\n2. View Completed Requests\n\nPlease select an option."; break; case '3': case 'assets': $reply = "You selected Assets. What would you like to do?\n1. View Asset Details\n2. Search by Asset Location\n\nPlease select an option."; break; default: $reply = "Hi, how can I assist you today? Please choose an option:\n1. Work Orders\n2. Work Requests\n3. Assets\n\nType the number of the option you want."; } // If user input matches any option, continue the flow echo json_encode(["reply" => $reply]); exit; ?> $reply]); exit; }else if ($userMessage == '1' || strtolower($userMessage) == "View Today's Work Orders") { $reply = "You selected Work Orders. What would you like to do?\n1. View Today's Work Orders\n2. Search by Status\n\nPlease select an option."; echo json_encode(["reply" => $reply]); exit; } // STEP 4: Handle Sub-Option for "View Today's Work Orders" if ($userMessage == '1') { // Database query to get today's work orders $sql = "SELECT wko_mst_wo_no, wko_mst_originator, wko_mst_phone, wko_mst_status, wko_mst_due_date, wko_mst_descs FROM wko_mst WHERE CAST(wko_mst_org_date AS DATE) = CAST(GETDATE() AS DATE)"; // Execute the query $conn = sqlsrv_connect(DB_HOST, [ "Database" => DB_NAME, "UID" => DB_USER, "PWD" => DB_PASS ]); if (!$conn) { echo json_encode(["reply" => "Database connection failed."]); exit; } $result = sqlsrv_query($conn, $sql); if (!$result) { echo json_encode(["reply" => "SQL Error: " . sqlsrv_errors()]); exit; } $reply = "Today's Work Orders:\n"; while ($row = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC)) { $reply .= "WO No: " . $row['wko_mst_wo_no'] . "\n"; $reply .= "Originator: " . $row['wko_mst_originator'] . "\n"; $reply .= "Phone: " . $row['wko_mst_phone'] . "\n"; $reply .= "Status: " . $row['wko_mst_status'] . "\n"; $reply .= "Description: " . $row['wko_mst_descs'] . "\n"; $reply .= "Due Date: " . $row['wko_mst_due_date'] . "\n\n"; } if (empty($reply)) { $reply = "No work orders found for today."; } echo json_encode(["reply" => $reply]); exit; } // STEP 5: Handle Sub-Option for "Search by Status" if ($userMessage == '2') { $reply = "Please provide the work order status you'd like to search for (e.g., Pending, Completed)."; echo json_encode(["reply" => $reply]); exit; } // STEP 6: Handle Other Categories (Work Requests, Assets, etc.) if ($userMessage == 'work requests') { $reply = "You selected Work Requests. What would you like to do?\n1. View Pending Requests\n2. View Completed Requests\n\nPlease select an option."; echo json_encode(["reply" => $reply]); exit; } if ($userMessage == 'assets') { $reply = "You selected Assets. What would you like to do?\n1. View Asset Details\n2. Search by Asset Location\n\nPlease select an option."; echo json_encode(["reply" => $reply]);     exit; } ?>