Class: Vapi::BlocksClient

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

Parameters:



25
26
27
# File 'lib/vapi_server_sdk/blocks/client.rb', line 25

def initialize(request_client:)
  @request_client = request_client
end

Instance Attribute Details

#request_clientVapi::RequestClient (readonly)

Returns:



21
22
23
# File 'lib/vapi_server_sdk/blocks/client.rb', line 21

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:



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/vapi_server_sdk/blocks/client.rb', line 95

def 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)}/block"
  end
  Vapi::Blocks::BlocksCreateResponse.from_json(json_object: response.body)
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:



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

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



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/vapi_server_sdk/blocks/client.rb', line 123

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



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

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

#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::BlocksClient.{input{input.propertyName}) in context of the block execution (step)

    • (Vapi::BlocksClient.{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::BlocksClient.{stepName{stepName.output}`). These are accessible as variables:

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

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

    • (Vapi::BlocksClient.{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::BlocksClient.{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::BlocksClient.{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::BlocksClient.{input{input.your-property-name}” for the current step’s input

    • “Vapi::BlocksClient.{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::BlocksClient.{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::BlocksClient.{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::BlocksClient.{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::BlocksClient.{workflow{workflow.input{workflow.input.your-property-name}” for the current workflow’s input

    • “Vapi::BlocksClient.{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::BlocksClient.{input{input.firstName} Vapi::BlocksClient.{input{input.lastName}. their age is Vapi::BlocksClient.{input{input.age}.

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

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

    the graph. Vapi::BlocksClient.{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::BlocksClient.{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:



251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
# File 'lib/vapi_server_sdk/blocks/client.rb', line 251

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