Class: Vapi::AsyncCallsClient

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_client:) ⇒ Vapi::AsyncCallsClient

Parameters:



492
493
494
# File 'lib/vapi_server_sdk/calls/client.rb', line 492

def initialize(request_client:)
  @request_client = request_client
end

Instance Attribute Details

#request_clientVapi::AsyncRequestClient (readonly)



488
489
490
# File 'lib/vapi_server_sdk/calls/client.rb', line 488

def request_client
  @request_client
end

Instance Method Details

#create(name: nil, assistant_id: nil, assistant: nil, assistant_overrides: nil, squad_id: nil, squad: nil, phone_number_id: nil, phone_number: nil, customer_id: nil, customer: nil, request_options: nil) ⇒ Vapi::Call

Examples:

api = Vapi::Client.new(
  base_url: "https://api.example.com",
  environment: Vapi::Environment::DEFAULT,
  token: "YOUR_AUTH_TOKEN"
)
api.calls.create

Parameters:

  • name (String) (defaults to: nil)

    This is the name of the call. This is just for your own reference.

  • assistant_id (String) (defaults to: nil)

    This is the assistant that will be used for the call. To use a transient assistant, use ‘assistant` instead.

  • assistant (Hash) (defaults to: nil)

    This is the assistant that will be used for the call. To use an existing assistant, use ‘assistantId` instead.Request of type Vapi::CreateAssistantDto, as a Hash

    * :transcriber (Hash)
    * :model (Hash)
    * :voice (Hash)
    * :first_message_mode (Vapi::CreateAssistantDtoFirstMessageMode)
    * :hipaa_enabled (Boolean)
    * :client_messages (Array<Vapi::CreateAssistantDtoClientMessagesItem>)
    * :server_messages (Array<Vapi::CreateAssistantDtoServerMessagesItem>)
    * :silence_timeout_seconds (Float)
    * :max_duration_seconds (Float)
    * :background_sound (Vapi::CreateAssistantDtoBackgroundSound)
    * :backchanneling_enabled (Boolean)
    * :background_denoising_enabled (Boolean)
    * :model_output_in_messages_enabled (Boolean)
    * :transport_configurations (Array<Vapi::TransportConfigurationTwilio>)
    * :name (String)
    * :first_message (String)
    * :voicemail_detection (Hash)
      * :provider (String)
      * :voicemail_detection_types (Array<Vapi::TwilioVoicemailDetectionVoicemailDetectionTypesItem>)
      * :enabled (Boolean)
      * :machine_detection_timeout (Float)
      * :machine_detection_speech_threshold (Float)
      * :machine_detection_speech_end_threshold (Float)
      * :machine_detection_silence_timeout (Float)
    * :voicemail_message (String)
    * :end_call_message (String)
    * :end_call_phrases (Array<String>)
    * :metadata (Hash{String => Object})
    * :server_url (String)
    * :server_url_secret (String)
    * :analysis_plan (Hash)
      * :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)
          * :required (Array<String>)
        * :timeout_seconds (Float)
      * :success_evaluation_plan (Hash)
        * :rubric (Vapi::SuccessEvaluationPlanRubric)
        * :messages (Array<Hash{String => Object}>)
        * :enabled (Boolean)
        * :timeout_seconds (Float)
    * :artifact_plan (Hash)
      * :recording_enabled (Boolean)
      * :video_recording_enabled (Boolean)
      * :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_timeout_seconds (Float)
    * :start_speaking_plan (Hash)
      * :wait_seconds (Float)
      * :smart_endpointing_enabled (Boolean)
      * :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)
    * :monitor_plan (Hash)
      * :listen_enabled (Boolean)
      * :control_enabled (Boolean)
    * :credential_ids (Array<String>)
    
  • assistant_overrides (Hash) (defaults to: nil)

    These are the overrides for the ‘assistant` or `assistantId`’s settings and template variables.Request of type Vapi::AssistantOverrides, as a Hash

    * :transcriber (Hash)
    * :model (Hash)
    * :voice (Hash)
    * :first_message_mode (Vapi::AssistantOverridesFirstMessageMode)
    * :hipaa_enabled (Boolean)
    * :client_messages (Array<Vapi::AssistantOverridesClientMessagesItem>)
    * :server_messages (Array<Vapi::AssistantOverridesServerMessagesItem>)
    * :silence_timeout_seconds (Float)
    * :max_duration_seconds (Float)
    * :background_sound (Vapi::AssistantOverridesBackgroundSound)
    * :backchanneling_enabled (Boolean)
    * :background_denoising_enabled (Boolean)
    * :model_output_in_messages_enabled (Boolean)
    * :transport_configurations (Array<Vapi::TransportConfigurationTwilio>)
    * :variable_values (Hash{String => Object})
    * :name (String)
    * :first_message (String)
    * :voicemail_detection (Hash)
      * :provider (String)
      * :voicemail_detection_types (Array<Vapi::TwilioVoicemailDetectionVoicemailDetectionTypesItem>)
      * :enabled (Boolean)
      * :machine_detection_timeout (Float)
      * :machine_detection_speech_threshold (Float)
      * :machine_detection_speech_end_threshold (Float)
      * :machine_detection_silence_timeout (Float)
    * :voicemail_message (String)
    * :end_call_message (String)
    * :end_call_phrases (Array<String>)
    * :metadata (Hash{String => Object})
    * :server_url (String)
    * :server_url_secret (String)
    * :analysis_plan (Hash)
      * :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)
          * :required (Array<String>)
        * :timeout_seconds (Float)
      * :success_evaluation_plan (Hash)
        * :rubric (Vapi::SuccessEvaluationPlanRubric)
        * :messages (Array<Hash{String => Object}>)
        * :enabled (Boolean)
        * :timeout_seconds (Float)
    * :artifact_plan (Hash)
      * :recording_enabled (Boolean)
      * :video_recording_enabled (Boolean)
      * :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_timeout_seconds (Float)
    * :start_speaking_plan (Hash)
      * :wait_seconds (Float)
      * :smart_endpointing_enabled (Boolean)
      * :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)
    * :monitor_plan (Hash)
      * :listen_enabled (Boolean)
      * :control_enabled (Boolean)
    * :credential_ids (Array<String>)
    
  • squad_id (String) (defaults to: nil)

    This is the squad that will be used for the call. To use a transient squad, use ‘squad` instead.

  • squad (Hash) (defaults to: nil)

    This is a squad that will be used for the call. To use an existing squad, use ‘squadId` instead.Request of type Vapi::CreateSquadDto, as a Hash

    * :name (String)
    * :members (Array<Vapi::SquadMemberDto>)
    * :members_overrides (Hash)
      * :transcriber (Hash)
      * :model (Hash)
      * :voice (Hash)
      * :first_message_mode (Vapi::AssistantOverridesFirstMessageMode)
      * :hipaa_enabled (Boolean)
      * :client_messages (Array<Vapi::AssistantOverridesClientMessagesItem>)
      * :server_messages (Array<Vapi::AssistantOverridesServerMessagesItem>)
      * :silence_timeout_seconds (Float)
      * :max_duration_seconds (Float)
      * :background_sound (Vapi::AssistantOverridesBackgroundSound)
      * :backchanneling_enabled (Boolean)
      * :background_denoising_enabled (Boolean)
      * :model_output_in_messages_enabled (Boolean)
      * :transport_configurations (Array<Vapi::TransportConfigurationTwilio>)
      * :variable_values (Hash{String => Object})
      * :name (String)
      * :first_message (String)
      * :voicemail_detection (Hash)
        * :provider (String)
        * :voicemail_detection_types (Array<Vapi::TwilioVoicemailDetectionVoicemailDetectionTypesItem>)
        * :enabled (Boolean)
        * :machine_detection_timeout (Float)
        * :machine_detection_speech_threshold (Float)
        * :machine_detection_speech_end_threshold (Float)
        * :machine_detection_silence_timeout (Float)
      * :voicemail_message (String)
      * :end_call_message (String)
      * :end_call_phrases (Array<String>)
      * :metadata (Hash{String => Object})
      * :server_url (String)
      * :server_url_secret (String)
      * :analysis_plan (Hash)
        * :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)
            * :required (Array<String>)
          * :timeout_seconds (Float)
        * :success_evaluation_plan (Hash)
          * :rubric (Vapi::SuccessEvaluationPlanRubric)
          * :messages (Array<Hash{String => Object}>)
          * :enabled (Boolean)
          * :timeout_seconds (Float)
      * :artifact_plan (Hash)
        * :recording_enabled (Boolean)
        * :video_recording_enabled (Boolean)
        * :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_timeout_seconds (Float)
      * :start_speaking_plan (Hash)
        * :wait_seconds (Float)
        * :smart_endpointing_enabled (Boolean)
        * :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)
      * :monitor_plan (Hash)
        * :listen_enabled (Boolean)
        * :control_enabled (Boolean)
      * :credential_ids (Array<String>)
    
  • phone_number_id (String) (defaults to: nil)

    This is the phone number that will be used for the call. To use a transient number, use ‘phoneNumber` instead. Only relevant for `outboundPhoneCall` and `inboundPhoneCall` type.

  • phone_number (Hash) (defaults to: nil)

    This is the phone number that will be used for the call. To use an existing number, use ‘phoneNumberId` instead. Only relevant for `outboundPhoneCall` and `inboundPhoneCall` type.Request of type Vapi::ImportTwilioPhoneNumberDto, as a Hash

    * :fallback_destination (Hash)
    * :twilio_phone_number (String)
    * :twilio_account_sid (String)
    * :twilio_auth_token (String)
    * :name (String)
    * :assistant_id (String)
    * :squad_id (String)
    * :server_url (String)
    * :server_url_secret (String)
    
  • customer_id (String) (defaults to: nil)

    This is the customer that will be called. To call a transient customer , use ‘customer` instead. Only relevant for `outboundPhoneCall` and `inboundPhoneCall` type.

  • customer (Hash) (defaults to: nil)

    This is the customer that will be called. To call an existing customer, use ‘customerId` instead. Only relevant for `outboundPhoneCall` and `inboundPhoneCall` type.Request of type Vapi::CreateCustomerDto, as a Hash

    * :number_e_164_check_enabled (Boolean)
    * :extension (String)
    * :number (String)
    * :sip_uri (String)
    * :name (String)
    
  • request_options (Vapi::RequestOptions) (defaults to: nil)

Returns:



838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
# File 'lib/vapi_server_sdk/calls/client.rb', line 838

def create(name: nil, assistant_id: nil, assistant: nil, assistant_overrides: nil, squad_id: nil, squad: nil,
           phone_number_id: nil, phone_number: nil, customer_id: nil, customer: nil, request_options: nil)
  Async do
    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,
        assistantId: assistant_id,
        assistant: assistant,
        assistantOverrides: assistant_overrides,
        squadId: squad_id,
        squad: squad,
        phoneNumberId: phone_number_id,
        phoneNumber: phone_number,
        customerId: customer_id,
        customer: customer
      }.compact
      req.url "#{@request_client.get_url(request_options: request_options)}/call"
    end
    Vapi::Call.from_json(json_object: response.body)
  end
end

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

Examples:

api = Vapi::Client.new(
  base_url: "https://api.example.com",
  environment: Vapi::Environment::DEFAULT,
  token: "YOUR_AUTH_TOKEN"
)
api.calls.delete(id: "id")

Parameters:

Returns:



913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
# File 'lib/vapi_server_sdk/calls/client.rb', line 913

def delete(id:, request_options: nil)
  Async do
    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)}/call/#{id}"
    end
    Vapi::Call.from_json(json_object: response.body)
  end
end

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

Examples:

api = Vapi::Client.new(
  base_url: "https://api.example.com",
  environment: Vapi::Environment::DEFAULT,
  token: "YOUR_AUTH_TOKEN"
)
api.calls.get(id: "id")

Parameters:

Returns:



881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
# File 'lib/vapi_server_sdk/calls/client.rb', line 881

def get(id:, request_options: nil)
  Async do
    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)}/call/#{id}"
    end
    Vapi::Call.from_json(json_object: response.body)
  end
end

#list(assistant_id: 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) ⇒ Array<Vapi::Call>

Examples:

api = Vapi::Client.new(
  base_url: "https://api.example.com",
  environment: Vapi::Environment::DEFAULT,
  token: "YOUR_AUTH_TOKEN"
)
api.calls.list

Parameters:

  • assistant_id (String) (defaults to: nil)

    This will return calls with the specified assistantId.

  • 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:



519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
# File 'lib/vapi_server_sdk/calls/client.rb', line 519

def list(assistant_id: 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)
  Async do
    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 || {}),
        "assistantId": assistant_id,
        "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)}/call"
    end
    parsed_json = JSON.parse(response.body)
    parsed_json&.map do |item|
      item = item.to_json
      Vapi::Call.from_json(json_object: item)
    end
  end
end

#update(id:, name: nil, request_options: nil) ⇒ Vapi::Call

Examples:

api = Vapi::Client.new(
  base_url: "https://api.example.com",
  environment: Vapi::Environment::DEFAULT,
  token: "YOUR_AUTH_TOKEN"
)
api.calls.update(id: "id")

Parameters:

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

    This is the name of the call. This is just for your own reference.

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

Returns:



946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
# File 'lib/vapi_server_sdk/calls/client.rb', line 946

def update(id:, name: nil, request_options: nil)
  Async do
    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 }.compact
      req.url "#{@request_client.get_url(request_options: request_options)}/call/#{id}"
    end
    Vapi::Call.from_json(json_object: response.body)
  end
end