Skip to content

Re-design Webhook notifier(s) #283

@isSerge

Description

@isSerge

There are few problems with current implementation:

  • Slack, Telegram, Discord are almost identical in structure and logic. Seems like a lot of duplication

  • Notifier trait is not very useful for webhook-based notifiers, because notify method just delegates to notify_with_payload of inner Webhook notifier. Slack, Telegram, Discord are essentially wrappers around Webhook notifier.

  • Also, there is issue with signing in Webhook: currently it signs a generic WebhookMessage containing only a title and body, actual JSON payload containing other fields is not singed.

Proposed solution:

  1. Keep unified Webhook notifier, eliminate separate DiscordNotifier, SlackNotifier, and TelegramNotifier structs
  2. Introduce PayloadBuilder trait, which will take message and necessary variables and produce JSON payload. Each notification type will have own implementation. Something like this:
trait WebhookPayloadBuilder {
 fn build_payload(&self, title: &str, message: &str) -> serde_json::Value;
}

struct SlackPayloadBuilder;
impl WebhookPayloadBuilder for SlackPayloadBuilder {
 fn build_payload(&self, title: &str, message: &str) -> serde_json::Value {
   // ... logic to create payload JSON for Slack
 }
}
  1. NotificationService will create multiple WebhookNotifier instances and choose relevant payload builder based on TriggerType
  2. Builder will also ensure that the final payload is signed before sending

Metadata

Metadata

Assignees

Labels

A-notifsSlack, Email, or other notification methodsD-easyBeginner-friendly tasks.P-lowLow-priority or non-urgent tasksT-taskGeneral tasks or chores (e.g., refactoring, cleanup)cla: allowlistgood-first-issueBeginner-friendly, low-complexity issues to help new contributorshelp-wantedIssues where community contributions are welcome

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions