twitchapi

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 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) AddChannelModerator added in v1.5.0

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

func (*API) AddChannelVIP added in v1.5.0

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

func (*API) BanUser

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

func (*API) CancelRaid added in v1.5.0

func (a *API) CancelRaid(ctx context.Context, broadcasterID string) 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) GetModerators added in v1.5.0

func (a *API) GetModerators(ctx context.Context, broadcasterID string, userIDs []string) ([]ChatRoleUser, error)

GetModerators lists the channel's moderators. userIDs optionally filters the result to the given users, so callers can resolve specific roles without downloading every page.

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) GetVIPs added in v1.5.0

func (a *API) GetVIPs(ctx context.Context, broadcasterID string, userIDs []string) ([]ChatRoleUser, error)

func (*API) ManageAutoModMessage added in v1.5.0

func (a *API) ManageAutoModMessage(ctx context.Context, userID string, messageID string, action string) error

func (*API) RemoveChannelModerator added in v1.5.0

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

func (*API) RemoveChannelVIP added in v1.5.0

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

func (*API) ResolveBanRequest

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

ResolveBanRequest approves or denies one unban request. resolutionText is optional and limited to 500 characters by Twitch.

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) SendShoutout added in v1.5.0

func (a *API) SendShoutout(ctx context.Context, fromBroadcasterID string, toBroadcasterID string, moderatorID string) error

func (*API) SnoozeNextAd added in v1.5.0

func (a *API) SnoozeNextAd(ctx context.Context, broadcasterID string) (AdSnoozeData, error)

func (*API) StartRaid added in v1.5.0

func (a *API) StartRaid(ctx context.Context, fromBroadcasterID string, toBroadcasterID string) (RaidData, error)

func (*API) UnbanUser

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

func (*API) UpdateChatSettings added in v1.5.0

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

func (*API) WarnChatUser added in v1.5.0

func (a *API) WarnChatUser(ctx context.Context, broadcasterID string, moderatorID string, userID string, reason 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 AdSnoozeData added in v1.5.0

type AdSnoozeData struct {
	NextAdAt        string `json:"next_ad_at"`
	SnoozeRefreshAt string `json:"snooze_refresh_at"`
}

https://dev.twitch.tv/docs/api/reference/#snooze-next-ad

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"`
}

https://dev.twitch.tv/docs/api/reference/#get-channel-chat-badges https://dev.twitch.tv/docs/api/reference#get-global-emotes

type BanUserData

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

https://dev.twitch.tv/docs/api/reference/#ban-user

type BanUserRequest

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

https://dev.twitch.tv/docs/api/reference/#ban-user

type ChatAnnouncementColor

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

type ChatRoleUser added in v1.5.0

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

https://dev.twitch.tv/docs/api/reference/#get-moderators https://dev.twitch.tv/docs/api/reference/#get-vips

type ChatRoleUsersResponse added in v1.5.0

type ChatRoleUsersResponse struct {
	Data       []ChatRoleUser `json:"data"`
	Pagination Pagination     `json:"pagination"`
}

https://dev.twitch.tv/docs/api/reference/#get-moderators https://dev.twitch.tv/docs/api/reference/#get-vips

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
}

https://dev.twitch.tv/docs/api/reference/#get-chat-settings

type ChatSettingsUpdateData added in v1.5.0

type ChatSettingsUpdateData struct {
	SlowMode                      *bool `json:"slow_mode,omitempty"`
	SlowModeWaitTime              *int  `json:"slow_mode_wait_time,omitempty"`
	FollowerMode                  *bool `json:"follower_mode,omitempty"`
	FollowerModeDuration          *int  `json:"follower_mode_duration,omitempty"`
	SubscriberMode                *bool `json:"subscriber_mode,omitempty"`
	EmoteMode                     *bool `json:"emote_mode,omitempty"`
	UniqueChatMode                *bool `json:"unique_chat_mode,omitempty"`
	NonModeratorChatDelay         *bool `json:"non_moderator_chat_delay,omitempty"`
	NonModeratorChatDelayDuration *int  `json:"non_moderator_chat_delay_duration,omitempty"`
}

