twitchapi

package
v0.0.0-develop Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2026 License: MIT Imports: 15 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoAuthProvided   = errors.New("one of app secret or user access token needs to be provided")
	ErrNoUserAccess     = errors.New("user endpoint called when no token was provided")
	ErrUserRefreshToken = errors.New("the provided user refresh token is empty")
	ErrNoRefresher      = errors.New("refresher was not provided")
)

Functions

func ValidateToken added in v0.7.0

func ValidateToken(ctx context.Context, httpClient *http.Client, accessToken string) (bool, error)

ValidateToken checks if an access token is still valid by calling Twitch's validate endpoint. Returns true if valid, false if invalid/expired.

Types

type API

type API struct {
	// contains filtered or unexported fields
}

func NewAPI

func NewAPI(clientID string, opts ...APIOptionFunc) (*API, error)

func (*API) BanUser

func (a *API) BanUser(ctx context.Context, broadcasterID string, moderatorID string, data BanUserData) error

func (*API) CreateClip

func (a *API) CreateClip(ctx context.Context, broadcastID string, hasDelay bool) (CreatedClip, error)

func (*API) CreateStreamMarker

func (a *API) CreateStreamMarker(ctx context.Context, req CreateStreamMarkerRequest) (StreamMarker, error)

func (*API) DeleteMessage

func (a *API) DeleteMessage(ctx context.Context, broadcasterID string, moderatorID string, messageID string) error

func (*API) DeleteSubSubscriptions

func (a *API) DeleteSubSubscriptions(ctx context.Context, id string) error

func (*API) FetchAllUserEmotes

func (a *API) FetchAllUserEmotes(ctx context.Context, userID string, broadcasterID string) ([]UserEmoteImage, string, error)

func (*API) FetchEventSubSubscriptions

func (a *API) FetchEventSubSubscriptions(ctx context.Context, status, subType, userID string) ([]EventSubData, error)

https://dev.twitch.tv/docs/api/reference/#get-eventsub-subscriptions

func (*API) FetchUnbanRequests

func (a *API) FetchUnbanRequests(ctx context.Context, broadcasterID, moderatorID string) ([]UnbanRequest, error)

func (*API) FetchUserFollowedChannels

func (a *API) FetchUserFollowedChannels(ctx context.Context, userID string, broadcasterID string) ([]FollowedChannel, error)

func (*API) GetChannelChatBadges

func (a *API) GetChannelChatBadges(ctx context.Context, broadcasterID string) ([]BadgeSet, error)

func (*API) GetChannelEmotes

func (a *API) GetChannelEmotes(ctx context.Context, broadcaster string) (EmoteResponse, error)

func (*API) GetChatSettings

func (a *API) GetChatSettings(ctx context.Context, broadcasterID string, moderatorID string) (GetChatSettingsResponse, error)

moderatorID needs to match ID of the user the token was generated for

func (*API) GetGlobalChatBadges

func (a *API) GetGlobalChatBadges(ctx context.Context) ([]BadgeSet, error)

func (*API) GetGlobalEmotes

func (a *API) GetGlobalEmotes(ctx context.Context) (EmoteResponse, error)

func (*API) GetStreamInfo

func (a *API) GetStreamInfo(ctx context.Context, broadcastID []string) (GetStreamsResponse, error)

func (*API) GetUserChatColor

func (a *API) GetUserChatColor(ctx context.Context, userIDs []string) ([]UserChatColor, error)

func (*API) GetUsers

func (a *API) GetUsers(ctx context.Context, logins []string, ids []string) (UserResponse, error)

func (*API) ResolveBanRequest

func (a *API) ResolveBanRequest(ctx context.Context, broadcasterID, moderatorID, requestID, status string) (UnbanRequest, error)

func (*API) SendChatAnnouncement

func (a *API) SendChatAnnouncement(ctx context.Context, broadcasterID string, moderatorID string, req CreateChatAnnouncementRequest) error

