Current section
Files
Jump to
Current section
Files
lib/teac/api/moderation/chat.ex
defmodule Teac.Api.Moderation.Chat do
alias Teac.Api
@schema NimbleOptions.new!(
broadcaster_id: [type: :string, required: true],
moderator_id: [type: :string, required: true],
message_id: [type: :string]
)
@doc """
Removes a single chat message or all chat messages from the broadcaster's chat room.
## Authorization
Requires a user access token with the `moderator:manage:chat_messages` scope.
## Options
* `:broadcaster_id` - required. The ID of the broadcaster whose chat to delete messages from.
* `:moderator_id` - required. The ID of the moderator deleting the message.
* `:message_id` - optional. The ID of the message to delete. If omitted, deletes all messages.
"""
@spec delete(Teac.Client.t(), keyword()) :: {:ok, nil, Teac.RateLimit.t()} | {:error, Teac.Error.t()}
def delete(%Teac.Client{} = client, opts \\ []) do
case NimbleOptions.validate(opts, @schema) do
{:ok, opts} ->
params =
[
broadcaster_id: opts[:broadcaster_id],
moderator_id: opts[:moderator_id],
message_id: opts[:message_id]
]
|> Enum.reject(fn {_, v} -> is_nil(v) end)
[base_url: Api.uri("moderation/chat"), params: params, headers: Api.headers(client)]
|> Keyword.merge(Application.get_env(:teac, :api_req_options, []))
|> Req.delete()
|> Api.handle_response()
{:error, %NimbleOptions.ValidationError{} = err} ->
{:error, err.message}
end
end
end