Class: Vapi::VariableExtractionPlan

Inherits:
Object
  • Object
show all
Defined in:
lib/vapi_server_sdk/types/variable_extraction_plan.rb

Constant Summary collapse

OMIT =
Object.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schema: OMIT, aliases: OMIT, additional_properties: nil) ⇒ Vapi::VariableExtractionPlan

Parameters:

  • schema (Vapi::JsonSchema) (defaults to: OMIT)

    This is the schema to extract. Examples:

    1. To extract object properties, you can use the following schema:

    “‘json { “type”: “object”, “properties”: { “name”: { “type”: “string” }, “age”: { “type”: “number” } } } “` These will be extracted as `name }` and `age }` respectively. To emphasize, object properties are extracted as direct global variables.

    1. To extract nested properties, you can use the following schema:

    “‘json { “type”: “object”, “properties”: { “name”: { “type”: “object”, “properties”: { “first”: { “type”: “string” }, “last”: { “type”: “string” } } } } } “` These will be extracted as `name }`. And, `name.first }` and `name.last }` will be accessible.

    1. To extract array items, you can use the following schema:

    “‘json { “type”: “array”, “title”: “zipCodes”, “items”: { “type”: “string” } } “` This will be extracted as `zipCodes }`. To access the array items, you can use `zipCodes }` and `zipCodes }`.

    1. To extract array of objects, you can use the following schema:

    “‘json { “type”: “array”, “name”: “people”, “items”: { “type”: “object”, “properties”: { “name”: { “type”: “string” }, “age”: { “type”: “number” }, “zipCodes”: { “type”: “array”, “items”: { “type”: “string” } } } } } “` This will be extracted as `people }`. To access the array items, you can use `people.name }`, `people.age }`, `people.zipCodes }`, `people.zipCodes }` and `people.zipCodes }`.

  • aliases (Array<Vapi::VariableExtractionAlias>) (defaults to: OMIT)

    These are additional variables to create. These will be accessible during the call as ‘{key}` and stored in `call.artifact.variableValues` after the call. Example: “`json { “aliases”: [ { “key”: “customerName”, “value”: “{name}” }, { “key”: “fullName”, “value”: “{firstName} {lastName}” }, { “key”: “greeting”, “value”: “Hello {name}, welcome to {company}!” }, { “key”: “customerEmail”, “value”: “href="0">addresses.city}” }, { “key”: “something”, “value”: “liquid}” } ] } “` This will create variables `customerName`, `fullName`, `customerEmail`, `greeting`, and `something`. To access these variables, you can reference them as `{customerName}`, `{fullName}`, `{customerEmail}`, `{greeting}`, and `{something}`.

  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



246
247
248
249
250
251
252
253
# File 'lib/vapi_server_sdk/types/variable_extraction_plan.rb', line 246

def initialize(schema: OMIT, aliases: OMIT, additional_properties: nil)
  @schema = schema if schema != OMIT
  @aliases = aliases if aliases != OMIT
  @additional_properties = additional_properties
  @_field_set = { "schema": schema, "aliases": aliases }.reject do |_k, v|
    v == OMIT
  end
end

Instance Attribute Details

#additional_propertiesOpenStruct (readonly)

Returns Additional properties unmapped to the current class definition.

Returns:

  • (OpenStruct)

    Additional properties unmapped to the current class definition



125
126
127
# File 'lib/vapi_server_sdk/types/variable_extraction_plan.rb', line 125

def additional_properties
  @additional_properties
end

#aliasesArray<Vapi::VariableExtractionAlias> (readonly)

Returns These are additional variables to create. These will be accessible during the call as ‘{key}` and stored in `call.artifact.variableValues` after the call. Example: “`json { “aliases”: [ { “key”: “customerName”, “value”: “{name}” }, { “key”: “fullName”, “value”: “{firstName} {lastName}” }, { “key”: “greeting”, “value”: “Hello {name}, welcome to {company}!” }, { “key”: “customerEmail”, “value”: “href="0">addresses.city}” }, { “key”: “something”, “value”: “liquid}” } ] } “` This will create variables `customerName`, `fullName`, `customerEmail`, `greeting`, and `something`. To access these variables, you can reference them as `{customerName}`, `{fullName}`, `{customerEmail}`, `{greeting}`, and `{something}`.

