webhook.go 927 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package models
  2. import (
  3. "time"
  4. "github.com/owncast/owncast/utils"
  5. )
  6. // Webhook is an event that is sent to 3rd party, external services with details about something that took place within an Owncast server.
  7. type Webhook struct {
  8. ID int `json:"id"`
  9. URL string `json:"url"`
  10. Events []EventType `json:"events"`
  11. Timestamp time.Time `json:"timestamp"`
  12. LastUsed *time.Time `json:"lastUsed"`
  13. }
  14. // For an event to be seen as "valid" it must live in this slice.
  15. var validEvents = []EventType{
  16. MessageSent,
  17. UserJoined,
  18. UserNameChanged,
  19. VisibiltyToggled,
  20. StreamStarted,
  21. StreamStopped,
  22. }
  23. // HasValidEvents will verify that all the events provided are valid.
  24. // This is not a efficient method.
  25. func HasValidEvents(events []EventType) bool {
  26. for _, event := range events {
  27. if _, foundInSlice := utils.FindInSlice(validEvents, event); !foundInSlice {
  28. return false
  29. }
  30. }
  31. return true
  32. }