go-twitch/api/chat/send_shoutout.go

61 lines
2.2 KiB
Go
Raw Permalink Normal View History

2024-02-28 10:30:20 -05:00
package chat
import (
"context"
"fmt"
2024-02-28 10:30:20 -05:00
"net/http"
"github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
2024-02-28 10:30:20 -05:00
)
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)
2024-02-28 10:30:20 -05:00
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)
}
2024-02-28 10:30:20 -05:00
return nil
}