run method
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.');
}