Returns:

  • (Array<Vapi::VariableExtractionAlias>)

    These are additional variables to create. These will be accessible during the call as ‘{key}` and stored in `call.artifact.variableValues` after the call. Example: “`json { “aliases”: [ { “key”: “customerName”, “value”: “{name}” }, { “key”: “fullName”, “value”: “{firstName} {lastName}” }, { “key”: “greeting”, “value”: “Hello {name}, welcome to {company}!” }, { “key”: “customerEmail”, “value”: “href="0">addresses.city}” }, { “key”: “something”, “value”: “liquid}” } ] } “` This will create variables `customerName`, `fullName`, `customerEmail`, `greeting`, and `something`. To access these variables, you can reference them as `{customerName}`, `{fullName}`, `{customerEmail}`, `{greeting}`, and `{something}`.



123
124
125
# File 'lib/vapi_server_sdk/types/variable_extraction_plan.rb', line 123

def aliases
  @aliases
end

#schemaVapi::JsonSchema (readonly)

Returns This is the schema to extract. Examples:

  1. To extract object properties, you can use the following schema:

“‘json { “type”: “object”, “properties”: { “name”: { “type”: “string” }, “age”: { “type”: “number” } } } “` These will be extracted as `name }` and `age }` respectively. To emphasize, object properties are extracted as direct global variables.

  1. To extract nested properties, you can use the following schema:

“‘json { “type”: “object”, “properties”: { “name”: { “type”: “object”, “properties”: { “first”: { “type”: “string” }, “last”: { “type”: “string” } } } } } “` These will be extracted as `name }`. And, `name.first }` and `name.last }` will be accessible.

  1. To extract array items, you can use the following schema:

“‘json { “type”: “array”, “title”: “zipCodes”, “items”: { “type”: “string” } } “` This will be extracted as `zipCodes }`. To access the array items, you can use `zipCodes }` and `zipCodes }`.

  1. To extract array of objects, you can use the following schema:

“‘json { “type”: “array”, “name”: “people”, “items”: { “type”: “object”, “properties”: { “name”: { “type”: “string” }, “age”: { “type”: “number” }, “zipCodes”: { “type”: “array”, “items”: { “type”: “string” } } } } } “` This will be extracted as `people }`. To access the array items, you can use `people.name }`, `people.age }`, `people.zipCodes }`, `people.zipCodes }` and `people.zipCodes }`.

Returns:

  • (Vapi::JsonSchema)

    This is the schema to extract. Examples:

    1. To extract object properties, you can use the following schema:

    “‘json { “type”: “object”, “properties”: { “name”: { “type”: “string” }, “age”: { “type”: “number” } } } “` These will be extracted as `name }` and `age }` respectively. To emphasize, object properties are extracted as direct global variables.

    1. To extract nested properties, you can use the following schema:

    “‘json { “type”: “object”, “properties”: { “name”: { “type”: “object”, “properties”: { “first”: { “type”: “string” }, “last”: { “type”: “string” } } } } } “` These will be extracted as `name }`. And, `name.first }` and `name.last }` will be accessible.

    1. To extract array items, you can use the following schema:

    “‘json { “type”: “array”, “title”: “zipCodes”, “items”: { “type”: “string” } } “` This will be extracted as `zipCodes }`. To access the array items, you can use `zipCodes }` and `zipCodes }`.

    1. To extract array of objects, you can use the following schema:

    “‘json { “type”: “array”, “name”: “people”, “items”: { “type”: “object”, “properties”: { “name”: { “type”: “string” }, “age”: { “type”: “number” }, “zipCodes”: { “type”: “array”, “items”: { “type”: “string” } } } } } “` This will be extracted as `people }`. To access the array items, you can use `people.name }`, `people.age }`, `people.zipCodes }`, `people.zipCodes }` and `people.zipCodes }`.



88
89
90
# File 'lib/vapi_server_sdk/types/variable_extraction_plan.rb', line 88

def schema
  @schema
end

Class Method Details

.from_json(json_object:) ⇒ Vapi::VariableExtractionPlan

Deserialize a JSON object to an instance of VariableExtractionPlan

Parameters:

  • json_object (String)

Returns:



259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
# File 'lib/vapi_server_sdk/types/variable_extraction_plan.rb', line 259

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  if parsed_json["schema"].nil?
    schema = nil
  else
    schema = parsed_json["schema"].to_json
    schema = Vapi::JsonSchema.from_json(json_object: schema)
  end
  aliases = parsed_json["aliases"]&.map do |item|
    item = item.to_json
    Vapi::VariableExtractionAlias.from_json(json_object: item)
  end
  new(
    schema: schema,
    aliases: aliases,
    additional_properties: struct
  )
end

.validate_raw(obj:) ⇒ Void

Leveraged for Union-type generation, validate_raw attempts to parse the given

hash and check each fields type against the current object's property
definitions.

Parameters:

  • obj (Object)

Returns:

  • (Void)


292
293
294
295
# File 'lib/vapi_server_sdk/types/variable_extraction_plan.rb', line 292

def self.validate_raw(obj:)
  obj.schema.nil? || Vapi::JsonSchema.validate_raw(obj: obj.schema)
  obj.aliases&.is_a?(Array) != false || raise("Passed value for field obj.aliases is not the expected type, validation failed.")
end

Instance Method Details

#to_json(*_args) ⇒ String

Serialize an instance of VariableExtractionPlan to a JSON object

Returns:

  • (String)


282
283
284
# File 'lib/vapi_server_sdk/types/variable_extraction_plan.rb', line 282

def to_json(*_args)
  @_field_set&.to_json
end