Class: Vapi::AsyncBlocksClient

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_client:) ⇒ Vapi::AsyncBlocksClient

Parameters:



287
288
289
# File 'lib/vapi_server_sdk/blocks/client.rb', line 287

def initialize(request_client:)
  @request_client = request_client
end

Instance Attribute Details

#request_clientVapi::AsyncRequestClient (readonly)



283
284
285
# File 'lib/vapi_server_sdk/blocks/client.rb', line 283

def request_client
  @request_client
end

Instance Method Details

#create(request:, request_options: nil) ⇒ Vapi::Blocks::BlocksCreateResponse

Examples:

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

Parameters:

Returns:



359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
# File 'lib/vapi_server_sdk/blocks/client.rb', line 359

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

#delete(id:, request_options: nil) ⇒ Vapi::Blocks::BlocksDeleteResponse

Examples:

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

Parameters:

Returns:



421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
# File 'lib/vapi_server_sdk/blocks/client.rb', line 421

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)}/block/#{id}"
    end
    Vapi::Blocks::BlocksDeleteResponse.from_json(json_object: response.body)
  end
end

#get(id:, request_options: nil) ⇒ Vapi::Blocks::BlocksGetResponse

Examples:

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

Parameters:

Returns:



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

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)}/block/#{id}"
    end
    Vapi::Blocks::BlocksGetResponse.from_json(json_object: response.body)
  end
end

#list(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::Blocks::BlocksListResponseItem>

Examples:

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

Parameters:

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



313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
# File 'lib/vapi_server_sdk/blocks/client.rb', line 313

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

#update(id:, messages: nil, input_schema: nil, output_schema: nil, tool: nil, steps: nil, name: nil, instruction: nil, tool_id: nil, request_options: nil) ⇒ Vapi::Blocks::BlocksUpdateResponse

Examples:

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

Parameters:

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

    These are the pre-configured messages that will be spoken to the user while the block is running.Request of type Array<Vapi::Blocks::UpdateBlockDtoMessagesItem>, as a Hash

  • input_schema (Hash) (defaults to: nil)

    This is the input schema for the block. This is the input the block needs to run. It’s given to the block as ‘steps.input` These are accessible as variables:

    • (Vapi::AsyncBlocksClient.{input{input.propertyName}) in context of the block execution (step)

    • (Vapi::AsyncBlocksClient.{stepName{stepName.input{stepName.input.propertyName}) in context of the workflowRequest of type Vapi::JsonSchema, as a Hash

    • :type (Vapi::JsonSchemaType)

    • :items (Hash=> Object)

    • :properties (Hash=> Object)

    • :description (String)

    • :required (Array<String>)

  • output_schema (Hash) (defaults to: nil)

    This is the output schema for the block. This is the output the block will return to the workflow (‘Vapi::AsyncBlocksClient.{stepName{stepName.output}`). These are accessible as variables:

    • (Vapi::AsyncBlocksClient.{output{output.propertyName}) in context of the block execution (step)

    • (Vapi::AsyncBlocksClient.{stepName{stepName.output{stepName.output.propertyName}) in context of the workflow (read caveat #1)

    • (Vapi::AsyncBlocksClient.{blockName{blockName.output{blockName.output.propertyName}) in context of the workflow (read caveat

    #2) Caveats:

    1. a workflow can execute a step multiple times. example, if a loop is used in

    the graph. Vapi::AsyncBlocksClient.{stepName{stepName.output{stepName.output.propertyName} will reference the latest usage of the step.

    1. a workflow can execute a block multiple times. example, if a step is called

    multiple times or if a block is used in multiple steps. Vapi::AsyncBlocksClient.{blockName{blockName.output{blockName.output.propertyName} will reference the latest usage of the block. this liquid variable is just provided for convenience when creating blocks outside of a workflow with steps.Request of type Vapi::JsonSchema, as a Hash

    * :type (Vapi::JsonSchemaType)
    * :items (Hash{String => Object})
    * :properties (Hash{String => Object})
    * :description (String)
    * :required (Array<String>)
    
  • tool (Vapi::Blocks::UpdateBlockDtoTool) (defaults to: nil)

    This is the tool that the block will call. To use an existing tool, use ‘toolId`.

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

    These are the steps in the workflow.Request of type Array<Vapi::Blocks::UpdateBlockDtoStepsItem>, as a Hash

  • name (String) (defaults to: nil)

    This is the name of the block. This is just for your reference.

  • instruction (String) (defaults to: nil)

    This is the instruction to the model. You can reference any variable in the context of the current block execution (step):

    • “Vapi::AsyncBlocksClient.{input{input.your-property-name}” for the current step’s input

    • “Vapi::AsyncBlocksClient.{your-step-name{your-step-name.output{your-step-name.output.your-property-name}” for another step’s output (in

    the same workflow; read caveat #1)

    • “Vapi::AsyncBlocksClient.{your-step-name{your-step-name.input{your-step-name.input.your-property-name}” for another step’s input (in the

    same workflow; read caveat #1)

    • “Vapi::AsyncBlocksClient.{your-block-name{your-block-name.output{your-block-name.output.your-property-name}” for another block’s output (in

    the same workflow; read caveat #2)

    • “Vapi::AsyncBlocksClient.{your-block-name{your-block-name.input{your-block-name.input.your-property-name}” for another block’s input (in

    the same workflow; read caveat #2)

    • “Vapi::AsyncBlocksClient.{workflow{workflow.input{workflow.input.your-property-name}” for the current workflow’s input

    • “Vapi::AsyncBlocksClient.{global{global.your-property-name}” for the global context

    This can be as simple or as complex as you want it to be.

    • “say hello and ask the user about their day!”

    • “collect the user’s first and last name”

    • “user is Vapi::AsyncBlocksClient.{input{input.firstName} Vapi::AsyncBlocksClient.{input{input.lastName}. their age is Vapi::AsyncBlocksClient.{input{input.age}.

    ask them about their salary and if they might be interested in buying a house. we offer Vapi::AsyncBlocksClient.{input{input.offer}“ Caveats:

    1. a workflow can execute a step multiple times. example, if a loop is used in

    the graph. Vapi::AsyncBlocksClient.{stepName{stepName.output/input{stepName.output/input.propertyName} will reference the latest usage of the step.

    1. a workflow can execute a block multiple times. example, if a step is called

    multiple times or if a block is used in multiple steps. Vapi::AsyncBlocksClient.{blockName{blockName.output/input{blockName.output/input.propertyName} will reference the latest usage of the block. this liquid variable is just provided for convenience when creating blocks outside of a workflow with steps.

  • tool_id (String) (defaults to: nil)

    This is the id of the tool that the block will call. To use a transient tool, use ‘tool`.

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

Returns:



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
# File 'lib/vapi_server_sdk/blocks/client.rb', line 521

def update(id:, messages: nil, input_schema: nil, output_schema: nil, tool: nil, steps: nil, name: nil,
           instruction: nil, tool_id: 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 || {}),
        messages: messages,
        inputSchema: input_schema,
        outputSchema: output_schema,
        tool: tool,
        steps: steps,
        name: name,
        instruction: instruction,
        toolId: tool_id
      }.compact
      req.url "#{@request_client.get_url(request_options: request_options)}/block/#{id}"
    end
    Vapi::Blocks::BlocksUpdateResponse.from_json(json_object: response.body)
  end
end