func (*API) SendChatMessage

func (a *API) SendChatMessage(ctx context.Context, data SendChatMessageRequest) (SendChatMessageResponse, error)

func (*API) UnbanUser

func (a *API) UnbanUser(ctx context.Context, broadcasterID string, moderatorID string, userID string) error

type APIError

type APIError struct {
	ErrorText string `json:"error"`
	Status    int    `json:"status"`
	Message   string `json:"message"`
}

error response

func (APIError) Error

func (a APIError) Error() string

type APIOptionFunc

type APIOptionFunc func(api *API) error

func WithHTTPClient

func WithHTTPClient(client *http.Client) APIOptionFunc

func WithTransport added in v0.7.0

func WithTransport(transport http.RoundTripper) APIOptionFunc

func WithUserAuthentication

func WithUserAuthentication(provider AccountProvider, refresher TokenRefresher, accountID string) APIOptionFunc

type AccountProvider

type AccountProvider interface {
	GetAccountBy(id string) (save.Account, error)
	UpdateTokensFor(id, accessToken, refreshToken string) error
}

type BadgeSet

type BadgeSet struct {
	ID       string         `json:"set_id"`
	Versions []BadgeVersion `json:"versions"`
}

type BadgeVersion

type BadgeVersion struct {
	ID           string `json:"id"`
	Image_URL_1x string `json:"image_url_1x"`
	Image_URL_2x string `json:"image_url_2x"`
	Image_URL_4x string `json:"image_url_4x"`
	Title        string `json:"title"`
	Description  string `json:"description"`
	ClickAction  string `json:"click_action"`
	ClickURL     string `json:"click_url"`
}

type BanUserData

type BanUserData struct {
	UserID            string `json:"user_id"`
	DurationInSeconds int    `json:"duration,omitempty"`
	Reason            string `json:"reason"`
}

type BanUserRequest

type BanUserRequest struct {
	Data BanUserData `json:"data"`
}

type ChatAnnouncementColor

type ChatAnnouncementColor string
const (
	ChatAnnouncementColorBlue    ChatAnnouncementColor = "blue"
	ChatAnnouncementColorGreen   ChatAnnouncementColor = "green"
	ChatAnnouncementColorOrange  ChatAnnouncementColor = "orange"
	ChatAnnouncementColorPurple  ChatAnnouncementColor = "purple"
	ChatAnnouncementColorPrimary ChatAnnouncementColor = "primary"
)

type ChatSettingData

type ChatSettingData struct {
	BroadcasterID                 string `json:"broadcaster_id"`
	SlowMode                      bool   `json:"slow_mode"`
	SlowModeWaitTime              int    `json:"slow_mode_wait_time"` // in seconds
	FollowerMode                  bool   `json:"follower_mode"`
	FollowerModeDuration          int    `json:"follower_mode_duration"` // in minutes
	SubscriberMode                bool   `json:"subscriber_mode"`
	EmoteMode                     bool   `json:"emote_mode"`
	UniqueChatMode                bool   `json:"unique_chat_mode"`
	NonModeratorChatDelay         bool   `json:"non_moderator_chat_delay"`
	NonModeratorChatDelayDuration int    `json:"non_moderator_chat_delay_duration"` // in seconds
}

type CreateChatAnnouncementRequest

type CreateChatAnnouncementRequest struct {
	Message string                `json:"message"`
	Color   ChatAnnouncementColor `json:"color"`
}

https://dev.twitch.tv/docs/api/reference/#send-chat-announcement

type CreateClipResponse

type CreateClipResponse struct {
	Data []CreatedClip `json:"data"`
}

type CreateEventSubSubscriptionRequest

type CreateEventSubSubscriptionRequest struct {
	Type      string                   `json:"type"`
	Version   string                   `json:"version"`
	Condition map[string]string        `json:"condition"`
	Transport EventSubTransportRequest `json:"transport"`
}

type CreateEventSubSubscriptionResponse

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

