Class: Vapi::ApiRequestTool
- Inherits:
-
Object
- Object
- Vapi::ApiRequestTool
- Defined in:
- lib/vapi_server_sdk/types/api_request_tool.rb
Constant Summary collapse
- OMIT =
Object.new
Instance Attribute Summary collapse
-
#additional_properties ⇒ OpenStruct
readonly
Additional properties unmapped to the current class definition.
-
#backoff_plan ⇒ Vapi::BackoffPlan
readonly
This is the backoff plan if the request fails.
-
#body ⇒ Vapi::JsonSchema
readonly
This is the body of the request.
-
#created_at ⇒ DateTime
readonly
This is the ISO 8601 date-time string of when the tool was created.
-
#description ⇒ String
readonly
This is the description of the tool.
-
#function ⇒ Vapi::OpenAiFunction
readonly
This is the function definition of the tool.
-
#headers ⇒ Vapi::JsonSchema
readonly
These are the headers to send in the request.
-
#id ⇒ String
readonly
This is the unique identifier for the tool.
-
#messages ⇒ Array<Vapi::ApiRequestToolMessagesItem>
readonly
These are the messages that will be spoken to the user as the tool is running.
- #method ⇒ Vapi::ApiRequestToolMethod readonly
-
#name ⇒ String
readonly
This is the name of the tool.
-
#org_id ⇒ String
readonly
This is the unique identifier for the organization that this tool belongs to.
-
#timeout_seconds ⇒ Float
readonly
This is the timeout in seconds for the request.
-
#updated_at ⇒ DateTime
readonly
This is the ISO 8601 date-time string of when the tool was last updated.
-
#url ⇒ String
readonly
This is where the request will be sent.
-
#variable_extraction_plan ⇒ Vapi::VariableExtractionPlan
readonly
This is the plan to extract variables from the tool’s response.
Class Method Summary collapse
-
.from_json(json_object:) ⇒ Vapi::ApiRequestTool
Deserialize a JSON object to an instance of ApiRequestTool.
-
.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.
Instance Method Summary collapse
- #initialize(method:, id:, org_id:, created_at:, updated_at:, url:, messages: OMIT, timeout_seconds: OMIT, function: OMIT, name: OMIT, description: OMIT, body: OMIT, headers: OMIT, backoff_plan: OMIT, variable_extraction_plan: OMIT, additional_properties: nil) ⇒ Vapi::ApiRequestTool constructor
-
#to_json(*_args) ⇒ String
Serialize an instance of ApiRequestTool to a JSON object.
Constructor Details
#initialize(method:, id:, org_id:, created_at:, updated_at:, url:, messages: OMIT, timeout_seconds: OMIT, function: OMIT, name: OMIT, description: OMIT, body: OMIT, headers: OMIT, backoff_plan: OMIT, variable_extraction_plan: OMIT, additional_properties: nil) ⇒ Vapi::ApiRequestTool
444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 |
# File 'lib/vapi_server_sdk/types/api_request_tool.rb', line 444 def initialize(method:, id:, org_id:, created_at:, updated_at:, url:, messages: OMIT, timeout_seconds: OMIT, function: OMIT, name: OMIT, description: OMIT, body: OMIT, headers: OMIT, backoff_plan: OMIT, variable_extraction_plan: OMIT, additional_properties: nil) @messages = if != OMIT @method = method @timeout_seconds = timeout_seconds if timeout_seconds != OMIT @id = id @org_id = org_id @created_at = created_at @updated_at = updated_at @function = function if function != OMIT @name = name if name != OMIT @description = description if description != OMIT @url = url @body = body if body != OMIT @headers = headers if headers != OMIT @backoff_plan = backoff_plan if backoff_plan != OMIT @variable_extraction_plan = variable_extraction_plan if variable_extraction_plan != OMIT @additional_properties = additional_properties @_field_set = { "messages": , "method": method, "timeoutSeconds": timeout_seconds, "id": id, "orgId": org_id, "createdAt": created_at, "updatedAt": updated_at, "function": function, "name": name, "description": description, "url": url, "body": body, "headers": headers, "backoffPlan": backoff_plan, "variableExtractionPlan": variable_extraction_plan }.reject do |_k, v| v == OMIT end end |
Instance Attribute Details
#additional_properties ⇒ OpenStruct (readonly)
Returns Additional properties unmapped to the current class definition.
233 234 235 |
# File 'lib/vapi_server_sdk/types/api_request_tool.rb', line 233 def additional_properties @additional_properties end |
#backoff_plan ⇒ Vapi::BackoffPlan (readonly)
Returns This is the backoff plan if the request fails. Defaults to undefined (the request will not be retried). @default undefined (the request will not be retried).
58 59 60 |
# File 'lib/vapi_server_sdk/types/api_request_tool.rb', line 58 def backoff_plan @backoff_plan end |
#body ⇒ Vapi::JsonSchema (readonly)
Returns This is the body of the request.
52 53 54 |
# File 'lib/vapi_server_sdk/types/api_request_tool.rb', line 52 def body @body end |
#created_at ⇒ DateTime (readonly)
Returns This is the ISO 8601 date-time string of when the tool was created.
30 31 32 |
# File 'lib/vapi_server_sdk/types/api_request_tool.rb', line 30 def created_at @created_at end |
#description ⇒ String (readonly)
Returns This is the description of the tool. This will be passed to the model.
48 49 50 |
# File 'lib/vapi_server_sdk/types/api_request_tool.rb', line 48 def description @description end |
#function ⇒ Vapi::OpenAiFunction (readonly)
Returns This is the function definition of the tool. For ‘endCall`, `transferCall`, and `dtmf` tools, this is auto-filled based on tool-specific fields like `tool.destinations`. But, even in those cases, you can provide a custom function definition for advanced use cases. An example of an advanced use case is if you want to customize the message that’s spoken for ‘endCall` tool. You can specify a function where it returns an argument “reason”. Then, in `messages` array, you can have many “request-complete” messages. One of these messages will be triggered if the `messages[].conditions` matches the “reason” argument.
42 43 44 |
# File 'lib/vapi_server_sdk/types/api_request_tool.rb', line 42 def function @function end |
#headers ⇒ Vapi::JsonSchema (readonly)
Returns These are the headers to send in the request.
54 55 56 |
# File 'lib/vapi_server_sdk/types/api_request_tool.rb', line 54 def headers @headers end |
#id ⇒ String (readonly)
Returns This is the unique identifier for the tool.
26 27 28 |
# File 'lib/vapi_server_sdk/types/api_request_tool.rb', line 26 def id @id end |
#messages ⇒ Array<Vapi::ApiRequestToolMessagesItem> (readonly)
Returns These are the messages that will be spoken to the user as the tool is running. For some tools, this is auto-filled based on special fields like ‘tool.destinations`. For others like the function tool, these can be custom configured.
19 20 21 |
# File 'lib/vapi_server_sdk/types/api_request_tool.rb', line 19 def @messages end |
#method ⇒ Vapi::ApiRequestToolMethod (readonly)
21 22 23 |
# File 'lib/vapi_server_sdk/types/api_request_tool.rb', line 21 def method @method end |
#name ⇒ String (readonly)
Returns This is the name of the tool. This will be passed to the model. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum length of 40.
46 47 48 |
# File 'lib/vapi_server_sdk/types/api_request_tool.rb', line 46 def name @name end |
#org_id ⇒ String (readonly)
Returns This is the unique identifier for the organization that this tool belongs to.
28 29 30 |
# File 'lib/vapi_server_sdk/types/api_request_tool.rb', line 28 def org_id @org_id end |
#timeout_seconds ⇒ Float (readonly)
Returns This is the timeout in seconds for the request. Defaults to 20 seconds. @default 20.
24 25 26 |
# File 'lib/vapi_server_sdk/types/api_request_tool.rb', line 24 def timeout_seconds @timeout_seconds end |
#updated_at ⇒ DateTime (readonly)
Returns This is the ISO 8601 date-time string of when the tool was last updated.
32 33 34 |
# File 'lib/vapi_server_sdk/types/api_request_tool.rb', line 32 def updated_at @updated_at end |
#url ⇒ String (readonly)
Returns This is where the request will be sent.
50 51 52 |
# File 'lib/vapi_server_sdk/types/api_request_tool.rb', line 50 def url @url end |
#variable_extraction_plan ⇒ Vapi::VariableExtractionPlan (readonly)
Returns This is the plan to extract variables from the tool’s response. These will be accessible during the call and stored in ‘call.artifact.variableValues` after the call. Usage:
-
Use ‘aliases` to extract variables from the tool’s response body. (Most
common case) “‘json { “aliases”: [ { “key”: “customerName”, “value”: “Vapi::ApiRequestTool.{customer{customer.name}” }, { “key”: “customerAge”, “value”: “Vapi::ApiRequestTool.{customer{customer.age}” } ] } “` The tool response body is made available to the liquid template.
-
Use ‘aliases` to extract variables from the tool’s response body if the
response is an array. “‘json { “aliases”: [ { “key”: “customerName”, “value”: “Vapi::ApiRequestTool.{$[0]{$[0].name}” }, { “key”: “customerAge”, “value”: “Vapi::ApiRequestTool.{$[0]{$[0].age}” } ] } “` $ is a shorthand for the tool’s response body. ‘$[0]` is the first item in the array. `$[n]` is the nth item in the array. Note, $ is available regardless of the response body type (both object and array).
-
Use ‘aliases` to extract variables from the tool’s response headers.
“‘json { “aliases”: [ { “key”: “customerName”, “value”: “Vapi::ApiRequestTool.{tool{tool.response{tool.response.headers{tool.response.headers.customer-name}” }, { “key”: “customerAge”, “value”: “Vapi::ApiRequestTool.{tool{tool.response{tool.response.headers{tool.response.headers.customer-age}” } ] } “` `tool.response` is made available to the liquid template. Particularly, both `tool.response.headers` and `tool.response.body` are available. Note, `tool.response` is available regardless of the response body type (both object and array).
-
Use ‘schema` to extract a large portion of the tool’s response body.
4.1. If you hit example.com and it returns ‘“John”, “age”: 30`, then you can specify the schema as: “`json { “schema”: { “type”: “object”, “properties”: { “name”: { “type”: “string” }, “age”: { “type”: “number” } } } } “` 4.2. If you hit example.com and it returns `{“first”: “John”, “last”: “Doe”}`, then you can specify the schema as: “`json { “schema”: { “type”: “object”, “properties”: { “name”: { “type”: “object”, “properties”: { “first”: { “type”: “string” }, “last”: { “type”: “string” } } } } } } “` These will be extracted as `name }` and `age }` respectively. To emphasize, object properties are extracted as direct global variables. 4.3. If you hit example.com and it returns `{“first”: “John”, “last”: “Doe”}`, then you can specify the schema as: “`json { “schema”: { “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. 4.4. If you hit example.com and it returns `[“94123”, “94124”]`, then you can specify the schema as: “`json { “schema”: { “type”: “array”, “title”: “zipCodes”, “items”: { “type”: “string” } } } “` This will be extracted as `zipCodes }`. To access the array items, you can use `zipCodes }` and `zipCodes }`. 4.5. If you hit example.com and it returns `[“John”, “age”: 30, “zipCodes”: [“94123”, “94124”], “Jane”, “age”: 25, “zipCodes”: [“94125”, “94126”]]`, then you can specify the schema as: “`json { “schema”: { “type”: “array”, “title”: “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 }`. Note: Both `aliases` and `schema` can be used together.
231 232 233 |
# File 'lib/vapi_server_sdk/types/api_request_tool.rb', line 231 def variable_extraction_plan @variable_extraction_plan end |
Class Method Details
.from_json(json_object:) ⇒ Vapi::ApiRequestTool
Deserialize a JSON object to an instance of ApiRequestTool
487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 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 |
# File 'lib/vapi_server_sdk/types/api_request_tool.rb', line 487 def self.from_json(json_object:) struct = JSON.parse(json_object, object_class: OpenStruct) parsed_json = JSON.parse(json_object) = parsed_json["messages"]&.map do |item| item = item.to_json Vapi::ApiRequestToolMessagesItem.from_json(json_object: item) end method = parsed_json["method"] timeout_seconds = parsed_json["timeoutSeconds"] id = parsed_json["id"] org_id = parsed_json["orgId"] created_at = (DateTime.parse(parsed_json["createdAt"]) unless parsed_json["createdAt"].nil?) updated_at = (DateTime.parse(parsed_json["updatedAt"]) unless parsed_json["updatedAt"].nil?) if parsed_json["function"].nil? function = nil else function = parsed_json["function"].to_json function = Vapi::OpenAiFunction.from_json(json_object: function) end name = parsed_json["name"] description = parsed_json["description"] url = parsed_json["url"] if parsed_json["body"].nil? body = nil else body = parsed_json["body"].to_json body = Vapi::JsonSchema.from_json(json_object: body) end if parsed_json["headers"].nil? headers = nil else headers = parsed_json["headers"].to_json headers = Vapi::JsonSchema.from_json(json_object: headers) end if parsed_json["backoffPlan"].nil? backoff_plan = nil else backoff_plan = parsed_json["backoffPlan"].to_json backoff_plan = Vapi::BackoffPlan.from_json(json_object: backoff_plan) end if parsed_json["variableExtractionPlan"].nil? variable_extraction_plan = nil else variable_extraction_plan = parsed_json["variableExtractionPlan"].to_json variable_extraction_plan = Vapi::VariableExtractionPlan.from_json(json_object: variable_extraction_plan) end new( messages: , method: method, timeout_seconds: timeout_seconds, id: id, org_id: org_id, created_at: created_at, updated_at: updated_at, function: function, name: name, description: description, url: url, body: body, headers: headers, backoff_plan: backoff_plan, variable_extraction_plan: variable_extraction_plan, 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.
566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 |
# File 'lib/vapi_server_sdk/types/api_request_tool.rb', line 566 def self.validate_raw(obj:) obj.&.is_a?(Array) != false || raise("Passed value for field obj.messages is not the expected type, validation failed.") obj.method.is_a?(Vapi::ApiRequestToolMethod) != false || raise("Passed value for field obj.method is not the expected type, validation failed.") obj.timeout_seconds&.is_a?(Float) != false || raise("Passed value for field obj.timeout_seconds is not the expected type, validation failed.") obj.id.is_a?(String) != false || raise("Passed value for field obj.id is not the expected type, validation failed.") obj.org_id.is_a?(String) != false || raise("Passed value for field obj.org_id is not the expected type, validation failed.") obj.created_at.is_a?(DateTime) != false || raise("Passed value for field obj.created_at is not the expected type, validation failed.") obj.updated_at.is_a?(DateTime) != false || raise("Passed value for field obj.updated_at is not the expected type, validation failed.") obj.function.nil? || Vapi::OpenAiFunction.validate_raw(obj: obj.function) obj.name&.is_a?(String) != false || raise("Passed value for field obj.name is not the expected type, validation failed.") obj.description&.is_a?(String) != false || raise("Passed value for field obj.description is not the expected type, validation failed.") obj.url.is_a?(String) != false || raise("Passed value for field obj.url is not the expected type, validation failed.") obj.body.nil? || Vapi::JsonSchema.validate_raw(obj: obj.body) obj.headers.nil? || Vapi::JsonSchema.validate_raw(obj: obj.headers) obj.backoff_plan.nil? || Vapi::BackoffPlan.validate_raw(obj: obj.backoff_plan) obj.variable_extraction_plan.nil? || Vapi::VariableExtractionPlan.validate_raw(obj: obj.variable_extraction_plan) end |
Instance Method Details
#to_json(*_args) ⇒ String
Serialize an instance of ApiRequestTool to a JSON object
556 557 558 |
# File 'lib/vapi_server_sdk/types/api_request_tool.rb', line 556 def to_json(*_args) @_field_set&.to_json end |