$is_settings_page, 'isLogsPage' => $is_logs_page, 'nonce' => wp_create_nonce('wp_rest'), 'restSummarizeUrl' => esc_url_raw(rest_url('aiutoma/v1/chatbot/summarize-session')), 'restToggleManualUrl' => esc_url_raw(rest_url('aiutoma/v1/chatbot/toggle-manual')), 'restOperatorSendUrl' => esc_url_raw(rest_url('aiutoma/v1/chatbot/operator-send')), 'restPollUrl' => esc_url_raw(rest_url('aiutoma/v1/chatbot/poll')), 'restCheckNewActivityUrl' => esc_url_raw(rest_url('aiutoma/v1/chatbot/check-new-activity')), // phpcs:ignore WordPress.Security.NonceVerification.Recommended 'sessionId' => isset($_GET['session_id']) ? sanitize_text_field(wp_unslash($_GET['session_id'])) : '', 'lastCheckTime' => gmdate('Y-m-d H:i:s'), // Translations 'textGenerating' => __('Generating...', 'aiutoma'), 'textSummarize' => __('Summarize Session', 'aiutoma'), 'textSessionDigest' => __('Session Digest:', 'aiutoma'), 'textSending' => __('Sending...', 'aiutoma'), 'textSendMessage' => __('Send Message', 'aiutoma'), 'textCommError' => __('Failed to communicate with server.', 'aiutoma'), 'textImportSuccess' => __('Models imported successfully! Please click Save Changes to apply them.', 'aiutoma'), 'textImportError' => __('Invalid JSON configuration file.', 'aiutoma') ]); } } public function chatbot_public_permission_check() { if (!get_option('aiutoma_chatbot_enabled', 1)) { return new \WP_Error('chatbot_disabled', __('Chatbot is currently disabled.', 'aiutoma'), ['status' => 403]); } return true; } public function register_chatbot_routes() { register_rest_route('aiutoma/v1', '/chatbot', [ 'methods' => 'POST', 'callback' => [$this, 'handle_chatbot_request'], 'permission_callback' => [$this, 'chatbot_public_permission_check'] ]); register_rest_route('aiutoma/v1', '/chatbot/summarize-session', [ 'methods' => 'POST', 'callback' => [$this, 'handle_summarize_session_request'], 'permission_callback' => function() { return current_user_can('manage_options'); } ]); register_rest_route('aiutoma/v1', '/chatbot/poll', [ 'methods' => 'POST', 'callback' => [$this, 'handle_chatbot_poll'], 'permission_callback' => [$this, 'chatbot_public_permission_check'] ]); register_rest_route('aiutoma/v1', '/chatbot/toggle-manual', [ 'methods' => 'POST', 'callback' => [$this, 'handle_chatbot_toggle_manual'], 'permission_callback' => function() { return current_user_can('manage_options'); } ]); register_rest_route('aiutoma/v1', '/chatbot/operator-send', [ 'methods' => 'POST', 'callback' => [$this, 'handle_chatbot_operator_send'], 'permission_callback' => function() { return current_user_can('manage_options'); } ]); register_rest_route('aiutoma/v1', '/chatbot/check-new-activity', [ 'methods' => 'POST', 'callback' => [$this, 'handle_chatbot_check_new_activity'], 'permission_callback' => function() { return current_user_can('manage_options'); } ]); } public function add_chatbot_menu() { add_submenu_page( 'aiutoma', __('Frontend Chatbot', 'aiutoma'), __('Frontend Chatbot', 'aiutoma'), 'manage_options', 'aiutoma-chatbot', [$this, 'aiutoma_chatbot_page_html'] ); add_submenu_page( null, __('Chatbot Logs', 'aiutoma'), __('Chatbot Logs', 'aiutoma'), 'manage_options', 'aiutoma-chatbot-logs', [$this, 'aiutoma_chatbot_logs_page_html'] ); } }