type CreateStreamMarkerRequest

type CreateStreamMarkerRequest struct {
	UserID string `json:"user_id"`
	// optional
	Description string `json:"description,omitempty"`
}

type CreateStreamMarkerResponse

type CreateStreamMarkerResponse struct {
	Data []StreamMarker `json:"data"`
}

type CreatedClip

type CreatedClip struct {
	ID      string `json:"id"`
	EditURL string `json:"edit_url"`
}

type DropReason

type DropReason struct {
	Code    string `json:"code"`
	Message string `json:"message"`
}

https://dev.twitch.tv/docs/api/reference/#send-chat-message

type EmoteData

type EmoteData struct {
	ID        string     `json:"id"`
	EmoteType string     `json:"emote_type"`
	Name      string     `json:"name"`
	Images    EmoteImage `json:"images"`
	Format    []string   `json:"format"`
	Scale     []string   `json:"scale"`
	ThemeMode []string   `json:"theme_mode"`
}

type EmoteImage

type EmoteImage struct {
	URL1X string `json:"url_1x"`
	URL2X string `json:"url_2x"`
	URL4X string `json:"url_4x"`
}

type EmoteResponse

type EmoteResponse struct {
	Data     []EmoteData `json:"data"`
	Template string      `json:"template"`
}

type EventSubData

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

type EventSubTransport

type EventSubTransport struct {
	Method    string `json:"method"`
	ConduitID string `json:"conduit_id"`
}

type EventSubTransportRequest

type EventSubTransportRequest struct {
	Method    string `json:"method"`
	Callback  string `json:"callback"`
	ConduitID string `json:"conduit_id"`
	Secret    string `json:"secret"`
	SessionID string `json:"session_id"`
}

type FollowedChannel

type FollowedChannel struct {
	BroadcasterID    string    `json:"broadcaster_id"`
	BroadcasterLogin string    `json:"broadcaster_login"`
	BroadcasterName  string    `json:"broadcaster_name"`
	FollowedAt       time.Time `json:"followed_at"`
}

type GetChannelChatBadgesResp

type GetChannelChatBadgesResp struct {
	Data []BadgeSet `json:"data"`
}

type GetChatSettingsResponse

type GetChatSettingsResponse struct {
	Data []ChatSettingData `json:"data"`
}

type GetEventSubSubscriptionsResponse

type GetEventSubSubscriptionsResponse struct {
	Total        int            `json:"total"`
	TotalCost    int            `json:"total_cost"`
	MaxTotalCost int            `json:"max_total_cost"`
	Pagination   Pagination     `json:"pagination"`
	Data         []EventSubData `json:"data"`
}

type GetFollowedChannelsResponse

type GetFollowedChannelsResponse struct {
	Total      int               `json:"total"`
	Data       []FollowedChannel `json:"data"`
	Pagination Pagination        `json:"pagination"`
}

type GetGlobalBadgesResp

type GetGlobalBadgesResp struct {
	Data []BadgeSet `json:"data"`
}

type GetStreamsResponse

type GetStreamsResponse struct {
	Data       []StreamData `json:"data"`
	Pagination Pagination   `json:"pagination"`
}

type GetUnbanRequestsResponse

type GetUnbanRequestsResponse struct {
	Data       []UnbanRequest `json:"data"`
	Pagination Pagination     `json:"pagination"`
}

type GetUserChatColorResponse

type GetUserChatColorResponse struct {
	Data []UserChatColor `json:"data"`
}

type GetUserEmotesResponse

type GetUserEmotesResponse struct {
	Data       []UserEmoteImage `json:"data"`
	Template   string           `json:"template"`
	Pagination Pagination       `json:"pagination"`
}

type Pagination

type Pagination struct {
	Cursor string `json:"cursor"`
}

type SendChatMessageData

type SendChatMessageData struct {
	MessageID  string     `json:"message_id"`
	IsSent     bool       `json:"is_sent"`
	DropReason DropReason `json:"drop_reason"`
}

