go-twitch/api/chat/send_shoutout.go

61 lines
2.2 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package chat
import (
"context"
"fmt"
"net/http"
"github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
)
type SendShoutoutParams struct {
// The ID of the broadcaster thats sending the Shoutout.
FromBroadcasterID string `url:"from_broadcaster_id"`
// The ID of the broadcaster thats receiving the Shoutout.
ToBroadcasterID string `url:"to_broadcaster_id"`
// The ID of the broadcaster or a user that is one of the broadcasters moderators.
// This ID must match the user ID in the access token.
ModeratorID string `url:"moderator_id"`
}
// Sends a Shoutout to the specified broadcaster.
// Typically, you send Shoutouts when you or one of your moderators notice another broadcaster in your chat,
// the other broadcaster is coming up in conversation, or after they raid your broadcast.
//
// Twitchs Shoutout feature is a great way for you to show support for other broadcasters and help them grow.
// Viewers who do not follow the other broadcaster will see a pop-up Follow button in your chat that they can click to follow the other broadcaster.
// Learn More: https://help.twitch.tv/s/article/shoutouts
//
// Rate Limits The broadcaster may send a Shoutout once every 2 minutes.
// They may send the same broadcaster a Shoutout once every 60 minutes.
//
// To receive notifications when a Shoutout is sent or received, subscribe to the channel.shoutout.create and channel.shoutout.receive subscription types.
// The channel.shoutout.create event includes cooldown periods that indicate when the broadcaster may send another
// Shoutout without exceeding the endpoints rate limit.
//
// Requires a user access token that includes the moderator:manage:shoutouts scope.
func (c *Chat) SendShoutout(ctx context.Context, params *SendShoutoutParams) error {
v, _ := query.Values(params)
req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.Make(c.baseUrl, "chat/shoutouts", v), nil)
if err != nil {
return err
}
res, err := c.client.Do(req)
if err != nil {
return err
}
defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return fmt.Errorf("failed to send shoutout (%d)", res.StatusCode)
}
return nil
}