Documentation
¶
Index ¶
- Constants
- Variables
- func BuildHMACMessage(messageID, timestamp string, body []byte) []byte
- func ComputeHMAC(secret []byte, message []byte) string
- func HandleHealthCheck(w http.ResponseWriter, r *http.Request)
- func HandleLogin(w http.ResponseWriter, r *http.Request)
- func VerifyHMAC(computedHex, receivedHeader string) bool
- type Bot
- func (b *Bot) Handle(w http.ResponseWriter, r *http.Request)
- func (b *Bot) HandleCallback(w http.ResponseWriter, r *http.Request)
- func (b *Bot) Helix() *helix.Client
- func (b *Bot) LoadMiddleware(middlewares []middleware.Middleware)
- func (b *Bot) LoadRouter(routers []router.Router)
- func (b *Bot) Logger() log.Logger
- func (b *Bot) Routes(m *chi.Mux)
- func (b *Bot) Start()
- type ChallengeRequest
- type EventEngine
- type HelixRefreshTransport
- type Method
- type Response
- type Status
- type Subscription
- type SubscriptionType
Constants ¶
const ( Webhook Method = "webhook" Websocket Method = "websocket" Enabled Status = "enabled" Disabled Status = "disabled" )
Variables ¶
var FULL_AUTH_SCOPES = []string{
"analytics:read:extensions",
"analytics:read:games",
"bits:read",
"channel:bot",
"channel:manage:ads",
"channel:read:ads",
"channel:manage:broadcast",
"channel:read:charity",
"channel:manage:clips",
"channel:edit:commercial",
"channel:read:editors",
"channel:manage:extensions",
"channel:read:goals",
"channel:read:guest_star",
"channel:manage:guest_star",
"channel:read:hype_train",
"channel:manage:moderators",
"channel:read:polls",
"channel:manage:polls",
"channel:read:predictions",
"channel:manage:predictions",
"channel:manage:raids",
"channel:read:redemptions",
"channel:manage:redemptions",
"channel:manage:schedule",
"channel:read:stream_key",
"channel:read:subscriptions",
"channel:manage:videos",
"channel:read:vips",
"channel:manage:vips",
"channel:moderate",
"clips:edit",
"editor:manage:clips",
"moderation:read",
"moderator:manage:banned_users",
"moderator:read:blocked_terms",
"moderator:read:chat_messages",
"moderator:manage:blocked_terms",
"moderator:manage:chat_messages",
"moderator:read:chat_settings",
"moderator:manage:chat_settings",
"moderator:read:chatters",
"moderator:read:followers",
"moderator:read:guest_star",
"moderator:manage:guest_star",
"moderator:read:shield_mode",
"moderator:manage:shield_mode",
"moderator:read:shoutouts",
"moderator:manage:shoutouts",
"moderator:read:suspicious_users",
"moderator:read:unban_requests",
"moderator:manage:unban_requests",
"moderator:read:vips",
"moderator:read:warnings",
"moderator:manage:warnings",
"user:bot",
"user:edit",
"user:edit:broadcast",
"user:read:blocked_users",
"user:manage:blocked_users",
"user:read:broadcast",
"user:read:chat",
"user:manage:chat_color",
"user:read:email",
"user:read:emotes",
"user:read:follows",
"user:read:moderated_channels",
"user:read:subscriptions",
"user:read:whispers",
"user:manage:whispers",
"user:write:chat",
"chat:edit",
"chat:read",
"whispers:read",
}
Functions ¶
func BuildHMACMessage ¶ added in v1.1.0
BuildHMACMessage constructs the message string used to compute the HMAC.
func ComputeHMAC ¶ added in v1.1.0
ComputeHMAC returns the HMAC SHA-256 hex digest for the provided secret and message.
func HandleHealthCheck ¶ added in v1.1.0
func HandleHealthCheck(w http.ResponseWriter, r *http.Request)
func HandleLogin ¶ added in v1.1.0
func HandleLogin(w http.ResponseWriter, r *http.Request)
func VerifyHMAC ¶ added in v1.1.0
VerifyHMAC performs a constant-time comparison between the computed HMAC and the provided signature.
Types ¶
type Bot ¶
type Bot struct {
// contains filtered or unexported fields
}
configuration, middleware, routers, and structured logging.
func New ¶
func New(engine EventEngine) *Bot
New creates a new Bot instance with configuration loaded and a logger initialized.
It will fatal exit if configuration loading failb.
Example:
bot := twitchgo.New()
func (*Bot) HandleCallback ¶ added in v1.1.1
func (b *Bot) HandleCallback(w http.ResponseWriter, r *http.Request)
func (*Bot) Helix ¶ added in v1.1.0
Helix returns the helix instance used by the bot.
Example:
helix := bot.Helix() helix.GetUser...
func (*Bot) LoadMiddleware ¶ added in v1.1.4
func (b *Bot) LoadMiddleware(middlewares []middleware.Middleware)
LoadMiddleware appends one or more middleware instances to the server's middleware chain.
Middleware registered here will be applied globally to all routers.
Example:
srv.LoadMiddleware([]middleware.Middleware{corsMw, loggingMw})
func (*Bot) LoadRouter ¶ added in v1.1.4
LoadRouter appends one or more routers to the server's router list.
Example:
srv.LoadRouter([]router.Router{myRouter1, myRouter2})
type ChallengeRequest ¶ added in v1.1.0
type ChallengeRequest struct {
Challenge string `json:"challenge"`
}
type EventEngine ¶ added in v1.1.0
type EventEngine interface {
// OnBotStart is called when the bot starts.
// Useful for initializing connections, registering event subscriptions, or performing startup routines.
OnBotStart(ctx context.Context, api *helix.Client)
// OnClientLogin is called when a user logs into the client.
// At this point, access and refresh tokens are set, allowing API calls on behalf of the user.
OnClientLogin(ctx context.Context, api *helix.Client)
// OnClientRefresh is called whenever an access token is refreshed.
// This ensures the bot continues to operate with a valid token without interruption.
OnClientRefresh(ctx context.Context, api *helix.Client)
OnChannelChatMessage(ctx context.Context, api *helix.Client, response Response[helix.EventSubChannelChatMessageEvent, helix.EventSubCondition])
}
EventEngine defines an interface for handling various Twitch bot events.
type HelixRefreshTransport ¶ added in v1.3.0
type HelixRefreshTransport struct {
Base http.RoundTripper
Client *helix.Client
Event EventEngine
}
type Response ¶ added in v1.1.0
type Response[T interface{}, U interface{}] struct {
Event T `json:"event"`
Subscription Subscription[U] `json:"subscription"`
}
Request represents an EventSub subscription response.
See: https://dev.twitch.tv/docs/eventsub/eventsub-reference for more information.
type Subscription ¶ added in v1.1.0
type SubscriptionType ¶ added in v1.1.0
type SubscriptionType string
const (
ChannelChatMessage SubscriptionType = "channel.chat.message.v1"
)