ChatSettingsUpdateData is the PATCH body of Update Chat Settings. Every field is optional: nil means "leave this setting alone", which is why the fields are pointers instead of zero values. A false boolean is a real update.

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"`
}

https://dev.twitch.tv/docs/api/reference/#create-clip

type CreateEventSubSubscriptionRequest

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

https://dev.twitch.tv/docs/api/reference/#create-eventsub-subscription

type CreateEventSubSubscriptionResponse

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

https://dev.twitch.tv/docs/api/reference/#create-eventsub-subscription

type CreateStreamMarkerRequest

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

https://dev.twitch.tv/docs/api/reference/#create-stream-marker

type CreateStreamMarkerResponse

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

https://dev.twitch.tv/docs/api/reference/#create-stream-marker

type CreatedClip

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

https://dev.twitch.tv/docs/api/reference/#create-clip

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"`
}

https://api.twitch.tv/helix/chat/emotes/global

type EmoteImage

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

https://api.twitch.tv/helix/chat/emotes/global

type EmoteResponse

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

https://api.twitch.tv/helix/chat/emotes/global

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"`
}

https://dev.twitch.tv/docs/api/reference/#create-eventsub-subscription

type EventSubTransport

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

https://dev.twitch.tv/docs/api/reference/#create-eventsub-subscription

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"`
}

https://dev.twitch.tv/docs/api/reference/#create-eventsub-subscription

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"`
}

https://dev.twitch.tv/docs/api/reference/#get-followed-channels

type GetChatSettingsResponse

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

https://dev.twitch.tv/docs/api/reference/#get-chat-settings

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"`
}

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

type GetFollowedChannelsResponse

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

https://dev.twitch.tv/docs/api/reference/#get-followed-channels

type GetStreamsResponse

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

https://api.twitch.tv/helix/streams

type GetUnbanRequestsResponse

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

https://dev.twitch.tv/docs/api/reference/#get-unban-requests

type GetUserChatColorResponse

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

https://dev.twitch.tv/docs/api/reference/#get-user-chat-color

type GetUserEmotesResponse

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

https://dev.twitch.tv/docs/api/reference/#get-user-emotes

type ManageAutoModMessageRequest added in v1.5.0

type ManageAutoModMessageRequest struct {
	UserID string `json:"user_id"`
	MsgID  string `json:"msg_id"`
	Action string `json:"action"`
}

https://dev.twitch.tv/docs/api/reference/#manage-held-automod-messages

type Pagination

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

https://api.twitch.tv/helix/streams

type RaidData added in v1.5.0

type RaidData struct {
	CreatedAt time.Time `json:"created_at"`
	IsMature  bool      `json:"is_mature"`
}

https://dev.twitch.tv/docs/api/reference/#start-a-raid

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 SnoozeNextAdResponse added in v1.5.0

type SnoozeNextAdResponse struct {
	Data []AdSnoozeData `json:"data"`
}

https://dev.twitch.tv/docs/api/reference/#snooze-next-ad

type StartRaidResponse added in v1.5.0

type StartRaidResponse struct {
	Data []RaidData `json:"data"`
}

https://dev.twitch.tv/docs/api/reference/#start-a-raid

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"`
}

https://api.twitch.tv/helix/streams

type StreamMarker

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

https://dev.twitch.tv/docs/api/reference/#create-stream-marker

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"`
}

https://dev.twitch.tv/docs/api/reference/#get-unban-requests

type UserChatColor

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

https://dev.twitch.tv/docs/api/reference/#get-user-chat-color

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"`
}

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

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"`
}

https://dev.twitch.tv/docs/api/reference/#get-user-emotes

type UserResponse

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

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

type WarnChatUserData added in v1.5.0

type WarnChatUserData struct {
	UserID string `json:"user_id"`
	Reason string `json:"reason"`
}

https://dev.twitch.tv/docs/api/reference/#warn-chat-user

type WarnChatUserRequest added in v1.5.0

type WarnChatUserRequest struct {
	Data WarnChatUserData `json:"data"`
}

https://dev.twitch.tv/docs/api/reference/#warn-chat-user

Jump to

Keyboard shortcuts

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