Class: ModerationAPI::Resources::Content

Inherits:
Object
  • Object
show all
Defined in:
lib/moderation_api/resources/content.rb,
sig/moderation_api/resources/content.rbs

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Content

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Content.

Parameters:



94
95
96
# File 'lib/moderation_api/resources/content.rb', line 94

def initialize(client:)
  @client = client
end

Instance Method Details

#stream(sec_web_socket_protocol:, request_options: {}) ⇒ nil

Open a WebSocket to moderate live voice/call audio in real time. Speech is transcribed and each finalized utterance is moderated by your enabled text policies; you receive a verdict per utterance as it's spoken.

This is a WebSocket upgrade, not a regular HTTP call. The request body below documents the frames you send over the socket; the 101 response documents the events you receive.

  • Auth: Authorization: Bearer <api_key> on the upgrade. A missing/invalid key closes 4401; voice not enabled on the plan/channel closes 4403.
  • Subprotocol: request moderationapi.v1.
  • Flow: send one start frame, then media frames as audio arrives, then stop (or disconnect). You receive session.started, utterance.final per utterance, optional utterance.partial/warning, and session.ended.
  • Close codes: 1000 normal · 1011 server error · 4400 bad request · 4401 auth failed · 4403 voice not enabled · 4429 concurrency limit.

See the Real-time voice guide for the full walkthrough and code examples.

Parameters:

Returns:

  • (nil)

See Also:



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/moderation_api/resources/content.rb', line 36

def stream(params)
  parsed, options = ModerationAPI::ContentStreamParams.dump_request(params)
  path = @client.base_url_overridden? ? "stream" : "wss://voice.moderationapi.com/v1/stream"
  @client.request(
    method: :get,
    path: path,
    headers: parsed.transform_keys(sec_web_socket_protocol: "sec-websocket-protocol"),
    model: NilClass,
    options: options
  )
end

#submit(content:, author_id: nil, channel: nil, client_action: nil, content_id: nil, conversation_id: nil, do_not_store: nil, metadata: nil, meta_type: nil, policies: nil, timestamp: nil, request_options: {}) ⇒ ModerationAPI::Models::ContentSubmitResponse

Some parameter documentations has been truncated, see Models::ContentSubmitParams for more details.

Parameters:

Returns:

See Also:



80
81
82
83
84
85
86
87
88
89
# File 'lib/moderation_api/resources/content.rb', line 80

def submit(params)
  parsed, options = ModerationAPI::ContentSubmitParams.dump_request(params)
  @client.request(
    method: :post,
    path: "moderate",
    body: parsed,
    model: ModerationAPI::Models::ContentSubmitResponse,
    options: options
  )
end