package eventsub import "time" type Condition map[string]any type Subscription struct { // An ID that identifies the subscription. ID string `json:"id"` // The subscription’s status. The subscriber receives events only for enabled subscriptions. Status Status `json:"status"` // The subscription’s 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 subscription’s data. Version string `json:"version"` // The subscription’s 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"` } func (s Subscription) SubType() SubscriptionType { return SubscriptionType{Name: s.Type, Version: s.Version} } type Status string const ( // enabled — The subscription is enabled. StatusEnabled Status = "enabled" // webhook_callback_verification_pending — The subscription is pending verification of the specified callback URL. StatusWebhookCallbackVerificationPending Status = "webhook_callback_verification_pending" // webhook_callback_verification_failed — The specified callback URL failed verification. StatusWebhookCallbackVerificationFailed Status = "webhook_callback_verification_failed" // notification_failures_exceeded — The notification delivery failure rate was too high. StatusNotificationFailuresExceeded Status = "notification_failures_exceeded" // authorization_revoked — The authorization was revoked for one or more users specified in the Condition object. StatusAuthorizationRevoked Status = "authorization_revoked" // moderator_removed — The moderator that authorized the subscription is no longer one of the broadcaster's moderators. StatusModeratorRemoved Status = "moderator_removed" // user_removed — One of the users specified in the Condition object was removed. StatusUserRemoved Status = "user_removed" // chat_user_banned - The user specified in the Condition object was banned from the broadcaster's chat. StatusChatUserBanned Status = "chat_user_banned" // version_removed — The subscription to subscription type and version is no longer supported. StatusVersionRemoved Status = "version_removed" // beta_maintenance — The subscription to the beta subscription type was removed due to maintenance. StatusBetaMaintenance Status = "beta_maintenance" // websocket_disconnected — The client closed the connection. StatusWebsocketDisconnected Status = "websocket_disconnected" // websocket_failed_ping_pong — The client failed to respond to a ping message. StatusWebsocketFailedPingPong Status = "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). StatusWebsocketReceivedInboundTraffic Status = "websocket_received_inbound_traffic" // websocket_connection_unused — The client failed to subscribe to events within the required time. StatusWebsocketConnectionUnused Status = "websocket_connection_unused" // websocket_internal_error — The Twitch WebSocket server experienced an unexpected error. StatusWebsocketInternalError Status = "websocket_internal_error" // websocket_network_timeout — The Twitch WebSocket server timed out writing the message to the client. StatusWebsocketNetworkTimeout Status = "websocket_network_timeout" // websocket_network_error — The Twitch WebSocket server experienced a network error writing the message to the client. StatusWebsocketnetworkError Status = "websocket_network_error" // websocket_failed_to_reconnect - The client failed to reconnect to the Twitch WebSocket server within the required time after a Reconnect Message. StatusWebsocketFailedToReconnect Status = "websocket_failed_to_reconnect" ) 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 that’s 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 ( // A user is notified if a message is caught by automod for review. AutomodMessageHold = SubscriptionType{Name: "automod.message.hold", Version: "1"} // A message in the automod queue had its status changed. AutomodMessageUpdate = SubscriptionType{Name: "automod.message.update", Version: "1"} // A notification is sent when a broadcaster’s automod settings are updated. AutomodSettingsUpdate = SubscriptionType{Name: "automod.settings.update", Version: "1"} // A notification is sent when a broadcaster’s automod terms are updated. Changes to private terms are not sent. AutomodTermsUpdate = SubscriptionType{Name: "automod.terms.update", Version: "1"} // A broadcaster updates their channel properties e.g., category, title, content classification labels, broadcast, or language. ChannelUpdate = SubscriptionType{Name: "channel.update", Version: "2"} // A specified channel receives a follow. ChannelFollow = SubscriptionType{Name: "channel.follow", Version: "2"} // A midroll commercial break has started running. ChannelAdBreakBegin = SubscriptionType{Name: "channel.ad_break_begin", Version: "1"} // A moderator or bot has cleared all messages from the chat room. ChannelChatClear = SubscriptionType{Name: "channel.chat.clear", Version: "1"} // A moderator or bot has cleared all messages from a specific user. ChannelChatClearUserMessages = SubscriptionType{Name: "channel.chat.clear_user_messages", Version: "1"} // Any user sends a message to a specific chat room. ChannelChatMessage = SubscriptionType{Name: "channel.chat.message", Version: "1"} // A moderator has removed a specific message. ChannelChatMessageDelete = SubscriptionType{Name: "channel.chat.message_delete", Version: "1"} // A notification for when an event that appears in chat has occurred. ChannelChatNotification = SubscriptionType{Name: "channel.chat.notification", Version: "1"} // A notification for when a broadcaster’s chat settings are updated. ChannelChatSettingsUpdate = SubscriptionType{Name: "channel.chat_settings.update", Version: "1"} // A user is notified if their message is caught by automod. ChannelChatUserMessageHold = SubscriptionType{Name: "channel.chat.user_message_hold", Version: "1"} // A user is notified if their message’s automod status is updated. ChannelChatUserMessageUpdate = SubscriptionType{Name: "channel.chat.user_message_update", Version: "1"} // A notification when a specified channel receives a subscriber. This does not include resubscribes. ChannelSubscribe = SubscriptionType{Name: "channel.subscribe", Version: "1"} // A notification when a subscription to the specified channel ends. ChannelSubscriptionEnd = SubscriptionType{Name: "channel.subscription.end", Version: "1"} // A notification when a viewer gives a gift subscription to one or more users in the specified channel. ChannelSubscriptionGift = SubscriptionType{Name: "channel.subscription.gift", Version: "1"} // A notification when a user sends a resubscription chat message in a specific channel. ChannelSubscriptionMessage = SubscriptionType{Name: "channel.subscription.message", Version: "1"} // A user cheers on the specified channel. ChannelCheer = SubscriptionType{Name: "channel.cheer", Version: "1"} // A broadcaster raids another broadcaster’s channel. ChannelRaid = SubscriptionType{Name: "channel.raid", Version: "1"} // A viewer is banned from the specified channel. ChannelBan = SubscriptionType{Name: "channel.ban", Version: "1"} // A viewer is unbanned from the specified channel. ChannelUnban = SubscriptionType{Name: "channel.unban", Version: "1"} // A user creates an unban request. ChannelUnbanRequestCreate = SubscriptionType{Name: "channel.unban_request.create", Version: "1"} // An unban request has been resolved. ChannelUnbanRequestResolve = SubscriptionType{Name: "channel.unban_request.resolve", Version: "1"} // A moderator performs a moderation action in a channel. ChannelModerate = SubscriptionType{Name: "channel.moderate", Version: "1"} // Moderator privileges were added to a user on a specified channel. ChannelModeratorAdd = SubscriptionType{Name: "channel.moderator.add", Version: "1"} // Moderator privileges were removed from a user on a specified channel. ChannelModeratorRemove = SubscriptionType{Name: "channel.moderator.remove", Version: "1"} // The host began a new Guest Star session. ChannelGuestStarSessionBegin = SubscriptionType{Name: "channel.guest_star_session.begin", Version: "beta"} // A running Guest Star session has ended. ChannelGuestStarSessionEnd = SubscriptionType{Name: "channel.guest_star_session.end", Version: "beta"} // A guest or a slot is updated in an active Guest Star session. ChannelGuestStarGuestUpdate = SubscriptionType{Name: "channel.guest_star_guest.update", Version: "beta"} // The host preferences for Guest Star have been updated. ChannelGuestStarSettingsUpdate = SubscriptionType{Name: "channel.guest_star_settings.update", Version: "beta"} // A viewer has redeemed an automatic channel points reward on the specified channel. ChannelPointsAutomaticRewardAdd = SubscriptionType{Name: "channel.channel_points_automatic_reward.add", Version: "1"} // A custom channel points reward has been created for the specified channel. ChannelPointsCustomRewardAdd = SubscriptionType{Name: "channel.channel_points_custom_reward.add", Version: "1"} // A custom channel points reward has been updated for the specified channel. ChannelPointsCustomRewardUpdate = SubscriptionType{Name: "channel.channel_points_custom_reward.update", Version: "1"} // A custom channel points reward has been removed from the specified channel. ChannelPointsCustomRewardRemove = SubscriptionType{Name: "channel.channel_points_custom_reward.remove", Version: "1"} // A viewer has redeemed a custom channel points reward on the specified channel. ChannelPointsCustomRewardRedemptionAdd = SubscriptionType{Name: "channel.channel_points_custom_reward_redemption.add", Version: "1"} // A redemption of a channel points custom reward has been updated for the specified channel. ChannelPointsCustomRewardRedemptionUpdate = SubscriptionType{Name: "channel.channel_points_custom_reward_redemption.update", Version: "1"} // A poll started on a specified channel. ChannelPollBegin = SubscriptionType{Name: "channel.poll.begin", Version: "1"} // Users respond to a poll on a specified channel. ChannelPollProgress = SubscriptionType{Name: "channel.poll.progress", Version: "1"} // A poll ended on a specified channel. ChannelPollEnd = SubscriptionType{Name: "channel.poll.end", Version: "1"} // A Prediction started on a specified channel. ChannelPredictionBegin = SubscriptionType{Name: "channel.prediction.begin", Version: "1"} // Users participated in a Prediction on a specified channel. ChannelPredictionProgress = SubscriptionType{Name: "channel.prediction.progress", Version: "1"} // A Prediction was locked on a specified channel. ChannelPredictionLock = SubscriptionType{Name: "channel.prediction.lock", Version: "1"} // A Prediction ended on a specified channel. ChannelPredictionEnd = SubscriptionType{Name: "channel.prediction.end", Version: "1"} // A chat message has been sent by a suspicious user. ChannelSuspiciousUserMessage = SubscriptionType{Name: "channel.suspicious_user.message", Version: "1"} // A suspicious user has been updated. ChannelSuspiciousUserUpdate = SubscriptionType{Name: "channel.suspicious_user.update", Version: "1"} // A VIP is added to the channel. ChannelVipAdd = SubscriptionType{Name: "channel.vip.add", Version: "1"} // A VIP is removed from the channel. ChannelVipRemove = SubscriptionType{Name: "channel.vip.remove", Version: "1"} // Sends an event notification when a user donates to the broadcaster’s charity campaign. CharityCampaignDonate = SubscriptionType{Name: "channel.charity_campaign.donate", Version: "1"} // Sends an event notification when the broadcaster starts a charity campaign. CharityCampaignStart = SubscriptionType{Name: "channel.charity_campaign.start", Version: "1"} // Sends an event notification when progress is made towards the campaign’s goal or when the broadcaster changes the fundraising goal. CharityCampaignProgress = SubscriptionType{Name: "channel.charity_campaign.progress", Version: "1"} // Sends an event notification when the broadcaster stops a charity campaign. CharityCampaignStop = SubscriptionType{Name: "channel.charity_campaign.stop", Version: "1"} // Sends a notification when EventSub disables a shard due to the status of the underlying transport changing. ConduitShardDisabled = SubscriptionType{Name: "conduit.shard.disabled", Version: "1"} // An entitlement for a Drop is granted to a user. DropEntitlementGrant = SubscriptionType{Name: "drop.entitlement.grant", Version: "1"} // A Bits transaction occurred for a specified Twitch Extension. ExtensionBitsTransactionCreate = SubscriptionType{Name: "extension.bits.transaction.create", Version: "1"} // Get notified when a broadcaster begins a goal. GoalBegin = SubscriptionType{Name: "goal.begin", Version: "1"} // Get notified when progress (either positive or negative) is made towards a broadcaster’s goal. GoalProgress = SubscriptionType{Name: "goal.progress", Version: "1"} // Get notified when a broadcaster ends a goal. GoalEnd = SubscriptionType{Name: "goal.end", Version: "1"} // A Hype Train begins on the specified channel. HypeTrainBegin = SubscriptionType{Name: "hype_train.begin", Version: "1"} // A Hype Train makes progress on the specified channel. HypeTrainProgress = SubscriptionType{Name: "hype_train.progress", Version: "1"} // A Hype Train ends on the specified channel. HypeTrainEnd = SubscriptionType{Name: "hype_train.end", Version: "1"} // Sends a notification when the broadcaster activates Shield Mode. ShieldModeBegin = SubscriptionType{Name: "shield_mode.begin", Version: "1"} // Sends a notification when the broadcaster deactivates Shield Mode. ShieldModeEnd = SubscriptionType{Name: "shield_mode.end", Version: "1"} // Sends a notification when the specified broadcaster sends a Shoutout. ShoutoutCreate = SubscriptionType{Name: "shoutout.create", Version: "1"} // Sends a notification when the specified broadcaster receives a Shoutout. ShoutoutReceived = SubscriptionType{Name: "shoutout.received", Version: "1"} // The specified broadcaster starts a stream. StreamOnline = SubscriptionType{Name: "stream.online", Version: "1"} // The specified broadcaster stops a stream. StreamOffline = SubscriptionType{Name: "stream.offline", Version: "1"} // A user’s authorization has been granted to your client id. UserAuthorizationGrant = SubscriptionType{Name: "user.authorization.grant", Version: "1"} // A user’s authorization has been revoked for your client id. UserAuthorizationRevoke = SubscriptionType{Name: "user.authorization.revoke", Version: "1"} // A user has updated their account. UserUpdate = SubscriptionType{Name: "user.update", Version: "1"} // A user receives a whisper. UserWhisperMessage = SubscriptionType{Name: "user.whisper.message", Version: "1"} )