https://dev.twitch.tv/docs/api/reference/#send-chat-message

type SendChatMessageRequest

type SendChatMessageRequest struct {
	BroadcasterID string `json:"broadcaster_id"`
	SenderID      string `json:"sender_id"`
	Message       string `json:"message"`

	ReplyMessageID string `json:"reply_parent_message_id"`
	ForSourceOnly  bool   `json:"for_source_only,omitempty"`
}

https://dev.twitch.tv/docs/api/reference/#send-chat-message

type SendChatMessageResponse

type SendChatMessageResponse struct {
	Data []SendChatMessageData `json:"data"`
}

https://dev.twitch.tv/docs/api/reference/#send-chat-message

type StreamData

type StreamData struct {
	ID           string    `json:"id"`
	UserID       string    `json:"user_id"`
	UserLogin    string    `json:"user_login"`
	UserName     string    `json:"user_name"`
	GameID       string    `json:"game_id"`
	GameName     string    `json:"game_name"`
	Type         string    `json:"type"`
	Title        string    `json:"title"`
	Tags         []string  `json:"tags"`
	ViewerCount  int       `json:"viewer_count"`
	StartedAt    time.Time `json:"started_at"`
	Language     string    `json:"language"`
	ThumbnailURL string    `json:"thumbnail_url"`
	TagIds       []any     `json:"tag_ids"`
	IsMature     bool      `json:"is_mature"`
}

type StreamMarker

type StreamMarker struct {
	ID              string    `json:"id"`
	CreatedAt       time.Time `json:"created_at"`
	PositionSeconds int       `json:"position_seconds"`
	Description     string    `json:"description"`
}

type TokenRefresher

type TokenRefresher interface {
	RefreshToken(ctx context.Context, refreshToken string) (string, string, error)
}

type UnbanRequest

type UnbanRequest struct {
	ID               string    `json:"id"`
	BroadcasterName  string    `json:"broadcaster_name"`
	BroadcasterLogin string    `json:"broadcaster_login"`
	BroadcasterID    string    `json:"broadcaster_id"`
	ModeratorID      string    `json:"moderator_id"`
	ModeratorLogin   string    `json:"moderator_login"`
	ModeratorName    string    `json:"moderator_name"`
	UserID           string    `json:"user_id"`
	UserLogin        string    `json:"user_login"`
	UserName         string    `json:"user_name"`
	Text             string    `json:"text"`
	Status           string    `json:"status"`
	CreatedAt        time.Time `json:"created_at"`
	ResolvedAt       time.Time `json:"resolved_at"`
	ResolutionText   string    `json:"resolution_text"`
}

type UserChatColor

type UserChatColor struct {
	Color     string `json:"color"`
	UserName  string `json:"user_name"`
	UserLogin string `json:"user_login"`
	UserID    string `json:"user_id"`
}

type UserData

type UserData struct {
	ID              string    `json:"id"`
	Login           string    `json:"login"`
	DisplayName     string    `json:"display_name"`
	Type            string    `json:"type"`
	BroadcasterType string    `json:"broadcaster_type"`
	Description     string    `json:"description"`
	ProfileImageURL string    `json:"profile_image_url"`
	OfflineImageURL string    `json:"offline_image_url"`
	ViewCount       int       `json:"view_count"`
	Email           string    `json:"email"`
	CreatedAt       time.Time `json:"created_at"`
}

type UserEmoteImage

type UserEmoteImage struct {
	ID         string   `json:"id"`
	EmoteSetID string   `json:"emote_set_id"`
	EmoteType  string   `json:"emote_type"`
	Format     []string `json:"format"`
	Name       string   `json:"name"`
	OwnerID    string   `json:"owner_id"`
	Scale      []string `json:"scale"`
	ThemeMode  []string `json:"theme_mode"`
}

type UserResponse

type UserResponse struct {
	Data []UserData `json:"data"`
}

Jump to

Keyboard shortcuts

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