Class: Tavus::Resources::Conversations

Inherits:
Object
  • Object
show all
Defined in:
lib/tavus/resources/conversations.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Conversations

Returns a new instance of Conversations.



6
7
8
# File 'lib/tavus/resources/conversations.rb', line 6

def initialize(client)
  @client = client
end

Instance Method Details

#create(replica_id: nil, persona_id: nil, **options) ⇒ Hash

Create a new conversation

Parameters:

  • replica_id (String) (defaults to: nil)

    The unique identifier for the replica

  • persona_id (String) (defaults to: nil)

    The unique identifier for the persona

  • options (Hash)

    Additional optional parameters

Options Hash (**options):

  • :audio_only (Boolean)

    Specifies whether the interaction should be voice-only

  • :callback_url (String)

    A URL that will receive webhooks

  • :conversation_name (String)

    A name for the conversation

  • :conversational_context (String)

    Optional context for the conversation

  • :custom_greeting (String)

    Custom greeting for the replica

  • :memory_stores (Array<String>)

    Memory stores to use for the conversation

  • :document_ids (Array<String>)

    Document IDs the persona can access

  • :document_retrieval_strategy (String)

    Strategy for document retrieval (speed, quality, balanced)

  • :document_tags (Array<String>)

    Document tags the replica can access

  • :test_mode (Boolean)

    If true, conversation created but replica won’t join

  • :properties (Hash)

    Optional properties to customize the conversation

Returns:

  • (Hash)

    The created conversation details



26
27
28
29
30
31
32
# File 'lib/tavus/resources/conversations.rb', line 26

def create(replica_id: nil, persona_id: nil, **options)
  body = options.dup
  body[:replica_id] = replica_id if replica_id
  body[:persona_id] = persona_id if persona_id

  @client.post("/v2/conversations", body: body)
end

#delete(conversation_id) ⇒ Hash

Delete a conversation

Parameters:

  • conversation_id (String)

    The unique identifier of the conversation

Returns:

  • (Hash)

    Success response



61
62
63
# File 'lib/tavus/resources/conversations.rb', line 61

def delete(conversation_id)
  @client.delete("/v2/conversations/#{conversation_id}")
end

#end(conversation_id) ⇒ Hash

End a conversation

Parameters:

  • conversation_id (String)

    The unique identifier of the conversation

Returns:

  • (Hash)

    Success response



54
55
56
# File 'lib/tavus/resources/conversations.rb', line 54

def end(conversation_id)
  @client.post("/v2/conversations/#{conversation_id}/end")
end

#get(conversation_id) ⇒ Hash

Get a single conversation by ID

Parameters:

  • conversation_id (String)

    The unique identifier of the conversation

Returns:

  • (Hash)

    The conversation details



37
38
39
# File 'lib/tavus/resources/conversations.rb', line 37

def get(conversation_id)
  @client.get("/v2/conversations/#{conversation_id}")
end

#list(**options) ⇒ Hash

List all conversations

Parameters:

  • options (Hash)

    Query parameters

Options Hash (**options):

  • :limit (Integer)

    Number of conversations to return per page (default: 10)

  • :page (Integer)

    Page number to return (default: 1)

  • :status (String)

    Filter by status (active, ended)

Returns:

  • (Hash)

    List of conversations and total count



47
48
49
# File 'lib/tavus/resources/conversations.rb', line 47

def list(**options)
  @client.get("/v2/conversations", params: options)
end