chat.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. // SendChatEventUserParted sends a webhook notifying that a user has parted.
  39. func SendChatEventUserParted(event events.UserPartEvent) {
  40. webhookEvent := WebhookEvent{
  41. Type: events.UserParted,
  42. EventData: event,
  43. }
  44. SendEventToWebhooks(webhookEvent)
  45. }
  46. // SendChatEventSetMessageVisibility sends a webhook notifying that the visibility of one or more
  47. // messages has changed.
  48. func SendChatEventSetMessageVisibility(event events.SetMessageVisibilityEvent) {
  49. webhookEvent := WebhookEvent{
  50. Type: models.VisibiltyToggled,
  51. EventData: event,
  52. }
  53. SendEventToWebhooks(webhookEvent)
  54. }