Class: Vapi::FunctionTool

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

Constant Summary collapse

OMIT =
Object.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, org_id:, created_at:, updated_at:, messages: OMIT, async: OMIT, server: OMIT, function: OMIT, additional_properties: nil) ⇒ Vapi::FunctionTool

Parameters:

  • messages (Array<Vapi::FunctionToolMessagesItem>) (defaults to: OMIT)

    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.

  • async (Boolean) (defaults to: OMIT)

    This determines if the tool is async. If async, the assistant will move forward without waiting for your server to respond. This is useful if you just want to trigger something on your server. If sync, the assistant will wait for your server to respond. This is useful if want assistant to respond with the result from your server. Defaults to synchronous (‘false`).

  • server (Vapi::Server) (defaults to: OMIT)

    This is the server where a ‘tool-calls` webhook will be sent. Notes:

    • Webhook is sent to this server when a tool call is made.

    • Webhook contains the call, assistant, and phone number objects.

    • Webhook contains the variables set on the assistant.

    • Webhook is sent to the first available URL in this order:

    Vapi::FunctionTool.{tool{tool.server{tool.server.url}, Vapi::FunctionTool.{assistant{assistant.server{assistant.server.url}, Vapi::FunctionTool.{phoneNumber{phoneNumber.server{phoneNumber.server.url}, Vapi::FunctionTool.{org{org.server{org.server.url}.

    • Webhook expects a response with tool call result.

  • id (String)

    This is the unique identifier for the tool.

  • org_id (String)

    This is the unique identifier for the organization that this tool belongs to.

  • created_at (DateTime)

    This is the ISO 8601 date-time string of when the tool was created.

  • updated_at (DateTime)

    This is the ISO 8601 date-time string of when the tool was last updated.

  • function (Vapi::OpenAiFunction) (defaults to: OMIT)

    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.

  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/vapi_server_sdk/types/function_tool.rb', line 96

def initialize(id:, org_id:, created_at:, updated_at:, messages: OMIT, async: OMIT, server: OMIT, function: OMIT,
               additional_properties: nil)
  @messages = messages if messages != OMIT
  @async = async if async != OMIT
  @server = server if server != OMIT
  @id = id
  @org_id = org_id
  @created_at = created_at
  @updated_at = updated_at
  @function = function if function != OMIT
  @additional_properties = additional_properties
  @_field_set = {
    "messages": messages,
    "async": async,
    "server": server,
    "id": id,
    "orgId": org_id,
    "createdAt": created_at,
    "updatedAt": updated_at,
    "function": function
  }.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



54
55
56
# File 'lib/vapi_server_sdk/types/function_tool.rb', line 54

def additional_properties
  @additional_properties
end

#asyncBoolean (readonly)

Returns This determines if the tool is async. If async, the assistant will move forward without waiting for your server to respond. This is useful if you just want to trigger something on your server. If sync, the assistant will wait for your server to respond. This is useful if want assistant to respond with the result from your server. Defaults to synchronous (‘false`).

Returns:

  • (Boolean)

    This determines if the tool is async. If async, the assistant will move forward without waiting for your server to respond. This is useful if you just want to trigger something on your server. If sync, the assistant will wait for your server to respond. This is useful if want assistant to respond with the result from your server. Defaults to synchronous (‘false`).



23
24
25
# File 'lib/vapi_server_sdk/types/function_tool.rb', line 23

def async
  @async
end

#created_atDateTime (readonly)

Returns This is the ISO 8601 date-time string of when the tool was created.

Returns:

  • (DateTime)

    This is the ISO 8601 date-time string of when the tool was created.



40
41
42
# File 'lib/vapi_server_sdk/types/function_tool.rb', line 40

def created_at
  @created_at
end

#functionVapi::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.

Returns:

  • (Vapi::OpenAiFunction)

    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.



52
53
54
# File 'lib/vapi_server_sdk/types/function_tool.rb', line 52

def function
  @function
end

#idString (readonly)

Returns This is the unique identifier for the tool.

Returns:

  • (String)

    This is the unique identifier for the tool.



36
37
38
# File 'lib/vapi_server_sdk/types/function_tool.rb', line 36

def id
  @id
end

#messagesArray<Vapi::FunctionToolMessagesItem> (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.

Returns:

  • (Array<Vapi::FunctionToolMessagesItem>)

    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.



16
17
18
# File 'lib/vapi_server_sdk/types/function_tool.rb', line 16

def messages
  @messages
end

#org_idString (readonly)

Returns This is the unique identifier for the organization that this tool belongs to.

Returns:

  • (String)

    This is the unique identifier for the organization that this tool belongs to.



38
39
40
# File 'lib/vapi_server_sdk/types/function_tool.rb', line 38

def org_id
  @org_id
end

#serverVapi::Server (readonly)

Returns This is the server where a ‘tool-calls` webhook will be sent. Notes:

  • Webhook is sent to this server when a tool call is made.

  • Webhook contains the call, assistant, and phone number objects.

  • Webhook contains the variables set on the assistant.

  • Webhook is sent to the first available URL in this order:

Vapi::FunctionTool.{tool{tool.server{tool.server.url}, Vapi::FunctionTool.{assistant{assistant.server{assistant.server.url}, Vapi::FunctionTool.{phoneNumber{phoneNumber.server{phoneNumber.server.url}, Vapi::FunctionTool.{org{org.server{org.server.url}.

  • Webhook expects a response with tool call result.

Returns:

  • (Vapi::Server)

    This is the server where a ‘tool-calls` webhook will be sent. Notes:

    • Webhook is sent to this server when a tool call is made.

    • Webhook contains the call, assistant, and phone number objects.

    • Webhook contains the variables set on the assistant.

    • Webhook is sent to the first available URL in this order:

    Vapi::FunctionTool.{tool{tool.server{tool.server.url}, Vapi::FunctionTool.{assistant{assistant.server{assistant.server.url}, Vapi::FunctionTool.{phoneNumber{phoneNumber.server{phoneNumber.server.url}, Vapi::FunctionTool.{org{org.server{org.server.url}.

    • Webhook expects a response with tool call result.



34
35
36
# File 'lib/vapi_server_sdk/types/function_tool.rb', line 34

def server
  @server
end

#updated_atDateTime (readonly)

Returns This is the ISO 8601 date-time string of when the tool was last updated.

Returns:

  • (DateTime)

    This is the ISO 8601 date-time string of when the tool was last updated.



42
43
44
# File 'lib/vapi_server_sdk/types/function_tool.rb', line 42

def updated_at
  @updated_at
end

Class Method Details

.from_json(json_object:) ⇒ Vapi::FunctionTool

Deserialize a JSON object to an instance of FunctionTool

Parameters:

  • json_object (String)

Returns:



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/vapi_server_sdk/types/function_tool.rb', line 125

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  messages = parsed_json["messages"]&.map do |item|
    item = item.to_json
    Vapi::FunctionToolMessagesItem.from_json(json_object: item)
  end
  async = parsed_json["async"]
  if parsed_json["server"].nil?
    server = nil
  else
    server = parsed_json["server"].to_json
    server = Vapi::Server.from_json(json_object: server)
  end
  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
  new(
    messages: messages,
    async: async,
    server: server,
    id: id,
    org_id: org_id,
    created_at: created_at,
    updated_at: updated_at,
    function: function,
    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)


175
176
177
178
179
180
181
182
183
184
# File 'lib/vapi_server_sdk/types/function_tool.rb', line 175

def self.validate_raw(obj:)
  obj.messages&.is_a?(Array) != false || raise("Passed value for field obj.messages is not the expected type, validation failed.")
  obj.async&.is_a?(Boolean) != false || raise("Passed value for field obj.async is not the expected type, validation failed.")
  obj.server.nil? || Vapi::Server.validate_raw(obj: obj.server)
  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)
end

Instance Method Details

#to_json(*_args) ⇒ String

Serialize an instance of FunctionTool to a JSON object

Returns:

  • (String)


165
166
167
# File 'lib/vapi_server_sdk/types/function_tool.rb', line 165

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