twitch

package
v0.0.0-...-a2f784d Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2025 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetChannelID

func GetChannelID(token, clientID string) (string, error)

GetChannelID retrieves the channel ID for the OAuth token provided, and returns it as a string

func GetOAuthToken

func GetOAuthToken(clientID string) string

GetOAuthToken gets a User OAuth Token from the Twitch API and returns it as a string. This function needs further work: it is not fully automated, requiring user involvement (which also has an ugly UX)

func ListenChannelPoints

func ListenChannelPoints(chanID, clientID, oauthToken string, callback func(RedemptionEvent))

ListenChannelPoints starts a WebSocket listening to the Twitch EventSub API for Channel Point redemptions, which calls callback with the provided file handle and the reward title as a string

Types

type Connection

type Connection struct {
	// Whether the connection is actually connected to the API and therefore valid to use; this is false if the connection was intentionally Closed.
	Alive bool
	// ID of this connection for use with API calls
	Id string
	// contains filtered or unexported fields
}

An individual Connection to the Twitch EventSub API.

func New

func New(callback func(Message)) (*Connection, error)

New connection to the Twitch EventSub API, which will call the provided `callback` when a Notification event is received for any subscribed events.

func (*Connection) Close

func (c *Connection) Close() error

Close the EventSub connection

func (*Connection) ProcessMessage

func (c *Connection) ProcessMessage() error

Poll for a new message from the WebSocket and process it.

This will handle Reconnect events transparently for you, note any Revocations, and call the relevant callback for Notification events.

func (*Connection) Subscribe

func (c *Connection) Subscribe(clientId, oauthToken, event, version string, cond esApiCond) error

Subscribe to a given event

type Message

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

Message received from the EventSub API, composed of Metadata and a Payload.

See the Twitch EventSub API reference for details.

type Metadata

type Metadata struct {
	MessageId           string `json:"message_id"`
	MessageType         string `json:"message_type"`
	MessageTimestamp    string `json:"message_timestamp"`
	SubscriptionType    string `json:"subscription_type"`
	SubscriptionVersion string `json:"subscription_version"`
}

type Payload

type Payload struct {
	Session      PayloadSession      `json:"session"`
	Subscription PayloadSubscription `json:"subscription"`
	// Event has differing definition depending on which event's data it is providing; therefore, this must be deserialised separately using an appropriate struct.
	Event json.RawMessage `json:"event"`
}

type PayloadSession

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

type PayloadSubscription

type PayloadSubscription struct {
	Id      string `json:"id"`
	Status  string `json:"status"`
	Type    string `json:"type"`
	Version string `json:"version"`
	Cost    int    `json:"cost"`
	// Condition object, defined per Subscription type and therefore deserialised separately.
	Condition json.RawMessage `json:"condition"`
	Transport Transport       `json:"transport"`
	CreatedAt string          `json:"created_at"`
}

type RedemptionEvent

type RedemptionEvent struct {
	ID                   string    `json:"id"`
	BroadcasterUserId    string    `json:"broadcaster_user_id"`
	BroadcasterUserLogin string    `json:"broadcaster_user_login"`
	BroadcasterUserName  string    `json:"broadcaster_user_name"`
	UserId               string    `json:"user_id"`
	UserLogin            string    `json:"user_login"`
	UserName             string    `json:"user_name"`
	UserInput            string    `json:"user_input"`
	Status               string    `json:"status"`
	Reward               reward    `json:"reward"`
	RedeemedAt           time.Time `json:"redeemed_at"`
}

RedemptionEvent represents an event data object for a Channel Points Reward redemption.

This is provided as a convenience; consumers may need to define their own data structs for deserialising other event data objects if they subscribe to different events.

type Transport

type Transport struct {
	Method    string `json:"method"`
	SessionId string `json:"session_id"`
}

Jump to

Keyboard shortcuts

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