Class: Vapi::SessionsClient

Inherits:
Object
  • Object
show all
Defined in:
lib/vapi_server_sdk/sessions/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_client:) ⇒ Vapi::SessionsClient

Parameters:



24
25
26
# File 'lib/vapi_server_sdk/sessions/client.rb', line 24

def initialize(request_client:)
  @request_client = request_client
end

Instance Attribute Details

#request_clientVapi::RequestClient (readonly)

Returns:



20
21
22
# File 'lib/vapi_server_sdk/sessions/client.rb', line 20

def request_client
  @request_client
end

Instance Method Details

#create(name: nil, status: nil, expiration_seconds: nil, assistant_id: nil, assistant: nil, messages: nil, customer: nil, phone_number_id: nil, phone_number: nil, request_options: nil) ⇒ Vapi::Session

Parameters:

  • name (String) (defaults to: nil)

    This is a user-defined name for the session. Maximum length is 40 characters.

  • status (Vapi::Sessions::CreateSessionDtoStatus) (defaults to: nil)

    This is the current status of the session. Can be either ‘active’ or ‘completed’.

  • expiration_seconds (Float) (defaults to: nil)

    Session expiration time in seconds. Defaults to 24 hours (86400 seconds) if not set.

  • assistant_id (String) (defaults to: nil)

    This is the ID of the assistant associated with this session. Use this when referencing an existing assistant.

  • assistant (Hash) (defaults to: nil)

    This is the assistant configuration for this session. Use this when creating a new assistant configuration. If assistantId is provided, this will be ignored.Request of type Vapi::CreateAssistantDto, as a Hash

    * :transcriber (Hash)
    * :model (Hash)
    * :voice (Hash)
    * :first_message (String)
    * :first_message_interruptions_enabled (Boolean)
    * :first_message_mode (Vapi::CreateAssistantDtoFirstMessageMode)
    * :voicemail_detection (Hash)
    * :client_messages (Array<Vapi::CreateAssistantDtoClientMessagesItem>)
    * :server_messages (Array<Vapi::CreateAssistantDtoServerMessagesItem>)
    * :silence_timeout_seconds (Float)
    * :max_duration_seconds (Float)
    * :background_sound (Hash)
    * :background_denoising_enabled (Boolean)
    * :model_output_in_messages_enabled (Boolean)
    * :transport_configurations (Array<Vapi::TransportConfigurationTwilio>)
    * :observability_plan (Hash)
      * :provider (String)
      * :tags (Array<String>)
      * :metadata (Hash{String => Object})
    * :credentials (Array<Vapi::CreateAssistantDtoCredentialsItem>)
    * :hooks (Array<Vapi::CreateAssistantDtoHooksItem>)
    * :name (String)
    * :voicemail_message (String)
    * :end_call_message (String)
    * :end_call_phrases (Array<String>)
    * :compliance_plan (Hash)
      * :hipaa_enabled (Boolean)
      * :pci_enabled (Boolean)
    * :metadata (Hash{String => Object})
    * :background_speech_denoising_plan (Hash)
      * :smart_denoising_plan (Hash)
        * :enabled (Boolean)
      * :fourier_denoising_plan (Hash)
        * :enabled (Boolean)
        * :media_detection_enabled (Boolean)
        * :static_threshold (Float)
        * :baseline_offset_db (Float)
        * :window_size_ms (Float)
        * :baseline_percentile (Float)
    * :analysis_plan (Hash)
      * :min_messages_threshold (Float)
      * :summary_plan (Hash)
        * :messages (Array<Hash{String => Object}>)
        * :enabled (Boolean)
        * :timeout_seconds (Float)
      * :structured_data_plan (Hash)
        * :messages (Array<Hash{String => Object}>)
        * :enabled (Boolean)
        * :schema (Hash)
          * :type (Vapi::JsonSchemaType)
          * :items (Hash{String => Object})
          * :properties (Hash{String => Object})
          * :description (String)
          * :pattern (String)
          * :format (Vapi::JsonSchemaFormat)
          * :required (Array<String>)
          * :enum (Array<String>)
          * :title (String)
        * :timeout_seconds (Float)
      * :structured_data_multi_plan (Array<Vapi::StructuredDataMultiPlan>)
      * :success_evaluation_plan (Hash)
        * :rubric (Vapi::SuccessEvaluationPlanRubric)
        * :messages (Array<Hash{String => Object}>)
        * :enabled (Boolean)
        * :timeout_seconds (Float)
    * :artifact_plan (Hash)
      * :recording_enabled (Boolean)
      * :recording_format (Vapi::ArtifactPlanRecordingFormat)
      * :video_recording_enabled (Boolean)
      * :pcap_enabled (Boolean)
      * :pcap_s_3_path_prefix (String)
      * :transcript_plan (Hash)
        * :enabled (Boolean)
        * :assistant_name (String)
        * :user_name (String)
      * :recording_path (String)
    * :message_plan (Hash)
      * :idle_messages (Array<String>)
      * :idle_message_max_spoken_count (Float)
      * :idle_message_reset_count_on_user_speech_enabled (Boolean)
      * :idle_timeout_seconds (Float)
      * :silence_timeout_message (String)
    * :start_speaking_plan (Hash)
      * :wait_seconds (Float)
      * :smart_endpointing_enabled (Hash)
      * :smart_endpointing_plan (Hash)
      * :custom_endpointing_rules (Array<Vapi::StartSpeakingPlanCustomEndpointingRulesItem>)
      * :transcription_endpointing_plan (Hash)
        * :on_punctuation_seconds (Float)
        * :on_no_punctuation_seconds (Float)
        * :on_number_seconds (Float)
    * :stop_speaking_plan (Hash)
      * :num_words (Float)
      * :voice_seconds (Float)
      * :backoff_seconds (Float)
      * :acknowledgement_phrases (Array<String>)
      * :interruption_phrases (Array<String>)
    * :monitor_plan (Hash)
      * :listen_enabled (Boolean)
      * :listen_authentication_enabled (Boolean)
      * :control_enabled (Boolean)
      * :control_authentication_enabled (Boolean)
    * :credential_ids (Array<String>)
    * :server (Hash)
      * :timeout_seconds (Float)
      * :url (String)
      * :headers (Hash{String => Object})
      * :backoff_plan (Hash)
        * :type (Hash{String => Object})
        * :max_retries (Float)
        * :base_delay_seconds (Float)
    * :keypad_input_plan (Hash)
      * :enabled (Boolean)
      * :timeout_seconds (Float)
      * :delimiters (Vapi::KeypadInputPlanDelimiters)
    
  • messages (Array<Hash>) (defaults to: nil)

    This is an array of chat messages in the session.Request of type Array<Vapi::Sessions::CreateSessionDtoMessagesItem>, as a Hash

  • customer (Hash) (defaults to: nil)

    This is the customer information associated with this session.Request of type Vapi::CreateCustomerDto, as a Hash

    • :number_e_164_check_enabled (Boolean)

    • :extension (String)

    • :assistant_overrides (Hash)

      • :transcriber (Hash)

      • :model (Hash)

      • :voice (Hash)

      • :first_message (String)

      • :first_message_interruptions_enabled (Boolean)

      • :first_message_mode (Vapi::AssistantOverridesFirstMessageMode)

      • :voicemail_detection (Hash)

      • :client_messages (Array<Vapi::AssistantOverridesClientMessagesItem>)

      • :server_messages (Array<Vapi::AssistantOverridesServerMessagesItem>)

      • :silence_timeout_seconds (Float)

      • :max_duration_seconds (Float)

      • :background_sound (Hash)

      • :background_denoising_enabled (Boolean)

      • :model_output_in_messages_enabled (Boolean)

      • :transport_configurations (Array<Vapi::TransportConfigurationTwilio>)

      • :observability_plan (Hash)

        • :provider (String)

        • :tags (Array<String>)

        • :metadata (Hash=> Object)

      • :credentials (Array<Vapi::AssistantOverridesCredentialsItem>)

      • :hooks (Array<Vapi::AssistantOverridesHooksItem>)

      • :variable_values (Hash=> Object)

      • :name (String)

      • :voicemail_message (String)

      • :end_call_message (String)

      • :end_call_phrases (Array<String>)

      • :compliance_plan (Hash)

        • :hipaa_enabled (Boolean)

        • :pci_enabled (Boolean)

      • :metadata (Hash=> Object)

      • :background_speech_denoising_plan (Hash)

        • :smart_denoising_plan (Hash)

          • :enabled (Boolean)

        • :fourier_denoising_plan (Hash)

          • :enabled (Boolean)

          • :media_detection_enabled (Boolean)

          • :static_threshold (Float)

          • :baseline_offset_db (Float)

          • :window_size_ms (Float)

          • :baseline_percentile (Float)

      • :analysis_plan (Hash)

        • :min_messages_threshold (Float)

        • :summary_plan (Hash)

          • :messages (Array<Hash=> Object>)

          • :enabled (Boolean)

          • :timeout_seconds (Float)

        • :structured_data_plan (Hash)

          • :messages (Array<Hash=> Object>)

          • :enabled (Boolean)

          • :schema (Hash)

            • :type (Vapi::JsonSchemaType)

            • :items (Hash=> Object)

            • :properties (Hash=> Object)

            • :description (String)

            • :pattern (String)

            • :format (Vapi::JsonSchemaFormat)

            • :required (Array<String>)

            • :enum (Array<String>)

            • :title (String)

          • :timeout_seconds (Float)

        • :structured_data_multi_plan (Array<Vapi::StructuredDataMultiPlan>)

        • :success_evaluation_plan (Hash)

          • :rubric (Vapi::SuccessEvaluationPlanRubric)

          • :messages (Array<Hash=> Object>)

          • :enabled (Boolean)

          • :timeout_seconds (Float)

      • :artifact_plan (Hash)

        • :recording_enabled (Boolean)

        • :recording_format (Vapi::ArtifactPlanRecordingFormat)

        • :video_recording_enabled (Boolean)

        • :pcap_enabled (Boolean)

        • :pcap_s_3_path_prefix (String)

        • :transcript_plan (Hash)

          • :enabled (Boolean)

          • :assistant_name (String)

          • :user_name (String)

        • :recording_path (String)

      • :message_plan (Hash)

        • :idle_messages (Array<String>)

        • :idle_message_max_spoken_count (Float)

        • :idle_message_reset_count_on_user_speech_enabled (Boolean)

        • :idle_timeout_seconds (Float)

        • :silence_timeout_message (String)

      • :start_speaking_plan (Hash)

        • :wait_seconds (Float)

        • :smart_endpointing_enabled (Hash)

        • :smart_endpointing_plan (Hash)

        • :custom_endpointing_rules (Array<Vapi::StartSpeakingPlanCustomEndpointingRulesItem>)

        • :transcription_endpointing_plan (Hash)

          • :on_punctuation_seconds (Float)

          • :on_no_punctuation_seconds (Float)

          • :on_number_seconds (Float)

      • :stop_speaking_plan (Hash)

        • :num_words (Float)

        • :voice_seconds (Float)

        • :backoff_seconds (Float)

        • :acknowledgement_phrases (Array<String>)

        • :interruption_phrases (Array<String>)

      • :monitor_plan (Hash)

        • :listen_enabled (Boolean)

        • :listen_authentication_enabled (Boolean)

        • :control_enabled (Boolean)

        • :control_authentication_enabled (Boolean)

      • :credential_ids (Array<String>)

      • :server (Hash)

        • :timeout_seconds (Float)

        • :url (String)

        • :headers (Hash=> Object)

        • :backoff_plan (Hash)

          • :type (Hash=> Object)

          • :max_retries (Float)

          • :base_delay_seconds (Float)

      • :keypad_input_plan (Hash)

        • :enabled (Boolean)

        • :timeout_seconds (Float)

        • :delimiters (Vapi::KeypadInputPlanDelimiters)

    • :number (String)

    • :sip_uri (String)

    • :name (String)

    • :email (String)

    • :external_id (String)

  • phone_number_id (String) (defaults to: nil)

    This is the ID of the phone number associated with this session.

  • phone_number (Hash) (defaults to: nil)

    This is the phone number configuration for this session.Request of type Vapi::ImportTwilioPhoneNumberDto, as a Hash

    • :fallback_destination (Hash)

    • :hooks (Array<Vapi::PhoneNumberHookCallRinging>)

    • :sms_enabled (Boolean)

    • :twilio_phone_number (String)

    • :twilio_account_sid (String)

    • :twilio_auth_token (String)

    • :twilio_api_key (String)

    • :twilio_api_secret (String)

    • :name (String)

    • :assistant_id (String)

    • :workflow_id (String)

    • :squad_id (String)

    • :server (Hash)

      • :timeout_seconds (Float)

      • :url (String)

      • :headers (Hash=> Object)

      • :backoff_plan (Hash)

        • :type (Hash=> Object)

        • :max_retries (Float)

        • :base_delay_seconds (Float)

  • request_options (Vapi::RequestOptions) (defaults to: nil)

