testConnection method

Future<bool> testConnection()

Test the Slack connection with detailed feedback

Implementation

Future<bool> testConnection() async {
  try {
    _debugLog('Testing connection with token: ${_maskToken(botToken)}');
    final url = Uri.parse('https://slack.com/api/auth.test');

    final response = await http.post(
      url,
      headers: {
        'Authorization': 'Bearer $botToken',
        'Content-Type': 'application/json',
      },
    );

    _debugLog('Auth test response status: ${response.statusCode}');
    _debugLog('Auth test response body: ${response.body}');

    if (response.statusCode == 200) {
      final data = jsonDecode(response.body);
      final isOk = data['ok'] as bool? ?? false;

      if (isOk) {
        _debugLog('✅ Authentication successful');
        _debugLog('Bot user: ${data['user']}');
        _debugLog('Team: ${data['team']}');
      } else {
        _debugLog('❌ Authentication failed: ${data['error']}');
      }

      return isOk;
    }
    return false;
  } catch (e) {
    _debugLog('❌ Connection test error: $e');
    return false;
  }
}