webhooks.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. package webhooks
  2. import (
  3. "time"
  4. "github.com/owncast/owncast/core/data"
  5. "github.com/owncast/owncast/core/user"
  6. "github.com/owncast/owncast/models"
  7. )
  8. // WebhookEvent represents an event sent as a webhook.
  9. type WebhookEvent struct {
  10. Type models.EventType `json:"type"` // messageSent | userJoined | userNameChange
  11. EventData interface{} `json:"eventData,omitempty"`
  12. }
  13. // WebhookChatMessage represents a single chat message sent as a webhook payload.
  14. type WebhookChatMessage struct {
  15. User *user.User `json:"user,omitempty"`
  16. ClientID uint `json:"clientId,omitempty"`
  17. Body string `json:"body,omitempty"`
  18. RawBody string `json:"rawBody,omitempty"`
  19. ID string `json:"id,omitempty"`
  20. Visible bool `json:"visible"`
  21. Timestamp *time.Time `json:"timestamp,omitempty"`
  22. }
  23. // SendEventToWebhooks will send a single webhook event to all webhook destinations.
  24. func SendEventToWebhooks(payload WebhookEvent) {
  25. webhooks := data.GetWebhooksForEvent(payload.Type)
  26. for _, webhook := range webhooks {
  27. go addToQueue(webhook, payload)
  28. }
  29. }