Returns:



358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
# File 'lib/vapi_server_sdk/sessions/client.rb', line 358

def create(name: nil, status: nil, expiration_seconds: nil, assistant_id: nil, assistant: nil, messages: nil,
           customer: nil, phone_number_id: nil, phone_number: nil, request_options: nil)
  response = @request_client.conn.post do |req|
    req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
    req.headers["Authorization"] = request_options.token unless request_options&.token.nil?
    req.headers = {
  **(req.headers || {}),
  **@request_client.get_headers,
  **(request_options&.additional_headers || {})
    }.compact
    unless request_options.nil? || request_options&.additional_query_parameters.nil?
      req.params = { **(request_options&.additional_query_parameters || {}) }.compact
    end
    req.body = {
      **(request_options&.additional_body_parameters || {}),
      name: name,
      status: status,
      expirationSeconds: expiration_seconds,
      assistantId: assistant_id,
      assistant: assistant,
      messages: messages,
      customer: customer,
      phoneNumberId: phone_number_id,
      phoneNumber: phone_number
    }.compact
    req.url "#{@request_client.get_url(request_options: request_options)}/session"
  end
  Vapi::Session.from_json(json_object: response.body)
end

#delete(id:, request_options: nil) ⇒ Vapi::Session

Parameters:

Returns:



