go-twitch/api/eventsub/models.go

218 lines
12 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package eventsub
import "time"
type Condition map[string]any
type Subscription struct {
// An ID that identifies the subscription.
ID string `json:"id"`
// The subscriptions status. The subscriber receives events only for enabled subscriptions. Possible values are:
//
// enabled — The subscription is enabled.
//
// webhook_callback_verification_pending — The subscription is pending verification of the specified callback URL (see Responding to a challenge request).
Status string `json:"status"`
// The subscriptions type.
// See Subscription Types: https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#subscription-types
Type string `json:"type"`
// The version number that identifies this definition of the subscriptions data.
Version string `json:"version"`
// The subscriptions parameter values. This is a string-encoded JSON object whose contents are determined by the subscription type.
Condition Condition `json:"condition"`
// The date and time (in RFC3339 format) of when the subscription was created.
CreatedAt time.Time `json:"created_at"`
// The transport details used to send the notifications.
Transport *Transport `json:"transport"`
// The amount that the subscription counts against your limit.
// Learn More: https://dev.twitch.tv/docs/eventsub/manage-subscriptions/#subscription-limits
Cost int `json:"cost"`
}
type Status string
const (
// enabled — The subscription is enabled.
StatusEnabled = "enabled"
// webhook_callback_verification_pending — The subscription is pending verification of the specified callback URL.
StatusWebhookCallbackVerificationPending = "webhook_callback_verification_pending"
// webhook_callback_verification_failed — The specified callback URL failed verification.
StatusWebhookCallbackVerificationFailed = "webhook_callback_verification_failed"
// notification_failures_exceeded — The notification delivery failure rate was too high.
NotificationFailuresExceeded = "notification_failures_exceeded"
// authorization_revoked — The authorization was revoked for one or more users specified in the Condition object.
AuthorizationRevoked = "authorization_revoked"
// moderator_removed — The moderator that authorized the subscription is no longer one of the broadcaster's moderators.
ModeratorRemoved = "moderator_removed"
// user_removed — One of the users specified in the Condition object was removed.
UserRemoved = "user_removed"
// version_removed — The subscription to subscription type and version is no longer supported.
VersionRemoved = "version_removed"
// beta_maintenance — The subscription to the beta subscription type was removed due to maintenance.
BetaMaintenance = "beta_maintenance"
// websocket_disconnected — The client closed the connection.
WebsocketDisconnected = "websocket_disconnected"
// websocket_failed_ping_pong — The client failed to respond to a ping message.
WebsocketFailedPingPong = "websocket_failed_ping_pong"
// websocket_received_inbound_traffic — The client sent a non-pong message.
// Clients may only send pong messages (and only in response to a ping message).
WebsocketReceivedInboundTraffic = "websocket_received_inbound_traffic"
// websocket_connection_unused — The client failed to subscribe to events within the required time.
WebsocketConnectionUnused = "websocket_connection_unused"
// websocket_internal_error — The Twitch WebSocket server experienced an unexpected error.
WebsocketInternalError = "websocket_internal_error"
// websocket_network_timeout — The Twitch WebSocket server timed out writing the message to the client.
WebsocketNetworkTimeout = "websocket_network_timeout"
// websocket_network_error — The Twitch WebSocket server experienced a network error writing the message to the client.
WebsocketnetworkError = "websocket_network_error"
)
type Transport struct {
// The transport method. Possible values are:
//
// webhook, websocket, conduit
Method string `json:"method"`
// The callback URL where the notifications are sent. The URL must use the HTTPS protocol and port 443.
// See Processing an event. Specify this field only if method is set to webhook.
//
// NOTE: Redirects are not followed.
Callback *string `json:"callback,omitempty"`
// The secret used to verify the signature.
// The secret must be an ASCII string thats a minimum of 10 characters long and a maximum of 100 characters long.
// For information about how the secret is used,
// see Verifying the event message: https://dev.twitch.tv/docs/eventsub/handling-webhook-events#verifying-the-event-message
// Specify this field only if method is set to webhook.
Secret *string `json:"secret,omitempty"`
// An ID that identifies the WebSocket to send notifications to. When you connect to EventSub using WebSockets,
// the server returns the ID in the Welcome message. Specify this field only if method is set to websocket.
SessionID *string `json:"session_id,omitempty"`
// An ID that identifies the conduit to send notifications to.
// When you create a conduit, the server returns the conduit ID.
// Specify this field only if method is set to conduit.
ConduitID *string `json:"conduit_id,omitempty"`
}
func WebhookTransport(callback string, secret string) *Transport {
return &Transport{
Method: "webhook",
Callback: &callback,
Secret: &secret,
SessionID: nil,
ConduitID: nil,
}
}
func WebSocketTransport(sessionID string) *Transport {
return &Transport{
Method: "websocket",
Callback: nil,
Secret: nil,
SessionID: &sessionID,
ConduitID: nil,
}
}
func ConduitTransport(conduitID string) *Transport {
return &Transport{
Method: "websocket",
Callback: nil,
Secret: nil,
SessionID: nil,
ConduitID: &conduitID,
}
}
type SubscriptionType struct {
// The type of subscription.
Name string `json:"type"`
// The version number that identifies the definition of the subscription type that you want the response to use.
Version string `json:"version"`
}
var (
ChannelUpdate = SubscriptionType{Name: "channel.update", Version: "2"}
ChannelFollow = SubscriptionType{Name: "channel.follow", Version: "2"}
ChannelAdBreakBegin = SubscriptionType{Name: "channel.ad_break_begin", Version: "1"}
ChannelChatClear = SubscriptionType{Name: "channel.chat.clear", Version: "1"}
ChannelChatClearUserMessages = SubscriptionType{Name: "channel.chat.clear_user_messages", Version: "1"}
ChannelChatMessage = SubscriptionType{Name: "channel.chat.message", Version: "1"}
ChannelChatMessageDelete = SubscriptionType{Name: "channel.chat.message_delete", Version: "1"}
ChannelChatNotification = SubscriptionType{Name: "channel.chat.notification", Version: "1"}
ChannelChatSettingsUpdate = SubscriptionType{Name: "channel.chat_settings.update", Version: "beta"}
ChannelSubscribe = SubscriptionType{Name: "channel.subscribe", Version: "1"}
ChannelSubscriptionEnd = SubscriptionType{Name: "channel.subscription.end", Version: "1"}
ChannelSubscriptionGift = SubscriptionType{Name: "channel.subscription.gift", Version: "1"}
ChannelSubscriptionMessage = SubscriptionType{Name: "channel.subscription.message", Version: "1"}
ChannelCheer = SubscriptionType{Name: "channel.cheer", Version: "1"}
ChannelRaid = SubscriptionType{Name: "channel.raid", Version: "1"}
ChannelBan = SubscriptionType{Name: "channel.ban", Version: "1"}
ChannelUnban = SubscriptionType{Name: "channel.unban", Version: "1"}
ChannelModeratorAdd = SubscriptionType{Name: "channel.moderator.add", Version: "1"}
ChannelModeratorRemove = SubscriptionType{Name: "channel.moderator.remove", Version: "1"}
ChannelGuestStarSessionBegin = SubscriptionType{Name: "channel.guest_star_session.begin", Version: "beta"}
ChannelGuestStarSessionEnd = SubscriptionType{Name: "channel.guest_star_session.end", Version: "beta"}
ChannelGuestStarGuestUpdate = SubscriptionType{Name: "channel.guest_star_guest.update", Version: "beta"}
ChannelGuestStarSettingsUpdate = SubscriptionType{Name: "channel.guest_star_settings.update", Version: "beta"}
ChannelPointsCustomRewardAdd = SubscriptionType{Name: "channel.channel_points_custom_reward.add", Version: "1"}
ChannelPointsCustomRewardUpdate = SubscriptionType{Name: "channel.channel_points_custom_reward.update", Version: "1"}
ChannelPointsCustomRewardRemove = SubscriptionType{Name: "channel.channel_points_custom_reward.remove", Version: "1"}
ChannelPointsCustomRewardRedemptionAdd = SubscriptionType{Name: "channel.channel_points_custom_reward_redemption.add", Version: "1"}
ChannelPointsCustomRewardRedemptionUpdate = SubscriptionType{Name: "channel.channel_points_custom_reward_redemption.update", Version: "1"}
ChannelPollBegin = SubscriptionType{Name: "channel.poll.begin", Version: "1"}
ChannelPollProgress = SubscriptionType{Name: "channel.poll.progress", Version: "1"}
ChannelPollEnd = SubscriptionType{Name: "channel.poll.end", Version: "1"}
ChannelPredictionBegin = SubscriptionType{Name: "channel.prediction.begin", Version: "1"}
ChannelPredictionProgress = SubscriptionType{Name: "channel.prediction.progress", Version: "1"}
ChannelPredictionLock = SubscriptionType{Name: "channel.prediction.lock", Version: "1"}
ChannelPredictionEnd = SubscriptionType{Name: "channel.prediction.end", Version: "1"}
CharityCampaignDonate = SubscriptionType{Name: "channel.charity_campaign.donate", Version: "1"}
CharityCampaignStart = SubscriptionType{Name: "channel.charity_campaign.start", Version: "1"}
CharityCampaignProgress = SubscriptionType{Name: "channel.charity_campaign.progress", Version: "1"}
CharityCampaignStop = SubscriptionType{Name: "channel.charity_campaign.stop", Version: "1"}
ConduitShardDisabled = SubscriptionType{Name: "conduit.shard.disabled", Version: "1"}
DropEntitlementGrant = SubscriptionType{Name: "drop.entitlement.grant", Version: "1"}
ExtensionBitsTransactionCreate = SubscriptionType{Name: "extension.bits.transaction.create", Version: "1"}
GoalBegin = SubscriptionType{Name: "goal.begin", Version: "1"}
GoalProgress = SubscriptionType{Name: "goal.progress", Version: "1"}
GoalEnd = SubscriptionType{Name: "goal.end", Version: "1"}
HypeTrainBegin = SubscriptionType{Name: "hype_train.begin", Version: "1"}
HypeTrainProgress = SubscriptionType{Name: "hype_train.progress", Version: "1"}
HypeTrainEnd = SubscriptionType{Name: "hype_train.end", Version: "1"}
ShieldModeBegin = SubscriptionType{Name: "shield_mode.begin", Version: "1"}
ShieldModeEnd = SubscriptionType{Name: "shield_mode.end", Version: "1"}
ShoutoutCreate = SubscriptionType{Name: "shoutout.create", Version: "1"}
ShoutoutReceived = SubscriptionType{Name: "shoutout.received", Version: "1"}
StreamOnline = SubscriptionType{Name: "stream.online", Version: "1"}
StreamOffline = SubscriptionType{Name: "stream.offline", Version: "1"}
UserAuthorizationGrant = SubscriptionType{Name: "user.authorization.grant", Version: "1"}
UserAuthorizationRevoke = SubscriptionType{Name: "user.authorization.revoke", Version: "1"}
UserUpdate = SubscriptionType{Name: "user.update", Version: "1"}
)