chat.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package webhooks
  2. import (
  3. "github.com/owncast/owncast/core/chat/events"
  4. "github.com/owncast/owncast/models"
  5. )
  6. // SendChatEvent will send a chat event to webhook destinations.
  7. func SendChatEvent(chatEvent *events.UserMessageEvent) {
  8. webhookEvent := WebhookEvent{
  9. Type: chatEvent.GetMessageType(),
  10. EventData: &WebhookChatMessage{
  11. User: chatEvent.User,
  12. Body: chatEvent.Body,
  13. ClientID: chatEvent.ClientID,
  14. RawBody: chatEvent.RawBody,
  15. ID: chatEvent.ID,
  16. Visible: chatEvent.HiddenAt == nil,
  17. Timestamp: &chatEvent.Timestamp,
  18. },
  19. }
  20. SendEventToWebhooks(webhookEvent)
  21. }
  22. // SendChatEventUsernameChanged will send a username changed event to webhook destinations.
  23. func SendChatEventUsernameChanged(event events.NameChangeEvent) {
  24. webhookEvent := WebhookEvent{
  25. Type: models.UserNameChanged,
  26. EventData: event,
  27. }
  28. SendEventToWebhooks(webhookEvent)
  29. }
  30. // SendChatEventUserJoined sends a webhook notifying that a user has joined.
  31. func SendChatEventUserJoined(event events.UserJoinedEvent) {
  32. webhookEvent := WebhookEvent{
  33. Type: models.UserJoined,
  34. EventData: event,
  35. }
  36. SendEventToWebhooks(webhookEvent)
  37. }
  38. // SendChatEventSetMessageVisibility sends a webhook notifying that the visibility of one or more
  39. // messages has changed.
  40. func SendChatEventSetMessageVisibility(event events.SetMessageVisibilityEvent) {
  41. webhookEvent := WebhookEvent{
  42. Type: models.VisibiltyToggled,
  43. EventData: event,
  44. }
  45. SendEventToWebhooks(webhookEvent)
  46. }