414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
# File 'lib/vapi_server_sdk/sessions/client.rb', line 414

def delete(id:, request_options: nil)
  response = @request_client.conn.delete do |req|
    req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
    req.headers["Authorization"] = request_options.token unless request_options&.token.nil?
    req.headers = {
  **(req.headers || {}),
  **@request_client.get_headers,
  **(request_options&.additional_headers || {})
    }.compact
    unless request_options.nil? || request_options&.additional_query_parameters.nil?
      req.params = { **(request_options&.additional_query_parameters || {}) }.compact
    end
    unless request_options.nil? || request_options&.additional_body_parameters.nil?
      req.body = { **(request_options&.additional_body_parameters || {}) }.compact
    end
    req.url "#{@request_client.get_url(request_options: request_options)}/session/#{id}"
  end
  Vapi::Session.from_json(json_object: response.body)
end

#get(id:, request_options: nil) ⇒ Vapi::Session

Parameters:

Returns:



391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
# File 'lib/vapi_server_sdk/sessions/client.rb', line 391

def get(id:, request_options: nil)
  response = @request_client.conn.get do |req|
    req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
    req.headers["Authorization"] = request_options.token unless request_options&.token.nil?
    req.headers = {
  **(req.headers || {}),
  **@request_client.get_headers,
  **(request_options&.additional_headers || {})
    }.compact
    unless request_options.nil? || request_options&.additional_query_parameters.nil?
      req.params = { **(request_options&.additional_query_parameters || {}) }.compact
    end
    unless request_options.nil? || request_options&.additional_body_parameters.nil?
      req.body = { **(request_options&.additional_body_parameters || {}) }.compact
    end
    req.url "#{@request_client.get_url(request_options: request_options)}/session/#{id}"
  end
  Vapi::Session.from_json(json_object: response.body)
