Class: ElevenlabsClient::Endpoints::AgentsPlatform::Widgets

Inherits:
Object
  • Object
show all
Defined in:
lib/elevenlabs_client/endpoints/agents_platform/widgets.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Widgets

Returns a new instance of Widgets.



7
8
9
# File 'lib/elevenlabs_client/endpoints/agents_platform/widgets.rb', line 7

def initialize(client)
  @client = client
end

Instance Method Details

#create_avatar(agent_id, avatar_file_io:, filename:) ⇒ Hash

POST /v1/convai/agents/agent_id/avatar Sets the avatar for an agent displayed in the widget Documentation: https://elevenlabs.io/docs/api-reference/convai/agents/create-avatar

Parameters:

  • agent_id (String)

    The id of an agent

  • avatar_file_io (IO)

    The avatar file to upload (e.g., File.open("avatar.png", "rb"))

  • filename (String)

    The name of the file, including extension

Returns:

  • (Hash)

    JSON response containing agent_id and avatar_url



39
40
41
42
43
44
45
46
47
48
# File 'lib/elevenlabs_client/endpoints/agents_platform/widgets.rb', line 39

def create_avatar(agent_id, avatar_file_io:, filename:)
  endpoint = "/v1/convai/agents/#{agent_id}/avatar"
  
  # Prepare multipart form data
  payload = {
    "avatar_file" => @client.file_part(avatar_file_io, filename)
  }

  @client.post_multipart(endpoint, payload)
end

#get(agent_id, **options) ⇒ Hash

GET /v1/convai/agents/agent_id/widget Retrieve the widget configuration for an agent Documentation: https://elevenlabs.io/docs/api-reference/convai/agents/get-widget

Parameters:

  • agent_id (String)

    The id of an agent

  • options (Hash)

    Optional parameters

Options Hash (**options):

  • :conversation_signature (String)

    An expiring token that enables a websocket conversation to start

Returns:

  • (Hash)

    Widget configuration including styling, behavior, and text content



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/elevenlabs_client/endpoints/agents_platform/widgets.rb', line 19

def get(agent_id, **options)
  endpoint = "/v1/convai/agents/#{agent_id}/widget"
  query_params = options.compact

  if query_params.any?
    query_string = URI.encode_www_form(query_params)
    endpoint = "#{endpoint}?#{query_string}"
  end

  @client.get(endpoint)
end