- Notifications
You must be signed in to change notification settings - Fork1k
feat: support custom notifications#19751
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Changes from1 commit
2ab1c4d
327ec0d
0d1144a
203668d
d3ffd1a
938d010
9a39693
6b8636d
80c6b22
657a230
681a29f
14e155e
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -16,17 +16,21 @@ func (r *RootCmd) notifications() *serpent.Command { | ||
Short: "Manage Coder notifications", | ||
Long: "Administrators can use these commands to change notification settings.\n" + FormatExamples( | ||
Example{ | ||
Description: "Pause Coder notifications. Administrators can temporarily stop notifiers from dispatching messages in case of the target outage (for example: unavailable SMTP server or Webhook not responding)", | ||
Command: "coder notifications pause", | ||
}, | ||
Example{ | ||
Description: "Resume Coder notifications", | ||
Command: "coder notifications resume", | ||
}, | ||
Example{ | ||
Description: "Send a test notification. Administrators can use this to verify the notification target settings", | ||
Command: "coder notifications test", | ||
}, | ||
Example{ | ||
Description: "Send a custom notification to the requesting user. The recipient is always the requesting user as targeting other users or groups isn’t supported yet", | ||
ssncferreira marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
Command: "coder notifications custom \"Custom Title\" \"Custom Message\"", | ||
}, | ||
), | ||
Aliases: []string{"notification"}, | ||
Handler: func(inv *serpent.Invocation) error { | ||
@@ -36,6 +40,7 @@ func (r *RootCmd) notifications() *serpent.Command { | ||
r.pauseNotifications(), | ||
r.resumeNotifications(), | ||
r.testNotifications(), | ||
r.customNotifications(), | ||
}, | ||
} | ||
return cmd | ||
@@ -109,3 +114,28 @@ func (r *RootCmd) testNotifications() *serpent.Command { | ||
} | ||
return cmd | ||
} | ||
func (r *RootCmd) customNotifications() *serpent.Command { | ||
client := new(codersdk.Client) | ||
cmd := &serpent.Command{ | ||
Use: "custom <title> <message>", | ||
Short: "Send a custom notification", | ||
Middleware: serpent.Chain( | ||
serpent.RequireNArgs(2), | ||
r.InitClient(client), | ||
), | ||
Handler: func(inv *serpent.Invocation) error { | ||
err := client.PostCustomNotification(inv.Context(), codersdk.CustomNotification{ | ||
Title: inv.Args[0], | ||
Message: inv.Args[1], | ||
}) | ||
if err != nil { | ||
return xerrors.Errorf("unable to post custom notification: %w", err) | ||
} | ||
_, _ = fmt.Fprintln(inv.Stderr, "A custom notification has been sent.") | ||
return nil | ||
}, | ||
} | ||
return cmd | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
coder v0.0.0-devel | ||
USAGE: | ||
coder notifications custom <title> <message> | ||
Send a custom notification | ||
——— | ||
Run `coder --help` for a list of global options. |
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
DELETE FROM notification_templates WHERE id = '39b1e189-c857-4b0c-877a-511144c18516'; | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
INSERT INTO notification_templates ( | ||
id, | ||
name, | ||
title_template, | ||
body_template, | ||
actions, | ||
"group", | ||
method, | ||
kind, | ||
enabled_by_default | ||
)VALUES ( | ||
'39b1e189-c857-4b0c-877a-511144c18516', | ||
'Custom Notification', | ||
'{{.Labels.custom_title}}', | ||
'{{.Labels.custom_message}}', | ||
'[]', | ||
'Custom Events', | ||
NULL, | ||
'system'::notification_template_kind, | ||
| ||
true | ||
); |
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.