end

#list(name: nil, assistant_id: nil, workflow_id: nil, page: nil, sort_order: nil, limit: nil, created_at_gt: nil, created_at_lt: nil, created_at_ge: nil, created_at_le: nil, updated_at_gt: nil, updated_at_lt: nil, updated_at_ge: nil, updated_at_le: nil, request_options: nil) ⇒ Vapi::SessionPaginatedResponse

Parameters:

  • name (String) (defaults to: nil)

    This is the name of the session to filter by.

  • assistant_id (String) (defaults to: nil)

    This is the ID of the assistant to filter sessions by.

  • workflow_id (String) (defaults to: nil)

    This is the ID of the workflow to filter sessions by.

  • page (Float) (defaults to: nil)

    This is the page number to return. Defaults to 1.

  • sort_order (Vapi::Sessions::SessionsListRequestSortOrder) (defaults to: nil)

    This is the sort order for pagination. Defaults to ‘DESC’.

  • limit (Float) (defaults to: nil)

    This is the maximum number of items to return. Defaults to 100.

  • created_at_gt (DateTime) (defaults to: nil)

    This will return items where the createdAt is greater than the specified value.

  • created_at_lt (DateTime) (defaults to: nil)

    This will return items where the createdAt is less than the specified value.

  • created_at_ge (DateTime) (defaults to: nil)

    This will return items where the createdAt is greater than or equal to the specified value.

  • created_at_le (DateTime) (defaults to: nil)

    This will return items where the createdAt is less than or equal to the specified value.

  • updated_at_gt (DateTime) (defaults to: nil)

    This will return items where the updatedAt is greater than the specified value.

  • updated_at_lt (DateTime) (defaults to: nil)

    This will return items where the updatedAt is less than the specified value.

  • updated_at_ge (DateTime) (defaults to: nil)

    This will return items where the updatedAt is greater than or equal to the specified value.

  • updated_at_le (DateTime) (defaults to: nil)

    This will return items where the updatedAt is less than or equal to the specified value.

  • request_options (Vapi::RequestOptions) (defaults to: nil)

