NotificationConfig.fromJson constructor

NotificationConfig.fromJson(
  1. Map<String, dynamic> json
)

Builds a notification from its YAML mapping.

Throws ArgumentError with an actionable message when a required key is missing, so ConfigParser can surface it with the position in the file.

Implementation

factory NotificationConfig.fromJson(Map<String, dynamic> json) {
  final provider = NotifyProvider.parse(_text(json, 'provider'));
  final webhookUrl = _text(json, 'webhook-url');

  if (webhookUrl == null || webhookUrl.trim().isEmpty) {
    throw ArgumentError("notifications entry requires a 'webhook-url'.");
  }

  final chatId = json['chat-id']?.toString();
  if (provider == NotifyProvider.telegram &&
      (chatId == null || chatId.isEmpty)) {
    throw ArgumentError(
      "The telegram notification provider requires a 'chat-id'.",
    );
  }

  return NotificationConfig(
    provider: provider,
    webhookUrl: webhookUrl,
    on: NotifyOn.parse(_text(json, 'on')),
    title: _text(json, 'title'),
    message: _text(json, 'message'),
    chatId: chatId,
  );
}