Skip to content

Commit 9a39693

Browse files
committed
chore: bypass the per-day notification dedupe
1 parent 938d010 commit 9a39693

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

coderd/notifications.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ func (api *API) postCustomNotification(rw http.ResponseWriter, r *http.Request)
396396
return
397397
}
398398

399-
if _, err := api.NotificationsEnqueuer.Enqueue(
399+
if _, err := api.NotificationsEnqueuer.EnqueueWithData(
400400
//nolint:gocritic // We need to be notifier to send the notification.
401401
dbauthz.AsNotifier(ctx),
402402
user.ID,
@@ -405,6 +405,15 @@ func (api *API) postCustomNotification(rw http.ResponseWriter, r *http.Request)
405405
"custom_title": req.Content.Title,
406406
"custom_message": req.Content.Message,
407407
},
408+
map[string]any{
409+
// Current dedupe is done via an hash of (template, user, method, payload, targets, day).
410+
// We intentionally include a timestamp to bypass the per-day dedupe so the caller can
411+
// resend identical content to themselves multiple times in one day.
412+
// TODO(ssncferreira): When we support sending custom notifications to multiple users/roles,
413+
// enforce proper deduplication across recipients to reduce noise and prevent spam.
414+
// See https://github.com/coder/coder/issues/19768
415+
"dedupe_bypass_ts": api.Clock.Now().UTC(),
416+
},
408417
user.ID.String(),
409418
); err != nil {
410419
api.Logger.Error(ctx, "send custom notification", slog.Error(err))

codersdk/notifications.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ type CustomNotificationContent struct {
290290
type CustomNotificationRequest struct {
291291
Content *CustomNotificationContent `json:"content"`
292292
// TODO(ssncferreira): Add target (user_ids, roles) to support multi-user and role-based delivery.
293+
// See: https://github.com/coder/coder/issues/19768
293294
}
294295

295296
func (c CustomNotificationRequest) Validate() error {

docs/admin/monitoring/notifications/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,10 @@ At this time, custom notifications can only be sent to the user making the reque
271271

272272
To send a custom notification, execute [`coder notifications custom <title> <message>`](../../../reference/cli/notifications_custom.md).
273273

274+
<!-- TODO(ssncferreira): Update when sending custom notifications to multiple users/roles is supported.
275+
Explain deduplication behaviour for multiple users/roles.
276+
See: https://github.com/coder/coder/issues/19768
277+
-->
274278
**Note:** The recipient is always the requesting user as targeting other users or groups isn’t supported yet.
275279

276280
### Examples

0 commit comments

Comments
 (0)