send method
Future<NotificationResult>
send(
- NotificationPayload payload, {
- required Map<
String, String> environment, - bool dryRun = false,
override
Dispatches payload to the destination. Network calls MUST be skipped if dryRun is true.
Implementation
@override
Future<NotificationResult> send(
NotificationPayload payload, {
required Map<String, String> environment,
bool dryRun = false,
}) async {
final stopwatch = Stopwatch()..start();
final url = environment['SLACK_WEBHOOK_URL'];
if (url == null || url.isEmpty) {
return NotificationResult.failure(
name, 'Slack webhook URL is not configured.');
}
final slackText = '*${payload.title}*\n```\n${payload.message}\n```';
final slackPayload = <String, dynamic>{
'text': slackText,
};
final response = await _client.postJson(
url,
jsonPayload: slackPayload,
dryRun: dryRun,
);
stopwatch.stop();
if (response.isSuccess) {
return NotificationResult.success(
name,
statusCode: response.statusCode,
durationMs: stopwatch.elapsedMilliseconds,
);
} else {
return NotificationResult.failure(
name,
'Slack notification failed with status code ${response.statusCode}.',
statusCode: response.statusCode,
durationMs: stopwatch.elapsedMilliseconds,
);
}
}