twitch

package module
v2.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 29, 2023 License: MIT Imports: 10 Imported by: 0

README

Twitch Eventsub

Go Report Card Software License GoDoc tests

Implements a Twitch EventSub Websocket connection

If a websocket connection has no subscriptions, then it will close automatically on twitch's end so call client.OnWelcome and subscribe there after getting the subscription ID.

Major Version Changes

v2 changes OnRawEvent from passing EventSubscription to PayloadSubscription. This allows extra information to be passed in the event instead of just the type.

Authorization

For authorization, a user access token must be used. An app access token will cause an error. See the Authorization section in the Twitch Docs

When subscribing to events using WebSockets, you must use a user access token only. The request fails if you use an app access token.

...

When subscribing to events using webhooks, you must use an app access token. The request fails if you use a user access token.

If the error below occurs, it's likely an app access token is being used instead of a user app token.

ERROR: could not subscribe to event: 400 Bad Request: {"error":"Bad Request","status":400,"message":"invalid transport and auth combination"}

Example

package main

import (
	"fmt"

	"github.com/joeyak/go-twitch-eventsub/v2"
)

var (
	userID = "<USERID>"
	accessToken = "<ACCESSTOKEN>"
	clientID = "<CLIENTID>"
)

func main() {
	client := twitch.NewClient()

	client.OnError(func(err error) {
		fmt.Printf("ERROR: %v\n", err)
	})
	client.OnWelcome(func(message twitch.WelcomeMessage) {
		fmt.Printf("WELCOME: %v\n", message)

		events := []twitch.EventSubscription{
			twitch.SubStreamOnline,
			twitch.SubStreamOffline,
		}

		for _, event := range events {
			fmt.Printf("subscribing to %s\n", event)
			_, err := twitch.SubscribeEvent(twitch.SubscribeRequest{
				SessionID:   message.Payload.Session.ID,
				ClientID:    clientID,
				AccessToken: accessToken,
				Event:       event,
				Condition: map[string]string{
					"broadcaster_user_id": userID,
				},
			})
			if err != nil {
				fmt.Printf("ERROR: %v\n", err)
				return
			}
		}
	})
	client.OnNotification(func(message twitch.NotificationMessage) {
		fmt.Printf("NOTIFICATION: %s: %#v\n", message.Payload.Subscription.Type, message.Payload.Event)
	})
	client.OnKeepAlive(func(message twitch.KeepAliveMessage) {
		fmt.Printf("KEEPALIVE: %v\n", message)
	})
	client.OnRevoke(func(message twitch.RevokeMessage) {
		fmt.Printf("REVOKE: %v\n", message)
	})
	client.OnRawEvent(func(event string, metadata twitch.MessageMetadata, subscription twitch.PayloadSubscription) {
		fmt.Printf("EVENT[%s]: %s: %s\n", subscription.Type, metadata, event)
	})

	err := client.Connect()
	if err != nil {
		fmt.Printf("Could not connect client: %v\n", err)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrConnClosed   = fmt.Errorf("connection closed")
	ErrNilOnWelcome = fmt.Errorf("OnWelcome function was not set")
)

Functions

This section is empty.

Types

type BaseCharity

type BaseCharity struct {
	Broadcaster
	User

	CharityName        string `json:"charity_name"`
	CharityDescription string `json:"charity_description"`
	CharityWebsite     string `json:"charity_website"`
}

type Broadcaster

type Broadcaster struct {
	BroadcasterUserId    string `json:"broadcaster_user_id"`
	BroadcasterUserLogin string `json:"broadcaster_user_login"`
	BroadcasterUserName  string `json:"broadcaster_user_name"`
}

type ChannelPointReward

type ChannelPointReward struct {
	ID     string `json:"id"`
	Title  string `json:"title"`
	Cost   int    `json:"cost"`
	Prompt string `json:"prompt"`
}

type Client

type Client struct {
	Address string
	// contains filtered or unexported fields
}

func NewClient

func NewClient() *Client

func NewClientWithUrl

func NewClientWithUrl(url string) *Client

func (*Client) Close

func (c *Client) Close() error

func (*Client) Connect

func (c *Client) Connect() error

func (*Client) ConnectWithContext

func (c *Client) ConnectWithContext(ctx context.Context) error

func (*Client) OnError

func (c *Client) OnError(callback func(err error))

func (*Client) OnEventChannelBan

func (c *Client) OnEventChannelBan(callback func(event EventChannelBan))

func (*Client) OnEventChannelChannelPointsCustomRewardAdd

func (c *Client) OnEventChannelChannelPointsCustomRewardAdd(callback func(event EventChannelChannelPointsCustomRewardAdd))

func (*Client) OnEventChannelChannelPointsCustomRewardRedemptionAdd

func (c *Client) OnEventChannelChannelPointsCustomRewardRedemptionAdd(callback func(event EventChannelChannelPointsCustomRewardRedemptionAdd))

func (*Client) OnEventChannelChannelPointsCustomRewardRedemptionUpdate

func (c *Client) OnEventChannelChannelPointsCustomRewardRedemptionUpdate(callback func(event EventChannelChannelPointsCustomRewardRedemptionUpdate))

func (*Client) OnEventChannelChannelPointsCustomRewardRemove

func (c *Client) OnEventChannelChannelPointsCustomRewardRemove(callback func(event EventChannelChannelPointsCustomRewardRemove))

func (*Client) OnEventChannelChannelPointsCustomRewardUpdate

func (c *Client) OnEventChannelChannelPointsCustomRewardUpdate(callback func(event EventChannelChannelPointsCustomRewardUpdate))

func (*Client) OnEventChannelCharityCampaignDonate

func (c *Client) OnEventChannelCharityCampaignDonate(callback func(event EventChannelCharityCampaignDonate))

func (*Client) OnEventChannelCharityCampaignProgress

func (c *Client) OnEventChannelCharityCampaignProgress(callback func(event EventChannelCharityCampaignProgress))

func (*Client) OnEventChannelCharityCampaignStart

func (c *Client) OnEventChannelCharityCampaignStart(callback func(event EventChannelCharityCampaignStart))

func (*Client) OnEventChannelCharityCampaignStop

func (c *Client) OnEventChannelCharityCampaignStop(callback func(event EventChannelCharityCampaignStop))

func (*Client) OnEventChannelCheer

func (c *Client) OnEventChannelCheer(callback func(event EventChannelCheer))

func (*Client) OnEventChannelFollow

func (c *Client) OnEventChannelFollow(callback func(event EventChannelFollow))

func (*Client) OnEventChannelGoalBegin

func (c *Client) OnEventChannelGoalBegin(callback func(event EventChannelGoalBegin))

func (*Client) OnEventChannelGoalEnd

func (c *Client) OnEventChannelGoalEnd(callback func(event EventChannelGoalEnd))

func (*Client) OnEventChannelGoalProgress

func (c *Client) OnEventChannelGoalProgress(callback func(event EventChannelGoalProgress))

func (*Client) OnEventChannelHypeTrainBegin

func (c *Client) OnEventChannelHypeTrainBegin(callback func(event EventChannelHypeTrainBegin))

func (*Client) OnEventChannelHypeTrainEnd

func (c *Client) OnEventChannelHypeTrainEnd(callback func(event EventChannelHypeTrainEnd))

func (*Client) OnEventChannelHypeTrainProgress

func (c *Client) OnEventChannelHypeTrainProgress(callback func(event EventChannelHypeTrainProgress))

func (*Client) OnEventChannelModeratorAdd

func (c *Client) OnEventChannelModeratorAdd(callback func(event EventChannelModeratorAdd))

func (*Client) OnEventChannelModeratorRemove

func (c *Client) OnEventChannelModeratorRemove(callback func(event EventChannelModeratorRemove))

func (*Client) OnEventChannelPollBegin

func (c *Client) OnEventChannelPollBegin(callback func(event EventChannelPollBegin))

func (*Client) OnEventChannelPollEnd

func (c *Client) OnEventChannelPollEnd(callback func(event EventChannelPollEnd))

func (*Client) OnEventChannelPollProgress

func (c *Client) OnEventChannelPollProgress(callback func(event EventChannelPollProgress))

func (*Client) OnEventChannelPredictionBegin

func (c *Client) OnEventChannelPredictionBegin(callback func(event EventChannelPredictionBegin))

func (*Client) OnEventChannelPredictionEnd

func (c *Client) OnEventChannelPredictionEnd(callback func(event EventChannelPredictionEnd))

func (*Client) OnEventChannelPredictionLock

func (c *Client) OnEventChannelPredictionLock(callback func(event EventChannelPredictionLock))

func (*Client) OnEventChannelPredictionProgress

func (c *Client) OnEventChannelPredictionProgress(callback func(event EventChannelPredictionProgress))

func (*Client) OnEventChannelRaid

func (c *Client) OnEventChannelRaid(callback func(event EventChannelRaid))

func (*Client) OnEventChannelShieldModeBegin

func (c *Client) OnEventChannelShieldModeBegin(callback func(event EventChannelShieldModeBegin))

func (*Client) OnEventChannelShieldModeEnd

func (c *Client) OnEventChannelShieldModeEnd(callback func(event EventChannelShieldModeEnd))

func (*Client) OnEventChannelSubscribe

func (c *Client) OnEventChannelSubscribe(callback func(event EventChannelSubscribe))

func (*Client) OnEventChannelSubscriptionEnd

func (c *Client) OnEventChannelSubscriptionEnd(callback func(event EventChannelSubscriptionEnd))

func (*Client) OnEventChannelSubscriptionGift

func (c *Client) OnEventChannelSubscriptionGift(callback func(event EventChannelSubscriptionGift))

func (*Client) OnEventChannelSubscriptionMessage

func (c *Client) OnEventChannelSubscriptionMessage(callback func(event EventChannelSubscriptionMessage))

func (*Client) OnEventChannelUnban

func (c *Client) OnEventChannelUnban(callback func(event EventChannelUnban))

func (*Client) OnEventChannelUpdate

func (c *Client) OnEventChannelUpdate(callback func(event EventChannelUpdate))

func (*Client) OnEventDropEntitlementGrant

func (c *Client) OnEventDropEntitlementGrant(callback func(event []EventDropEntitlementGrant))

func (*Client) OnEventExtensionBitsTransactionCreate

func (c *Client) OnEventExtensionBitsTransactionCreate(callback func(event EventExtensionBitsTransactionCreate))

func (*Client) OnEventStreamOffline

func (c *Client) OnEventStreamOffline(callback func(event EventStreamOffline))

func (*Client) OnEventStreamOnline

func (c *Client) OnEventStreamOnline(callback func(event EventStreamOnline))

func (*Client) OnEventUserAuthorizationGrant

func (c *Client) OnEventUserAuthorizationGrant(callback func(event EventUserAuthorizationGrant))

func (*Client) OnEventUserAuthorizationRevoke

func (c *Client) OnEventUserAuthorizationRevoke(callback func(event EventUserAuthorizationRevoke))

func (*Client) OnEventUserUpdate

func (c *Client) OnEventUserUpdate(callback func(event EventUserUpdate))

func (*Client) OnKeepAlive

func (c *Client) OnKeepAlive(callback func(message KeepAliveMessage))

func (*Client) OnNotification

func (c *Client) OnNotification(callback func(message NotificationMessage))

func (*Client) OnRawEvent

func (c *Client) OnRawEvent(callback func(event string, metadata MessageMetadata, subscription PayloadSubscription))

func (*Client) OnReconnect

func (c *Client) OnReconnect(callback func(message ReconnectMessage))

func (*Client) OnRevoke

func (c *Client) OnRevoke(callback func(message RevokeMessage))

func (*Client) OnWelcome

func (c *Client) OnWelcome(callback func(message WelcomeMessage))

type DropEntitlement

type DropEntitlement struct {
	User

	OrganizationId string    `json:"organization_id"`
	CategoryId     string    `json:"category_id"`
	CategoryName   string    `json:"category_name"`
	CampaignId     string    `json:"campaign_id"`
	EntitlementId  string    `json:"entitlement_id"`
	BenefitId      string    `json:"benefit_id"`
	CreatedAt      time.Time `json:"created_at"`
}

type Emote

type Emote struct {
	ID    string `json:"id"`
	Begin int    `json:"begin"`
	End   int    `json:"end"`
}

type EventChannelBan

type EventChannelBan struct {
	User
	Broadcaster
	Moderator

	Reason      string `json:"reason"`
	BannedAt    string `json:"banned_at"`
	EndsAt      string `json:"ends_at"`
	IsPermanent bool   `json:"is_permanent"`
}

type EventChannelChannelPointsCustomRewardAdd

type EventChannelChannelPointsCustomRewardAdd struct {
	Broadcaster

	ID                                string                    `json:"id"`
	IsEnabled                         bool                      `json:"is_enabled"`
	IsPaused                          bool                      `json:"is_paused"`
	IsInStock                         bool                      `json:"is_in_stock"`
	Title                             string                    `json:"title"`
	Cost                              int                       `json:"cost"`
	Prompt                            string                    `json:"prompt"`
	IsUserInputRequired               bool                      `json:"is_user_input_required"`
	ShouldRedemptionsSkipRequestQueue bool                      `json:"should_redemptions_skip_request_queue"`
	MaxPerStream                      MaxChannelPointsPerStream `json:"max_per_stream"`
	MaxPerUserPerStream               MaxChannelPointsPerStream `json:"max_per_user_per_stream"`
	BackgroundColor                   string                    `json:"background_color"`
	Image                             Image                     `json:"image"`
	DefaultImage                      Image                     `json:"default_image"`
	GlobalCooldown                    GlobalCooldown            `json:"global_cooldown"`
	CooldownExpiresAt                 time.Time                 `json:"cooldown_expires_at"`
	RedemptionsRedeemedCurrentStream  int                       `json:"redemptions_redeemed_current_stream"`
}

type EventChannelChannelPointsCustomRewardRedemptionAdd

type EventChannelChannelPointsCustomRewardRedemptionAdd struct {
	Broadcaster
	User

	ID         string             `json:"id"`
	UserInput  string             `json:"user_input"`
	Status     string             `json:"status"`
	Reward     ChannelPointReward `json:"reward"`
	RedeemedAt time.Time          `json:"redeemed_at"`
}

type EventChannelChannelPointsCustomRewardRemove

type EventChannelChannelPointsCustomRewardRemove EventChannelChannelPointsCustomRewardAdd

type EventChannelChannelPointsCustomRewardUpdate

type EventChannelChannelPointsCustomRewardUpdate EventChannelChannelPointsCustomRewardAdd

type EventChannelCharityCampaignDonate

type EventChannelCharityCampaignDonate struct {
	BaseCharity

	Amount GoalAmount `json:"amount"`
}

type EventChannelCharityCampaignProgress

type EventChannelCharityCampaignProgress struct {
	BaseCharity

	CurrentAmount GoalAmount `json:"current_amount"`
	TargetAmount  GoalAmount `json:"target_amount"`
}

type EventChannelCharityCampaignStart

type EventChannelCharityCampaignStart struct {
	EventChannelCharityCampaignProgress

	StartedAt time.Time `json:"started_at"`
}

type EventChannelCharityCampaignStop

type EventChannelCharityCampaignStop struct {
	EventChannelCharityCampaignProgress

	StoppedAt time.Time `json:"stopped_at"`
}

type EventChannelCheer

type EventChannelCheer struct {
	User
	Broadcaster

	Message     string `json:"message"`
	Bits        int    `json:"bits"`
	IsAnonymous bool   `json:"is_anonymous"`
}

type EventChannelFollow

type EventChannelFollow struct {
	User
	Broadcaster

	FollowedAt time.Time `json:"followed_at"`
}

type EventChannelGoalBegin

type EventChannelGoalBegin struct {
	Broadcaster

	ID                 string    `json:"id"`
	CharityName        string    `json:"charity_name"`
	CharityDescription string    `json:"charity_description"`
	CharityWebsite     string    `json:"charity_website"`
	CurrentAmount      int       `json:"current_amount"`
	TargetAmount       int       `json:"target_amount"`
	StoppedAt          time.Time `json:"stopped_at"`
}

type EventChannelGoalEnd

type EventChannelGoalEnd EventChannelGoalBegin

type EventChannelGoalProgress

type EventChannelGoalProgress EventChannelGoalBegin

type EventChannelHypeTrainBegin

type EventChannelHypeTrainBegin struct {
	Broadcaster

	Id               string                  `json:"id"`
	Total            int                     `json:"total"`
	Progress         int                     `json:"progress"`
	Goal             int                     `json:"goal"`
	TopContributions []HypeTrainContribution `json:"top_contributions"`
	LastContribution HypeTrainContribution   `json:"last_contribution"`
	Level            int                     `json:"level"`
	StartedAt        time.Time               `json:"started_at"`
	ExpiresAt        time.Time               `json:"expires_at"`
}

type EventChannelHypeTrainEnd

type EventChannelHypeTrainEnd struct {
	Broadcaster

	Id               string                  `json:"id"`
	Level            int                     `json:"level"`
	Total            int                     `json:"total"`
	TopContributions []HypeTrainContribution `json:"top_contributions"`
	StartedAt        time.Time               `json:"started_at"`
	ExpiresAt        time.Time               `json:"expires_at"`
	CooldownEndsAt   time.Time               `json:"cooldown_ends_at"`
}

type EventChannelHypeTrainProgress

type EventChannelHypeTrainProgress struct {
	EventChannelHypeTrainBegin

	Level int `json:"level"`
}

type EventChannelModeratorAdd

type EventChannelModeratorAdd struct {
	Broadcaster
	User
}

type EventChannelModeratorRemove

type EventChannelModeratorRemove struct {
	Broadcaster
	User
}

type EventChannelPollBegin

type EventChannelPollBegin struct {
	Broadcaster

	ID                  string       `json:"id"`
	Title               string       `json:"title"`
	Choices             []PollChoice `json:"choices"`
	BitsVoting          PollVoting   `json:"bits_voting"`
	ChannelPointsVoting PollVoting   `json:"channel_points_voting"`
	StartedAt           time.Time    `json:"started_at"`
	EndsAt              time.Time    `json:"ends_at"`
}

type EventChannelPollEnd

type EventChannelPollEnd struct {
	EventChannelPollBegin

	Status string `json:"status"`
}

type EventChannelPollProgress

type EventChannelPollProgress EventChannelPollBegin

type EventChannelPredictionBegin

type EventChannelPredictionBegin struct {
	Broadcaster

	ID        string              `json:"id"`
	Title     string              `json:"title"`
	Outcomes  []PredictionOutcome `json:"outcomes"`
	StartedAt time.Time           `json:"started_at"`
	LocksAt   time.Time           `json:"locks_at"`
}

type EventChannelPredictionEnd

type EventChannelPredictionEnd struct {
	Broadcaster

	ID               string              `json:"id"`
	Title            string              `json:"title"`
	WinningOutcomeID string              `json:"winning_outcome_id"`
	Outcomes         []PredictionOutcome `json:"outcomes"`
	Status           string              `json:"status"`
	StartedAt        time.Time           `json:"started_at"`
	EndedAt          time.Time           `json:"ended_at"`
}

type EventChannelPredictionLock

type EventChannelPredictionLock EventChannelPredictionBegin

type EventChannelPredictionProgress

type EventChannelPredictionProgress EventChannelPredictionBegin

type EventChannelRaid

type EventChannelRaid struct {
	FromBroadcasterUserId    string `json:"from_broadcaster_user_id"`
	FromBroadcasterUserLogin string `json:"from_broadcaster_user_login"`
	FromBroadcasterUserName  string `json:"from_broadcaster_user_name"`
	ToBroadcasterUserId      string `json:"to_broadcaster_user_id"`
	ToBroadcasterUserLogin   string `json:"to_broadcaster_user_login"`
	ToBroadcasterUserName    string `json:"to_broadcaster_user_name"`
	Viewers                  int    `json:"viewers"`
}

type EventChannelShieldModeBegin

type EventChannelShieldModeBegin struct {
	Broadcaster
	Moderator

	StartedAt time.Time `json:"started_at"`
	StoppedAt time.Time `json:"stopped_at"`
}

type EventChannelShieldModeEnd

type EventChannelShieldModeEnd EventChannelShieldModeBegin

type EventChannelSubscribe

type EventChannelSubscribe struct {
	User
	Broadcaster

	Tier   string `json:"tier"`
	IsGift bool   `json:"is_gift"`
}

type EventChannelSubscriptionEnd

type EventChannelSubscriptionEnd struct {
	User
	Broadcaster

	Tier   string `json:"tier"`
	IsGift bool   `json:"is_gift"`
}

type EventChannelSubscriptionGift

type EventChannelSubscriptionGift struct {
	User
	Broadcaster

	Total           int    `json:"total"`
	Tier            string `json:"tier"`
	CumulativeTotal int    `json:"cumulative_total"`
	IsAnonymous     bool   `json:"is_anonymous"`
}

type EventChannelSubscriptionMessage

type EventChannelSubscriptionMessage struct {
	User
	Broadcaster

	Tier             string  `json:"tier"`
	Message          Message `json:"message"`
	CumulativeMonths int     `json:"cumulative_months"`
	StreakMonths     int     `json:"streak_months"`
	DurationMonths   int     `json:"duration_months"`
}

type EventChannelUnban

type EventChannelUnban struct {
	User
	Broadcaster
	Moderator
}

type EventChannelUpdate

type EventChannelUpdate struct {
	Broadcaster

	Title                       string   `json:"title"`
	Language                    string   `json:"language"`
	CategoryID                  string   `json:"category_id"`
	CategoryName                string   `json:"category_name"`
	ContentClassificationLabels []string `json:"content_classification_labels"`
}

type EventDropEntitlementGrant

type EventDropEntitlementGrant struct {
	ID   string          `json:"id"`
	Data DropEntitlement `json:"data"`
}

type EventExtensionBitsTransactionCreate

type EventExtensionBitsTransactionCreate struct {
	Broadcaster
	User

	ID                string           `json:"id"`
	ExtensionClientID string           `json:"extension_client_id"`
	Product           ExtensionProduct `json:"product"`
}

type EventStreamOffline

type EventStreamOffline Broadcaster

type EventStreamOnline

type EventStreamOnline struct {
	Broadcaster

	Id        string    `json:"id"`
	Type      string    `json:"type"`
	StartedAt time.Time `json:"started_at"`
}

type EventSubscription

type EventSubscription string
var (
	SubChannelUpdate EventSubscription = "channel.update"
	SubChannelFollow EventSubscription = "channel.follow"

	SubChannelSubscribe           EventSubscription = "channel.subscribe"
	SubChannelSubscriptionEnd     EventSubscription = "channel.subscription.end"
	SubChannelSubscriptionGift    EventSubscription = "channel.subscription.gift"
	SubChannelSubscriptionMessage EventSubscription = "channel.subscription.message"

	SubChannelCheer EventSubscription = "channel.cheer"
	SubChannelRaid  EventSubscription = "channel.raid"
	SubChannelBan   EventSubscription = "channel.ban"
	SubChannelUnban EventSubscription = "channel.unban"

	SubChannelModeratorAdd    EventSubscription = "channel.moderator.add"
	SubChannelModeratorRemove EventSubscription = "channel.moderator.remove"

	SubChannelChannelPointsCustomRewardAdd              EventSubscription = "channel.channel_points_custom_reward.add"
	SubChannelChannelPointsCustomRewardUpdate           EventSubscription = "channel.channel_points_custom_reward.update"
	SubChannelChannelPointsCustomRewardRemove           EventSubscription = "channel.channel_points_custom_reward.remove"
	SubChannelChannelPointsCustomRewardRedemptionAdd    EventSubscription = "channel.channel_points_custom_reward_redemption.add"
	SubChannelChannelPointsCustomRewardRedemptionUpdate EventSubscription = "channel.channel_points_custom_reward_redemption.update"

	SubChannelPollBegin    EventSubscription = "channel.poll.begin"
	SubChannelPollProgress EventSubscription = "channel.poll.progress"
	SubChannelPollEnd      EventSubscription = "channel.poll.end"

	SubChannelPredictionBegin    EventSubscription = "channel.prediction.begin"
	SubChannelPredictionProgress EventSubscription = "channel.prediction.progress"
	SubChannelPredictionLock     EventSubscription = "channel.prediction.lock"
	SubChannelPredictionEnd      EventSubscription = "channel.prediction.end"

	SubDropEntitlementGrant           EventSubscription = "drop.entitlement.grant"
	SubExtensionBitsTransactionCreate EventSubscription = "extension.bits_transaction.create"

	SubChannelGoalBegin    EventSubscription = "channel.goal.begin"
	SubChannelGoalProgress EventSubscription = "channel.goal.progress"
	SubChannelGoalEnd      EventSubscription = "channel.goal.end"

	SubChannelHypeTrainBegin    EventSubscription = "channel.hype_train.begin"
	SubChannelHypeTrainProgress EventSubscription = "channel.hype_train.progress"
	SubChannelHypeTrainEnd      EventSubscription = "channel.hype_train.end"

	SubStreamOnline  EventSubscription = "stream.online"
	SubStreamOffline EventSubscription = "stream.offline"

	SubUserAuthorizationGrant  EventSubscription = "user.authorization.grant"
	SubUserAuthorizationRevoke EventSubscription = "user.authorization.revoke"
	SubUserUpdate              EventSubscription = "user.update"

	SubChannelCharityCampaignDonate   EventSubscription = "channel.charity_campaign.donate"
	SubChannelCharityCampaignStart    EventSubscription = "channel.charity_campaign.start"
	SubChannelCharityCampaignProgress EventSubscription = "channel.charity_campaign.progress"
	SubChannelCharityCampaignStop     EventSubscription = "channel.charity_campaign.stop"

	SubChannelShieldModeBegin EventSubscription = "channel.shield_mode.begin"
	SubChannelShieldModeEnd   EventSubscription = "channel.shield_mode.end"
)

type EventUserAuthorizationGrant

type EventUserAuthorizationGrant struct {
	User

	ClientID string `json:"client_id"`
}

type EventUserAuthorizationRevoke

type EventUserAuthorizationRevoke EventUserAuthorizationGrant

type EventUserUpdate

type EventUserUpdate struct {
	User

	Email         string `json:"email"`
	EmailVerified bool   `json:"email_verified"`
	Description   string `json:"description"`
}

type ExtensionProduct

type ExtensionProduct struct {
	Name          string `json:"name"`
	Bits          int    `json:"bits"`
	SKU           string `json:"sku"`
	InDevelopment bool   `json:"in_development"`
}

type GlobalCooldown

type GlobalCooldown struct {
	IsEnabled bool `json:"is_enabled"`
	Seconds   int  `json:"seconds"`
}

type GoalAmount

type GoalAmount struct {
	Value         int    `json:"value"`
	DecimalPlaces int    `json:"decimal_places"`
	Currency      string `json:"currency"`
}

func (GoalAmount) Amount

func (a GoalAmount) Amount() float64

type HypeTrainContribution

type HypeTrainContribution struct {
	User

	Type  string `json:"type"`
	Total int    `json:"total"`
}

type Image

type Image struct {
	Url1x string `json:"url_1x"`
	Url2x string `json:"url_2x"`
	Url4x string `json:"url_4x"`
}

type KeepAliveMessage

type KeepAliveMessage struct {
	Metadata MessageMetadata `json:"metadata"`
	Payload  struct{}        `json:"payload"`
}

type MaxChannelPointsPerStream

type MaxChannelPointsPerStream struct {
	IsEnabled bool `json:"is_enabled"`
	Value     int  `json:"value"`
}

type Message

type Message struct {
	Text   string  `json:"text"`
	Emotes []Emote `json:"emotes"`
}

type MessageMetadata

type MessageMetadata struct {
	MessageID        string    `json:"message_id"`
	MessageType      string    `json:"message_type"`
	MessageTimestamp time.Time `json:"message_timestamp"`
}

type Moderator

type Moderator struct {
	ModeratorUserId    string `json:"moderator_user_id"`
	ModeratorUserLogin string `json:"moderator_user_login"`
	ModeratorUserName  string `json:"moderator_user_name"`
}

type NotificationMessage

type NotificationMessage struct {
	Metadata MessageMetadata `json:"metadata"`
	Payload  struct {
		Subscription PayloadSubscription `json:"subscription"`
		Event        *json.RawMessage    `json:"event"`
	} `json:"payload"`
}

type PayloadSession

type PayloadSession struct {
	ID                      string    `json:"id"`
	Status                  string    `json:"status"`
	ConnectedAt             time.Time `json:"connected_at"`
	KeepaliveTimeoutSeconds int       `json:"keepalive_timeout_seconds"`
	ReconnectUrl            string    `json:"reconnect_url"`
}

type PayloadSubscription

type PayloadSubscription struct {
	SubscriptionRequest

	ID       string    `json:"id"`
	Status   string    `json:"status"`
	Cost     int       `json:"cost"`
	CreateAt time.Time `json:"created_at"`
}

type PollChoice

type PollChoice struct {
	ID                string `json:"id"`
	Title             string `json:"title"`
	BitsVotes         int    `json:"bits_votes"`
	ChannelPointVotes int    `json:"channel_points_votes"`
	Votes             int    `json:"votes"`
}

type PollVoting

type PollVoting struct {
	IsEnabled     bool `json:"is_enabled"`
	AmountPerVote int  `json:"amount_per_vote"`
}

type PredictionOutcome

type PredictionOutcome struct {
	ID            string         `json:"id"`
	Title         string         `json:"title"`
	Color         string         `json:"color"`
	Users         int            `json:"users"`
	ChannelPoints int            `json:"channel_points"`
	TopPredictors []TopPredictor `json:"top_predictors"`
}

type ReconnectMessage

type ReconnectMessage struct {
	Metadata MessageMetadata `json:"metadata"`
	Payload  struct {
		Session PayloadSession `json:"session"`
	} `json:"payload"`
}

type RevokeMessage

type RevokeMessage struct {
	Metadata MessageMetadata `json:"metadata"`
	Payload  struct {
		Subscription PayloadSubscription `json:"subscription"`
	} `json:"payload"`
}

type SubscribeRequest

type SubscribeRequest struct {
	SessionID       string
	ClientID        string
	AccessToken     string
	VersionOverride string

	Event     EventSubscription
	Condition map[string]string
}

type SubscribeResponse

type SubscribeResponse struct {
	Data         []PayloadSubscription `json:"data"`
	Total        int                   `json:"total"`
	TotalCost    int                   `json:"total_cost"`
	MaxTotalCost int                   `json:"max_total_cost"`
}

func SubscribeEvent

func SubscribeEvent(request SubscribeRequest) (SubscribeResponse, error)

func SubscribeEventUrl

func SubscribeEventUrl(request SubscribeRequest, url string) (SubscribeResponse, error)

func SubscribeEventUrlWithContext

func SubscribeEventUrlWithContext(ctx context.Context, request SubscribeRequest, url string) (SubscribeResponse, error)

func SubscribeEventWithContext

func SubscribeEventWithContext(ctx context.Context, request SubscribeRequest) (SubscribeResponse, error)

type SubscriptionRequest

type SubscriptionRequest struct {
	Type      EventSubscription     `json:"type"`
	Version   string                `json:"version"`
	Condition map[string]string     `json:"condition"`
	Transport SubscriptionTransport `json:"transport"`
}

type SubscriptionTransport

type SubscriptionTransport struct {
	Method    string `json:"method"`
	SessionID string `json:"session_id"`
}

type TopPredictor

type TopPredictor struct {
	User

	ChannelPointsWon  int `json:"channel_points_won"`
	ChannelPointsUsed int `json:"channel_points_used"`
}

type User

type User struct {
	UserID    string `json:"user_id"`
	UserLogin string `json:"user_login"`
	UserName  string `json:"user_name"`
}

type WelcomeMessage

type WelcomeMessage struct {
	Metadata MessageMetadata `json:"metadata"`
	Payload  struct {
		Session PayloadSession `json:"session"`
	} `json:"payload"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL