Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Support multi-recipient targeting for custom notification #19768

@ssncferreira

Description

@ssncferreira

Description

Issue #19611 introduced custom notifications scoped to the requesting user. This follow-up adds recipient targeting (specific users and roles) and refines deduplication to reduce noise/spam.

Implementation

API

Extend POST /notifications/custom to accept a target object alongside content:

{
  "content": {
    "title": "Custom Title",
    "message": "Custom Message"
  },
  "target": {
    "user_ids": ["<USER_ID>", "..."],
    "roles": ["templateAdmin", "..."]
  }
}

If target is omitted, default to the requesting user (current behavior).

CLI

Update coder notifications custom "<title>" "<message>" to accept targeting flags:

  • --user-id <UUID> (repeatable)
  • --role <role> (repeatable)

UI

Update user notification settings /settings/notifications to enable/disable receiving custom notifications.

Deduplication

Coder’s notification system uses a deduplication mechanism that computes a hash for each notification based on several factors: the notification template, recipient, delivery method, payload, targets, and the creation date (truncated to day precision). As a result, duplicate notifications are not sent in the same day. This reduces noise and prevents spam. However, for custom notifications, the same message may legitimately be sent multiple times in a single day. A good approach would be:

  • For requesters sending a notification to themselves, either do not dedupe or reduce the deduplication timeframe to something shorter (e.g., 1 minute).
  • For requesters sending a notification to others, enforce similar notification limits to prevent noise.
Implementation details

Current workflow

  1. Coder executes an INSERT query on the notification_messages table
  2. Before the INSERT, the trigger function update_notification_message_dedupe_hash fires and calls compute_notification_message_dedupe_hash()
  3. The unique index notification_messages_dedupe_hash_idx on the dedupe_hash column prevents duplicate hashes.

Proposal
Update compute_notification_message_dedupe_hash() so that:

  • If the sender and recipient are the same user, deduplicate within a 1-minute truncated window (i.e., the same user cannot send the exact same message more than once within the same calendar minute).
  • For all other cases keep the existing day-based deduplication window.

Questions

  • RBAC: Is a user allowed to send notifications to everyone in the organization? Should we create a new resource specific for Custom Notifications and respective actions.

Related to

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions