package messages import ( "fmt" "go.fifitido.net/twitch/api/eventsub" ) type SessionWelcomePayload struct { Session Session `json:"session"` } type SessionKeepAlivePayload struct{} type NotificationPayload struct { Subscription eventsub.Subscription `json:"subscription"` Event any `json:"event"` } type SessionReconnectPayload struct { Session Session `json:"session"` } type RevocationPayload struct { Subscription eventsub.Subscription `json:"subscription"` } func DecodePayload(meta *Metadata, rawPayload map[string]any) (any, error) { switch meta.MessageType { case TypeSessionWelcome: return decode[SessionWelcomePayload](rawPayload) case TypeSessionKeepAlive: return SessionKeepAlivePayload{}, nil case TypeNotification: return decodeNotificationPayload(rawPayload) case TypeSessionReconnect: return decode[SessionReconnectPayload](rawPayload) case TypeRevocation: return decode[RevocationPayload](rawPayload) default: return nil, fmt.Errorf("unknown message type: %s", meta.MessageType) } }