Class: Vapi::WorkflowClient

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_client:) ⇒ Vapi::WorkflowClient

Parameters:



31
32
33
# File 'lib/vapi_server_sdk/workflow/client.rb', line 31

def initialize(request_client:)
  @request_client = request_client
end

Instance Attribute Details

#request_clientVapi::RequestClient (readonly)

Returns:



27
28
29
# File 'lib/vapi_server_sdk/workflow/client.rb', line 27

def request_client
  @request_client
end

Instance Method Details

#workflow_controller_create(request:, request_options: nil) ⇒ Vapi::Workflow

Parameters:

  • request (Hash)

    Request of type Vapi::CreateWorkflowDto, as a Hash

    • :nodes (Array<Vapi::CreateWorkflowDtoNodesItem>)

    • :transcriber (Hash)

    • :voice (Hash)

    • :observability_plan (Hash)

      • :provider (String)

      • :tags (Array<String>)

      • :metadata (Hash=> Object)

    • :background_sound (Hash)

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

    • :name (String)

    • :edges (Array<Vapi::Edge>)

    • :global_prompt (String)

    • :server (Hash)

      • :timeout_seconds (Float)

      • :url (String)

      • :headers (Hash=> Object)

      • :backoff_plan (Hash)

        • :type (Hash=> Object)

        • :max_retries (Float)

        • :base_delay_seconds (Float)

    • :compliance_plan (Hash)

      • :hipaa_enabled (Boolean)

      • :pci_enabled (Boolean)

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

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

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

    • :credential_ids (Array<String>)

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

Returns:



155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/vapi_server_sdk/workflow/client.rb', line 155

def workflow_controller_create(request:, 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 || {}), **(request_options&.additional_body_parameters || {}) }.compact
    req.url "#{@request_client.get_url(request_options: request_options)}/workflow"
  end
  Vapi::Workflow.from_json(json_object: response.body)
end

#workflow_controller_delete(id:, request_options: nil) ⇒ Vapi::Workflow

Parameters:

Returns:



199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/vapi_server_sdk/workflow/client.rb', line 199

def workflow_controller_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)}/workflow/#{id}"
  end
  Vapi::Workflow.from_json(json_object: response.body)
end

#workflow_controller_find_all(request_options: nil) ⇒ Array<Vapi::Workflow>

Parameters:

Returns:



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/vapi_server_sdk/workflow/client.rb', line 37

def workflow_controller_find_all(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)}/workflow"
  end
  parsed_json = JSON.parse(response.body)
  parsed_json&.map do |item|
    item = item.to_json
    Vapi::Workflow.from_json(json_object: item)
  end
end

#workflow_controller_find_one(id:, request_options: nil) ⇒ Vapi::Workflow

Parameters:

Returns:



176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/vapi_server_sdk/workflow/client.rb', line 176

def workflow_controller_find_one(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)}/workflow/#{id}"
  end
  Vapi::Workflow.from_json(json_object: response.body)
end

#workflow_controller_update(id:, nodes: nil, transcriber: nil, voice: nil, observability_plan: nil, background_sound: nil, credentials: nil, name: nil, edges: nil, global_prompt: nil, server: nil, compliance_plan: nil, analysis_plan: nil, artifact_plan: nil, start_speaking_plan: nil, stop_speaking_plan: nil, monitor_plan: nil, background_speech_denoising_plan: nil, credential_ids: nil, request_options: nil) ⇒ Vapi::Workflow