Returns:



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/vapi_server_sdk/sessions/client.rb', line 48

def list(name: nil, assistant_id: nil, workflow_id: nil, page: nil, sort_order: nil, limit: nil,
         created_at_gt: nil, created_at_lt: nil, created_at_ge: nil, created_at_le: nil, updated_at_gt: nil, updated_at_lt: nil, updated_at_ge: nil, updated_at_le: nil, request_options: nil)
  response = @request_client.conn.get do |req|
    req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
    req.headers["Authorization"] = request_options.token unless request_options&.token.nil?
    req.headers = {
  **(req.headers || {}),
  **@request_client.get_headers,
  **(request_options&.additional_headers || {})
    }.compact
    req.params = {
      **(request_options&.additional_query_parameters || {}),
      "name": name,
      "assistantId": assistant_id,
      "workflowId": workflow_id,
      "page": page,
      "sortOrder": sort_order,
      "limit": limit,
      "createdAtGt": created_at_gt,
      "createdAtLt": created_at_lt,
      "createdAtGe": created_at_ge,
      "createdAtLe": created_at_le,
      "updatedAtGt": updated_at_gt,
      "updatedAtLt": updated_at_lt,
      "updatedAtGe": updated_at_ge,
      "updatedAtLe": updated_at_le
    }.compact
    unless request_options.nil? || request_options&.additional_body_parameters.nil?
      req.body = { **(request_options&.additional_body_parameters || {}) }.compact
    end
    req.url "#{@request_client.get_url(request_options: request_options)}/session"
  end
  Vapi::SessionPaginatedResponse.from_json(json_object: response.body)
end

#update(id:, name: nil, status: nil, expiration_seconds: nil, messages: nil, request_options: nil) ⇒ Vapi::Session

Parameters:

  • id (String)
  • name (String) (defaults to: nil)

    This is the new name for the session. Maximum length is 40 characters.

  • status (Vapi::Sessions::UpdateSessionDtoStatus) (defaults to: nil)

    This is the new status for the session.

  • expiration_seconds (Float) (defaults to: nil)

    Session expiration time in seconds. Defaults to 24 hours (86400 seconds) if not set.

  • messages (Array<Hash>) (defaults to: nil)

    This is the updated array of chat messages.Request of type Array<Vapi::Sessions::UpdateSessionDtoMessagesItem>, as a Hash

  • request_options (Vapi::RequestOptions) (defaults to: nil)

Returns:



442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
# File 'lib/vapi_server_sdk/sessions/client.rb', line 442

def update(id:, name: nil, status: nil, expiration_seconds: nil, messages: nil, request_options: nil)
  response = @request_client.conn.patch do |req|
    req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
    req.headers["Authorization"] = request_options.token unless request_options&.token.nil?
    req.headers = {
  **(req.headers || {}),
  **@request_client.get_headers,
  **(request_options&.additional_headers || {})
    }.compact
    unless request_options.nil? || request_options&.additional_query_parameters.nil?
      req.params = { **(request_options&.additional_query_parameters || {}) }.compact
    end
    req.body = {
      **(request_options&.additional_body_parameters || {}),
      name: name,
      status: status,
      expirationSeconds: expiration_seconds,
      messages: messages
    }.compact
    req.url "#{@request_client.get_url(request_options: request_options)}/session/#{id}"
  end
  Vapi::Session.from_json(json_object: response.body)
end