eventsub

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Choice

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

type Conn

type Conn struct {
	HandleMessage func(msg Message[NotificationPayload])
	HandleError   func(err error)
	// contains filtered or unexported fields
}

func NewConn

func NewConn(logger zerolog.Logger, httpClient *http.Client) *Conn

func (*Conn) Connect

func (c *Conn) Connect(inbound <-chan InboundMessage) error

Connect connects to the twitch eventsub websocket It will wait util a message is send to the inbound channel before connecting this is because twitch will close the connection if we don't send a event sub subscription within 10 seconds after connecting. Connect will try to reconnect if the connection is dropped until inboud is closed. If twitch sends reconnect messsage, Connect will reconnect to the session. Duplicate messages are filtered out.

type Event

type Event struct {
	UserID               string    `json:"user_id"`
	UserLogin            string    `json:"user_login"`
	UserName             string    `json:"user_name"`
	BroadcasterUserID    string    `json:"broadcaster_user_id"`
	BroadcasterUserLogin string    `json:"broadcaster_user_login"`
	BroadcasterUserName  string    `json:"broadcaster_user_name"`
	FollowedAt           time.Time `json:"followed_at"`

	// Poll releated
	Title               string    `json:"title"`
	Choices             []Choice  `json:"choices"`
	BitsVoting          Voting    `json:"bits_voting"`
	ChannelPointsVoting Voting    `json:"channel_points_voting"`
	StartedAt           time.Time `json:"started_at"`
	EndsAt              time.Time `json:"ends_at"`  // empty if done
	EndedAt             time.Time `json:"ended_at"` // empty until done
	Status              string    `json:"status"`   // completed when done, else empty

	// Raid related
	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"`

	// Ad related
	IsAutomatic       bool `json:"is_automatic"`
	DurationInSeconds int  `json:"duration_seconds"`

	RequesterUserID    string `json:"requester_user_id"`
	RequesterUserLogin string `json:"requester_user_login"`
	RequesterUserName  string `json:"requester_user_name"`
}

type EventSubService

type EventSubService interface {
	CreateEventSubSubscription(ctx context.Context, reqData twitch.CreateEventSubSubscriptionRequest) (twitch.CreateEventSubSubscriptionResponse, error)
}

type InboundMessage

type InboundMessage struct {
	Req     twitch.CreateEventSubSubscriptionRequest
	Service EventSubService
}

type Message

type Message[T any] struct {
	Metadata metadata `json:"metadata"`
	Payload  T        `json:"payload"`
}

type NotificationPayload

type NotificationPayload struct {
	Subscription Subscription `json:"subscription"`
	Event        Event        `json:"event"`
}

type Session

type Session struct {
	ID                      string    `json:"id"`
	Satus                   string    `json:"status"`
	ConnectedAt             time.Time `json:"connected_at"`
	KeepAliveTimeoutSeconds int       `json:"keepalive_timeout_seconds"`
	ReconnectURL            string    `json:"reconnect_url"`
}

type SessionPayload

type SessionPayload struct {
	Session Session `json:"session"`
}

type Subscription

type Subscription struct {
	ID        string            `json:"id"`
	Status    string            `json:"status"`
	Type      string            `json:"type"`
	Version   string            `json:"version"`
	Cost      int               `json:"cost"`
	Condition map[string]string `json:"condition"`
	Transport Transport         `json:"transport"`
	CreatedAt time.Time         `json:"created_at"`
}

type Transport

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

type Voting

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

Jump to

Keyboard shortcuts

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