run method

  1. @override
Future<void> run()
override

Runs this command.

The return value is wrapped in a Future if necessary and returned by CommandRunner.runCommand.

Implementation

@override
Future<void> run() async {
  final channel = argResults!['channel'] as String;

  print('๐Ÿงช Testing Slack Integration');
  print('โ•' * 50);

  // Check if Slack is configured
  final slackToken = await ConfigService.getSlackBotToken();
  if (slackToken == null) {
    print('โŒ Slack not configured.');
    print('๐Ÿ’ก Run "udara_cli setup" to configure Slack first.');
    return;
  }

  print('โœ… Slack token found');
  print('๐ŸŽฏ Target channel: $channel');
  print('');

  // Create service with debug mode
  final slackService = SlackService(
    botToken: slackToken,
    channel: channel,
    debugMode: true,
  );

  // Test 1: Authentication
  print('๐Ÿ” Testing authentication...');
  final authSuccess = await slackService.testConnection();
  if (!authSuccess) {
    print('โŒ Authentication failed. Check your bot token.');
    return;
  }
  print('โœ… Authentication successful\n');

  // Test 2: Simple message
  print('๐Ÿ“ Sending test message...');
  final messageSuccess = await slackService.sendMessage(
    '๐Ÿงช Test message from Udara CLI at ${DateTime.now()}',
    emoji: ':robot_face:',
  );

  if (messageSuccess) {
    print('โœ… Simple message sent successfully\n');
  } else {
    print('โŒ Failed to send simple message\n');
    _printTroubleshootingTips(channel);
    return;
  }

  // Test 3: Rich message
  print('๐ŸŽจ Sending rich message...');
  final richSuccess = await slackService.sendRichMessage(
    title: '๐Ÿงช Rich Message Test',
    message: 'This is a test of rich message formatting',
    color: 'good',
    fields: {
      'Test Type': 'Rich Message',
      'Status': 'Testing',
      'Timestamp': DateTime.now().toString(),
    },
  );

  if (richSuccess) {
    print('โœ… Rich message sent successfully\n');
  } else {
    print('โŒ Failed to send rich message\n');
  }

  // Test 4: Build notification simulation
  print('๐Ÿš€ Simulating build notification...');
  await slackService.sendBuildStepNotification(
    step: 'Test Build Step',
    client: 'test-client',
    platform: 'android',
    status: 'completed',
    additionalInfo: 'This is a test notification',
  );

  print('');
  print('๐ŸŽ‰ Slack test completed!');
  print(
      '๐Ÿ’ก If you received messages in $channel, Slack integration is working correctly.');
}