owncast/models/webhook.go
Pranav Joglekar 07c5cabfe8
Trigger the title updated webhook event whenever a title is changed (#2823)
* wip: trigger the title updated webhook event whenever a title is changed

* Commit updated API documentation

* fix: add STREAM_TITLE_CHANGED to list of valid events

* feat: Add support for STREAM_TITLE_CHANGED webhook event on admin dashboard

* fix: transmit webhook event after stream has changed to fix race conditions where older title was sent

---------

Co-authored-by: Owncast <owncast@owncast.online>
2023-03-28 11:34:00 -07:00

38 lines
948 B
Go

package models
import (
"time"
"github.com/owncast/owncast/utils"
)
// Webhook is an event that is sent to 3rd party, external services with details about something that took place within an Owncast server.
type Webhook struct {
ID int `json:"id"`
URL string `json:"url"`
Events []EventType `json:"events"`
Timestamp time.Time `json:"timestamp"`
LastUsed *time.Time `json:"lastUsed"`
}
// For an event to be seen as "valid" it must live in this slice.
var validEvents = []EventType{
MessageSent,
UserJoined,
UserNameChanged,
VisibiltyToggled,
StreamStarted,
StreamStopped,
StreamTitleUpdated,
}
// HasValidEvents will verify that all the events provided are valid.
// This is not a efficient method.
func HasValidEvents(events []EventType) bool {
for _, event := range events {
if _, foundInSlice := utils.FindInSlice(validEvents, event); !foundInSlice {
return false
}
}
return true
}