Skip to content

Take control over your live stream video by running it yourself. Streaming + chat out of the box.

implement custom welcome message (#820)

nebunez561f63aa2e62
diff --git a/config/defaults.go b/config/defaults.go
index 9c966b3001..bb5fc56355 100644
--- a/config/defaults.go
+++ b/config/defaults.go
@@ -4,12 +4,13 @@ import "github.com/owncast/owncast/models"
// Defaults will hold default configuration values.
type Defaults struct {
- Name string
- Title string
- Summary string
- Logo string
- Tags []string
- PageBodyContent string
+ Name string
+ Title string
+ Summary string
+ ServerWelcomeMessage string
+ Logo string
+ Tags []string
+ PageBodyContent string
DatabaseFilePath string
WebServerPort int
@@ -27,10 +28,11 @@ type Defaults struct {
// GetDefaults will return default configuration values.
func GetDefaults() Defaults {
return Defaults{
- Name: "Owncast",
- Title: "My Owncast Server",
- Summary: "This is brief summary of whom you are or what your stream is. You can edit this description in the admin.",
- Logo: "logo.svg",
+ Name: "Owncast",
+ Title: "My Owncast Server",
+ Summary: "This is brief summary of whom you are or what your stream is. You can edit this description in the admin.",
+ ServerWelcomeMessage: "",
+ Logo: "logo.svg",
Tags: []string{
"owncast",
"streaming",
diff --git a/controllers/admin/config.go b/controllers/admin/config.go
index ea6d370d55..9b7f812267 100644
--- a/controllers/admin/config.go
+++ b/controllers/admin/config.go
@@ -6,6 +6,7 @@ import (
"net/http"
"path/filepath"
"reflect"
+ "strings"
"github.com/owncast/owncast/controllers"
"github.com/owncast/owncast/core"
@@ -120,6 +121,25 @@ func SetServerSummary(w http.ResponseWriter, r *http.Request) {
controllers.WriteSimpleResponse(w, true, "changed")
}
+// SetServerWelcomeMessage will handle the web config request to set the welcome message text.
+func SetServerWelcomeMessage(w http.ResponseWriter, r *http.Request) {
+ if !requirePOST(w, r) {
+ return
+ }
+
+ configValue, success := getValueFromRequest(w, r)
+ if !success {
+ return
+ }
+
+ if err := data.SetServerWelcomeMessage(strings.TrimSpace(configValue.Value.(string))); err != nil {
+ controllers.WriteSimpleResponse(w, false, err.Error())
+ return
+ }
+
+ controllers.WriteSimpleResponse(w, true, "changed")
+}
+
// SetExtraPageContent will handle the web config request to set the page markdown content.
func SetExtraPageContent(w http.ResponseWriter, r *http.Request) {
if !requirePOST(w, r) {
diff --git a/controllers/admin/serverConfig.go b/controllers/admin/serverConfig.go
index 6d99f001b2..8ba2d8ebdc 100644
--- a/controllers/admin/serverConfig.go
+++ b/controllers/admin/serverConfig.go
@@ -35,6 +35,7 @@ func GetServerConfig(w http.ResponseWriter, r *http.Request) {
Tags: data.GetServerMetadataTags(),
ExtraPageContent: data.GetExtraPageBodyContent(),
StreamTitle: data.GetStreamTitle(),
+ WelcomeMessage: data.GetServerWelcomeMessage(),
Logo: data.GetLogoPath(),
SocialHandles: data.GetSocialHandles(),
NSFW: data.GetNSFW(),
@@ -85,6 +86,7 @@ type videoSettings struct {
type webConfigResponse struct {
Name string `json:"name"`
Summary string `json:"summary"`
+ WelcomeMessage string `json:"welcomeMessage"`
Logo string `json:"logo"`
Tags []string `json:"tags"`
Version string `json:"version"`
diff --git a/core/chat/server.go b/core/chat/server.go
index 9ce5c5ee8e..01dfada58b 100644
--- a/core/chat/server.go
+++ b/core/chat/server.go
@@ -182,8 +182,10 @@ func (s *server) sendWelcomeMessageToClient(c *Client) {
// Add an artificial delay so people notice this message come in.
time.Sleep(7 * time.Second)
- initialChatMessageText := fmt.Sprintf("Welcome to %s! %s", data.GetServerName(), data.GetServerSummary())
- initialMessage := models.ChatEvent{ClientID: "owncast-server", Author: data.GetServerName(), Body: initialChatMessageText, ID: "initial-message-1", MessageType: "SYSTEM", Visible: true, Timestamp: time.Now()}
- c.write(initialMessage)
+ welcomeMessage := data.GetServerWelcomeMessage()
+ if welcomeMessage != "" {
+ initialMessage := models.ChatEvent{ClientID: "owncast-server", Author: data.GetServerName(), Body: welcomeMessage, ID: "initial-message-1", MessageType: "SYSTEM", Visible: true, Timestamp: time.Now()}
+ c.write(initialMessage)
+ }
}()
}
diff --git a/core/data/config.go b/core/data/config.go
index 9455748eff..1655fc2117 100644
--- a/core/data/config.go
+++ b/core/data/config.go
@@ -16,6 +16,7 @@ const streamTitleKey = "stream_title"
const streamKeyKey = "stream_key"
const logoPathKey = "logo_path"
const serverSummaryKey = "server_summary"
+const serverWelcomeMessageKey = "server_welcome_message"
const serverNameKey = "server_name"
const serverURLKey = "server_url"
const httpPortNumberKey = "http_port_number"
@@ -119,6 +120,22 @@ func SetServerSummary(summary string) error {
return _datastore.SetString(serverSummaryKey, summary)
}
+// GetServerWelcomeMessage will return the server welcome message text.
+func GetServerWelcomeMessage() string {
+ welcomeMessage, err := _datastore.GetString(serverWelcomeMessageKey)
+ if err != nil {
+ log.Debugln(serverWelcomeMessageKey, err)
+ return config.GetDefaults().ServerWelcomeMessage
+ }
+
+ return welcomeMessage
+}
+
+// SetServerWelcomeMessage will set the server welcome message text.
+func SetServerWelcomeMessage(welcomeMessage string) error {
+ return _datastore.SetString(serverWelcomeMessageKey, welcomeMessage)
+}
+
// GetServerName will return the server name text.
func GetServerName() string {
name, err := _datastore.GetString(serverNameKey)
diff --git a/core/data/defaults.go b/core/data/defaults.go
index 4519b6736a..f523874942 100644
--- a/core/data/defaults.go
+++ b/core/data/defaults.go
@@ -28,6 +28,7 @@ func PopulateDefaults() {
_ = SetLogoPath(defaults.Logo)
_ = SetServerMetadataTags([]string{"owncast", "streaming"})
_ = SetServerSummary("Welcome to your new Owncast server! This description can be changed in the admin")
+ _ = SetServerWelcomeMessage("")
_ = SetServerName("Owncast")
_ = SetStreamKey(defaults.StreamKey)
_ = SetExtraPageBodyContent("This is your page's content that can be edited in the admin.")
diff --git a/router/router.go b/router/router.go
index e28c48cb39..dc42bf7232 100644
--- a/router/router.go
+++ b/router/router.go
@@ -109,6 +109,9 @@ func Start() error {
// Server summary
http.HandleFunc("/api/admin/config/serversummary", middleware.RequireAdminAuth(admin.SetServerSummary))
+ // Server welcome message
+ http.HandleFunc("/api/admin/config/welcomemessage", middleware.RequireAdminAuth(admin.SetServerWelcomeMessage))
+
// Disable chat
http.HandleFunc("/api/admin/config/chat/disable", middleware.RequireAdminAuth(admin.SetChatDisabled))