__( 'BotPar', 'botpar' ), 'description' => __( 'Status of the AI assistant. If you contact support, copy this information.', 'botpar' ), 'fields' => array( 'version' => array( 'label' => __( 'Plugin version', 'botpar' ), 'value' => CHAT_BOT_WEB_VERSION, ), 'public_key' => array( 'label' => __( 'Public key', 'botpar' ), 'value' => $this->mask_key( (string) $opts['public_key'] ), // La public key no es secreta, pero no hace falta que viaje en cada // copiado de la información del sitio. 'private' => true, ), 'api_base' => array( 'label' => __( 'Backend', 'botpar' ), 'value' => Injector::api_base( $opts ), ), 'site_origin' => array( 'label' => __( 'Domain validated against the allowlist', 'botpar' ), 'value' => Settings::site_origin(), ), 'identify_user' => array( 'label' => __( 'Auto-identify logged-in users', 'botpar' ), 'value' => empty( $opts['identify_user'] ) ? __( 'No', 'botpar' ) : __( 'Yes', 'botpar' ), ), 'excluded_paths' => array( 'label' => __( 'Page exclusion rules', 'botpar' ), 'value' => (string) count( $paths ), ), 'debug_mode' => array( 'label' => __( 'Debug mode', 'botpar' ), 'value' => Logger::enabled() ? __( 'Enabled', 'botpar' ) : __( 'Disabled', 'botpar' ), ), 'last_test' => array( 'label' => __( 'Last connection test', 'botpar' ), 'value' => $this->last_test_summary(), ), ), ); return $info; } /** * Registra la prueba de conexión en Salud del sitio → Estado. * * @param array $tests Pruebas existentes. * @return array */ public function site_status_tests( $tests ): array { $tests = is_array( $tests ) ? $tests : array(); // Prueba directa y no asíncrona: lee el resultado guardado en vez de salir a la // red. Si el backend estuviera caído, una prueba en vivo dejaría colgada la // pantalla de Salud del sitio hasta el timeout. El botón de los ajustes es el // que refresca el dato. $tests['direct']['botpar_connection'] = array( 'label' => __( 'BotPar connection', 'botpar' ), 'test' => array( $this, 'run_status_test' ), ); return $tests; } /** * Resultado de la prueba para Salud del sitio. * * @return array */ public function run_status_test(): array { $opts = wp_parse_args( get_option( CHAT_BOT_WEB_OPTION, array() ), Settings::defaults() ); $link = admin_url( 'options-general.php?page=botpar' ); $result = array( 'label' => __( 'The BotPar widget is connected', 'botpar' ), 'status' => 'good', 'badge' => array( 'label' => __( 'BotPar', 'botpar' ), 'color' => 'blue', ), 'description' => '', 'actions' => sprintf( '
', esc_url( $link ), esc_html__( 'Go to BotPar settings', 'botpar' ) ), 'test' => 'botpar_connection', ); if ( empty( $opts['public_key'] ) ) { $result['status'] = 'recommended'; $result['label'] = __( 'BotPar is not configured yet', 'botpar' ); $result['description'] = '' . esc_html__( 'The widget public key has not been entered. Until it is, the widget does not appear on the site.', 'botpar' ) . '
'; return $result; } $last = get_transient( 'chat_bot_web_test_result' ); if ( ! is_array( $last ) || empty( $last['status'] ) ) { $result['status'] = 'recommended'; $result['label'] = __( 'The BotPar connection has not been checked', 'botpar' ); $result['description'] = '' . esc_html__( 'Go to the BotPar settings and click "Test connection" to find out whether the widget will appear.', 'botpar' ) . '
'; return $result; } $message = isset( $last['message'] ) ? (string) $last['message'] : ''; if ( 'ok' !== $last['status'] ) { $result['status'] = 'critical'; $result['label'] = __( 'The BotPar widget is not loading', 'botpar' ); } $result['description'] = '' . esc_html( $message ) . '
' . esc_html( $this->last_test_summary() ) . '
'; return $result; } /** * Resumen legible del último test guardado. * * @return string */ private function last_test_summary(): string { $last = get_transient( 'chat_bot_web_test_result' ); if ( ! is_array( $last ) || empty( $last['status'] ) ) { return __( 'Never tested', 'botpar' ); } $labels = array( 'ok' => __( 'Connected', 'botpar' ), 'warning' => __( 'Domain not allowed', 'botpar' ), 'error' => __( 'Error', 'botpar' ), ); $status = isset( $labels[ $last['status'] ] ) ? $labels[ $last['status'] ] : $labels['error']; if ( empty( $last['checked_at'] ) ) { return $status; } return sprintf( /* translators: 1: connection status, 2: date and time of the check. */ __( '%1$s (%2$s)', 'botpar' ), $status, (string) wp_date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), (int) $last['checked_at'] ) ); } /** * Muestra solo el principio de la key, suficiente para identificar cuál es. * * @param string $key Public key completa. * @return string */ private function mask_key( string $key ): string { if ( '' === $key ) { return __( 'Not configured', 'botpar' ); } if ( strlen( $key ) <= 16 ) { return $key; } return substr( $key, 0, 16 ) . '…'; } }