go-twitch/api/moderation/manage_held_automod_message...

56 lines
1.6 KiB
Go
Raw Normal View History

2024-03-03 15:14:59 -05:00
package moderation
import (
"context"
"fmt"
2024-03-03 15:14:59 -05:00
"net/http"
"net/url"
)
type AutoModAction string
const (
AutoModActionAllow AutoModAction = "ALLOW"
AutoModActionDeny AutoModAction = "DENY"
)
type ManageHeldAutoModMessagesRequest struct {
// The moderator who is approving or denying the held message. This ID must match the user ID in the access token.
UserID string `url:"user_id"`
// The ID of the message to allow or deny.
MsgID string `url:"msg_id"`
// The action to take for the message.
Action AutoModAction `url:"action"`
}
// Allow or deny the message that AutoMod flagged for review.
// For information about AutoMod, see How to Use AutoMod: https://help.twitch.tv/s/article/how-to-use-automod
//
// To get messages that AutoMod is holding for review, subscribe to the automod-queue.<moderator_id>.<channel_id> topic using PubSub.
// PubSub sends a notification to your app when AutoMod holds a message for review.
//
// Requires a user access token that includes the moderator:manage:automod scope.
func (m *Moderation) ManageHeldAutoModMessages(ctx context.Context, body *ManageHeldAutoModMessagesRequest) error {
endpoint := m.baseUrl.ResolveReference(&url.URL{Path: "moderation/automod/message"})
req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.String(), nil)
if err != nil {
return err
}
res, err := m.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 manage held AutoMod messages (%d)", res.StatusCode)
}
2024-03-03 15:14:59 -05:00
return nil
}