42 lines
1.3 KiB
Go
42 lines
1.3 KiB
Go
|
package chat
|
|||
|
|
|||
|
import (
|
|||
|
"context"
|
|||
|
"encoding/json"
|
|||
|
"net/http"
|
|||
|
"net/url"
|
|||
|
)
|
|||
|
|
|||
|
type GetChannelChatBadgesResponse struct {
|
|||
|
// The list of chat badges. The list is sorted in ascending order by set_id, and within a set, the list is sorted in ascending order by id.
|
|||
|
Data []Badge `json:"data"`
|
|||
|
}
|
|||
|
|
|||
|
// Gets the broadcaster’s list of custom chat badges. The list is empty if the broadcaster hasn’t created custom chat badges.
|
|||
|
// For information about custom badges,
|
|||
|
// see subscriber badges: https://help.twitch.tv/s/article/subscriber-badge-guide
|
|||
|
// and Bits badges: https://help.twitch.tv/s/article/custom-bit-badges-guide.
|
|||
|
//
|
|||
|
// Requires an app access token or user access token.
|
|||
|
func (c *Chat) GetChannelChatBadges(ctx context.Context, broadcasterID string) (*GetChannelChatBadgesResponse, error) {
|
|||
|
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "chat/badges", RawQuery: "broadcaster_id=" + broadcasterID})
|
|||
|
|
|||
|
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
|
|||
|
if err != nil {
|
|||
|
return nil, err
|
|||
|
}
|
|||
|
|
|||
|
res, err := c.client.Do(req)
|
|||
|
if err != nil {
|
|||
|
return nil, err
|
|||
|
}
|
|||
|
defer res.Body.Close()
|
|||
|
|
|||
|
var data GetChannelChatBadgesResponse
|
|||
|
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
|
|||
|
return nil, err
|
|||
|
}
|
|||
|
|
|||
|
return &data, nil
|
|||
|
}
|