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['RELEASE_WEBHOOK_URL'] ?? environment['WEBHOOK_URL'];
if (url == null || url.isEmpty) {
return NotificationResult.failure(name, 'Webhook URL is not configured.');
}
final headers = <String, String>{};
final secret =
environment['WEBHOOK_SECRET'] ?? environment['RELEASE_WEBHOOK_SECRET'];
if (secret != null && secret.isNotEmpty) {
headers['Authorization'] = 'Bearer $secret';
}
final response = await _client.postJson(
url,
jsonPayload: payload.toJson(),
headers: headers,
dryRun: dryRun,
);
stopwatch.stop();
if (response.isSuccess) {
return NotificationResult.success(
name,
statusCode: response.statusCode,
durationMs: stopwatch.elapsedMilliseconds,
);
} else {
return NotificationResult.failure(
name,
'Webhook request failed with status code ${response.statusCode}.',
statusCode: response.statusCode,
durationMs: stopwatch.elapsedMilliseconds,
);
}
}