Outbound live stream notifications (#1663)
* First pass at browser, discord, twilio notifications * Commit updated Javascript packages * Remove twilio notification support * Email notifications/smtp support * Fix Firefox notification support, remove chrome checks * WIP more email work * Add support for twitter notifications * Add stream title to discord and twitter notifications * Update notification registration modal * Fix hide/show email section * Commit updated API documentation * Commit updated Javascript packages * Fix post-rebase missing var * Remove unused var * Handle unsubscribe errors for browser push * Standardize email config prop names * Allow overriding go live email template * Some notifications cleanup * Commit updated Javascript packages * Remove email/smtp/mailjet support * Remove more references to email notifications Co-authored-by: Owncast <owncast@owncast.online>
This commit is contained in:
50
controllers/notifications.go
Normal file
50
controllers/notifications.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/owncast/owncast/notifications"
|
||||
|
||||
"github.com/owncast/owncast/utils"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// RegisterForLiveNotifications will register a channel + destination to be
|
||||
// notified when a stream goes live.
|
||||
func RegisterForLiveNotifications(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != POST {
|
||||
WriteSimpleResponse(w, false, r.Method+" not supported")
|
||||
return
|
||||
}
|
||||
|
||||
type request struct {
|
||||
// Channel is the notification channel (browser, sms, etc)
|
||||
Channel string `json:"channel"`
|
||||
// Destination is the target of the notification in the above channel.
|
||||
Destination string `json:"destination"`
|
||||
}
|
||||
|
||||
decoder := json.NewDecoder(r.Body)
|
||||
var req request
|
||||
if err := decoder.Decode(&req); err != nil {
|
||||
log.Errorln(err)
|
||||
WriteSimpleResponse(w, false, "unable to register for notifications")
|
||||
return
|
||||
}
|
||||
|
||||
// Make sure the requested channel is one we want to handle.
|
||||
validTypes := []string{notifications.BrowserPushNotification}
|
||||
_, validChannel := utils.FindInSlice(validTypes, req.Channel)
|
||||
if !validChannel {
|
||||
WriteSimpleResponse(w, false, "invalid notification channel: "+req.Channel)
|
||||
return
|
||||
}
|
||||
|
||||
if err := notifications.AddNotification(req.Channel, req.Destination); err != nil {
|
||||
log.Errorln(err)
|
||||
WriteSimpleResponse(w, false, "unable to save notification")
|
||||
return
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user