Parameters:

  • id (String)
  • nodes (Array<Hash>) (defaults to: nil)

    Request of type Array<Vapi::Workflow::UpdateWorkflowDtoNodesItem>, as a Hash

  • transcriber (Vapi::Workflow::UpdateWorkflowDtoTranscriber) (defaults to: nil)

    This is the transcriber for the workflow. This can be overridden at node level using ‘nodes.transcriber`.

  • voice (Vapi::Workflow::UpdateWorkflowDtoVoice) (defaults to: nil)

    This is the voice for the workflow. This can be overridden at node level using ‘nodes.voice`.

  • observability_plan (Hash) (defaults to: nil)

    This is the plan for observability of workflow’s calls. Currently, only Langfuse is supported.Request of type Vapi::LangfuseObservabilityPlan, as a Hash

    * :provider (String)
    * :tags (Array<String>)
    * :metadata (Hash{String => Object})
    
  • background_sound (Vapi::Workflow::UpdateWorkflowDtoBackgroundSoundZero, String) (defaults to: nil)

    This is the background sound in the call. Default for phone calls is ‘office’ and default for web calls is ‘off’. You can also provide a custom sound by providing a URL to an audio file.

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

    These are dynamic credentials that will be used for the workflow calls. By default, all the credentials are available for use in the call but you can supplement an additional credentials using this. Dynamic credentials override existing credentials.Request of type Array<Vapi::Workflow::UpdateWorkflowDtoCredentialsItem>, as a Hash

  • name (String) (defaults to: nil)
  • edges (Array<Hash>) (defaults to: nil)

    Request of type Array<Vapi::Edge>, as a Hash

    • :condition (Hash)

      • :type (String)

      • :prompt (String)

    • :from (String)

    • :to (String)

    • :metadata (Hash=> Object)

  • global_prompt (String) (defaults to: nil)
  • server (Hash) (defaults to: nil)

    This is where Vapi will send webhooks. You can find all webhooks available along with their shape in ServerMessage schema. The order of precedence is:

    1. tool.server

    2. workflow.server / assistant.server

    3. phoneNumber.server

    4. org.serverRequest of type Vapi::Server, as a Hash

    * :timeout_seconds (Float)
    * :url (String)
    * :headers (Hash{String => Object})
    * :backoff_plan (Hash)
      * :type (Hash{String => Object})
      * :max_retries (Float)
      * :base_delay_seconds (Float)
    
  • compliance_plan (Hash) (defaults to: nil)

    This is the compliance plan for the workflow. It allows you to configure HIPAA and other compliance settings.Request of type Vapi::CompliancePlan, as a Hash

    * :hipaa_enabled (Boolean)
    * :pci_enabled (Boolean)
    
  • analysis_plan (Hash) (defaults to: nil)

    This is the plan for analysis of workflow’s calls. Stored in ‘call.analysis`.Request of type Vapi::AnalysisPlan, as a 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) (defaults to: nil)

    This is the plan for artifacts generated during workflow’s calls. Stored in ‘call.artifact`.Request of type Vapi::ArtifactPlan, as a 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)
    
  • start_speaking_plan (Hash) (defaults to: nil)

    This is the plan for when the workflow nodes should start talking. You should configure this if you’re running into these issues:

    • The assistant is too slow to start talking after the customer is done

    speaking.

    • The assistant is too fast to start talking after the customer is done

    speaking.

    • The assistant is so fast that it’s actually interrupting the customer.Request of type Vapi::StartSpeakingPlan, as a 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) (defaults to: nil)

    This is the plan for when workflow nodes should stop talking on customer interruption. You should configure this if you’re running into these issues:

    • The assistant is too slow to recognize customer’s interruption.

    • The assistant is too fast to recognize customer’s interruption.

    • The assistant is getting interrupted by phrases that are just acknowledgments.

    • The assistant is getting interrupted by background noises.

    • The assistant is not properly stopping – it starts talking right after

    getting interrupted.Request of type Vapi::StopSpeakingPlan, as a Hash

    * :num_words (Float)
    * :voice_seconds (Float)
    * :backoff_seconds (Float)
    * :acknowledgement_phrases (Array<String>)
    * :interruption_phrases (Array<String>)
    
  • monitor_plan (Hash) (defaults to: nil)

    This is the plan for real-time monitoring of the workflow’s calls. Usage:

    • To enable live listening of the workflow’s calls, set

    ‘monitorPlan.listenEnabled` to `true`.

    • To enable live control of the workflow’s calls, set

    ‘monitorPlan.controlEnabled` to `true`.Request of type Vapi::MonitorPlan, as a Hash

    * :listen_enabled (Boolean)
    * :listen_authentication_enabled (Boolean)
    * :control_enabled (Boolean)
    * :control_authentication_enabled (Boolean)
    
  • background_speech_denoising_plan (Hash) (defaults to: nil)

    This enables filtering of noise and background speech while the user is talking. Features:

    • Smart denoising using Krisp

    • Fourier denoising

    Both can be used together. Order of precedence:

    • Smart denoising

    • Fourier denoisingRequest of type Vapi::BackgroundSpeechDenoisingPlan, as a 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)

  • credential_ids (Array<String>) (defaults to: nil)

    These are the credentials that will be used for the workflow calls. By default, all the credentials are available for use in the call but you can provide a subset using this.

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

Returns:



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
387
388
389
390
391
392
393
394
395
396
397
398
399
# File 'lib/vapi_server_sdk/workflow/client.rb', line 362

def workflow_controller_update(id:, nodes: nil, transcriber: nil, voice: nil, observability_plan: nil,
                               background_sound: nil, credentials: nil, name: nil, edges: nil, global_prompt: nil, server: nil, compliance_plan: nil, analysis_plan: nil, artifact_plan: nil, start_speaking_plan: nil, stop_speaking_plan: nil, monitor_plan: nil, background_speech_denoising_plan: nil, credential_ids: 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 || {}),
      nodes: nodes,
      transcriber: transcriber,
      voice: voice,
      observabilityPlan: observability_plan,
      backgroundSound: background_sound,
      credentials: credentials,
      name: name,
      edges: edges,
      globalPrompt: global_prompt,
      server: server,
      compliancePlan: compliance_plan,
      analysisPlan: analysis_plan,
      artifactPlan: artifact_plan,
      startSpeakingPlan: start_speaking_plan,
      stopSpeakingPlan: stop_speaking_plan,
      monitorPlan: monitor_plan,
      backgroundSpeechDenoisingPlan: background_speech_denoising_plan,
      credentialIds: credential_ids
    }.compact
    req.url "#{@request_client.get_url(request_options: request_options)}/workflow/#{id}"
  end
  Vapi::Workflow.from_json(json_object: response.body)
end