mirror of
https://github.com/owncast/owncast.git
synced 2025-11-01 19:32:20 +08:00
* Initial plan * Add server status as default field in all webhooks Co-authored-by: gabek <414923+gabek@users.noreply.github.com> * Fix goimports linter error by removing trailing whitespace Co-authored-by: gabek <414923+gabek@users.noreply.github.com> * Move serverURL from status object to separate webhook field per feedback Per code review feedback, serverURL is a configuration value, not a status property. This change: - Removes ServerURL from models.Status struct - Adds ServerURL as separate field in WebhookEvent - Populates ServerURL directly when sending webhooks using configrepository.GetServerURL() - Updates all tests to expect new structure This provides the same functionality (server URL in all webhooks) while correctly treating it as configuration rather than status. Co-authored-by: gabek <414923+gabek@users.noreply.github.com> * Add omitempty tag to ServerURL field in WebhookEvent struct Co-authored-by: gabek <414923+gabek@users.noreply.github.com> * Fix webhook duplication by moving status to eventData for all events Co-authored-by: gabek <414923+gabek@users.noreply.github.com> * Restore type safety to webhook EventData using proper typed structs Co-authored-by: gabek <414923+gabek@users.noreply.github.com> * Move ServerURL from top-level WebhookEvent to eventData for all webhook types Co-authored-by: gabek <414923+gabek@users.noreply.github.com> * Update core/webhooks/webhooks.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Create BaseWebhookData struct for common webhook fields using struct embedding Co-authored-by: gabek <414923+gabek@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: gabek <414923+gabek@users.noreply.github.com> Co-authored-by: Gabe Kangas <gabek@real-ity.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
105 lines
2.7 KiB
Go
105 lines
2.7 KiB
Go
package webhooks
|
|
|
|
import (
|
|
"github.com/owncast/owncast/core/chat/events"
|
|
"github.com/owncast/owncast/models"
|
|
)
|
|
|
|
// SendChatEvent will send a chat event to webhook destinations.
|
|
func SendChatEvent(chatEvent *events.UserMessageEvent) {
|
|
webhookEvent := WebhookEvent{
|
|
Type: chatEvent.GetMessageType(),
|
|
EventData: &WebhookChatMessage{
|
|
BaseWebhookData: BaseWebhookData{
|
|
Status: getStatus(),
|
|
ServerURL: getServerURL(),
|
|
},
|
|
User: chatEvent.User,
|
|
Body: chatEvent.Body,
|
|
ClientID: chatEvent.ClientID,
|
|
RawBody: chatEvent.RawBody,
|
|
ID: chatEvent.ID,
|
|
Visible: chatEvent.HiddenAt == nil,
|
|
Timestamp: &chatEvent.Timestamp,
|
|
},
|
|
}
|
|
|
|
SendEventToWebhooks(webhookEvent)
|
|
}
|
|
|
|
// SendChatEventUsernameChanged will send a username changed event to webhook destinations.
|
|
func SendChatEventUsernameChanged(event events.NameChangeEvent) {
|
|
webhookEvent := WebhookEvent{
|
|
Type: models.UserNameChanged,
|
|
EventData: &WebhookNameChangeEventData{
|
|
BaseWebhookData: BaseWebhookData{
|
|
Status: getStatus(),
|
|
ServerURL: getServerURL(),
|
|
},
|
|
ID: event.ID,
|
|
Timestamp: event.Timestamp,
|
|
User: event.User,
|
|
NewName: event.NewName,
|
|
},
|
|
}
|
|
|
|
SendEventToWebhooks(webhookEvent)
|
|
}
|
|
|
|
// SendChatEventUserJoined sends a webhook notifying that a user has joined.
|
|
func SendChatEventUserJoined(event events.UserJoinedEvent) {
|
|
webhookEvent := WebhookEvent{
|
|
Type: models.UserJoined,
|
|
EventData: &WebhookUserJoinedEventData{
|
|
BaseWebhookData: BaseWebhookData{
|
|
Status: getStatus(),
|
|
ServerURL: getServerURL(),
|
|
},
|
|
ID: event.ID,
|
|
Timestamp: event.Timestamp,
|
|
User: event.User,
|
|
},
|
|
}
|
|
|
|
SendEventToWebhooks(webhookEvent)
|
|
}
|
|
|
|
// SendChatEventUserParted sends a webhook notifying that a user has parted.
|
|
func SendChatEventUserParted(event events.UserPartEvent) {
|
|
webhookEvent := WebhookEvent{
|
|
Type: events.UserParted,
|
|
EventData: &WebhookUserPartEventData{
|
|
BaseWebhookData: BaseWebhookData{
|
|
Status: getStatus(),
|
|
ServerURL: getServerURL(),
|
|
},
|
|
ID: event.ID,
|
|
Timestamp: event.Timestamp,
|
|
User: event.User,
|
|
},
|
|
}
|
|
|
|
SendEventToWebhooks(webhookEvent)
|
|
}
|
|
|
|
// SendChatEventSetMessageVisibility sends a webhook notifying that the visibility of one or more
|
|
// messages has changed.
|
|
func SendChatEventSetMessageVisibility(event events.SetMessageVisibilityEvent) {
|
|
webhookEvent := WebhookEvent{
|
|
Type: models.VisibiltyToggled,
|
|
EventData: &WebhookVisibilityToggleEventData{
|
|
BaseWebhookData: BaseWebhookData{
|
|
Status: getStatus(),
|
|
ServerURL: getServerURL(),
|
|
},
|
|
ID: event.ID,
|
|
Timestamp: event.Timestamp,
|
|
User: event.User,
|
|
Visible: event.Visible,
|
|
MessageIDs: event.MessageIDs,
|
|
},
|
|
}
|
|
|
|
SendEventToWebhooks(webhookEvent)
|
|
}
|