Documentation
¶
Index ¶
- func GetChannelID(token, clientID string) (string, error)
- func GetOAuthToken(clientID string) string
- func ListenChannelPoints(chanID, clientID, oauthToken string, callback func(RedemptionEvent))
- type Connection
- type Message
- type Metadata
- type Payload
- type PayloadSession
- type PayloadSubscription
- type RedemptionEvent
- type Transport
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetChannelID ¶
GetChannelID retrieves the channel ID for the OAuth token provided, and returns it as a string
func GetOAuthToken ¶
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) 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 ¶
Message received from the EventSub API, composed of Metadata and a Payload.
See the Twitch EventSub API reference for details.
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 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.