Class: Vapi::PhoneNumbersClient

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_client:) ⇒ Vapi::PhoneNumbersClient

Parameters:



22
23
24
# File 'lib/vapi_server_sdk/phone_numbers/client.rb', line 22

def initialize(request_client:)
  @request_client = request_client
end

Instance Attribute Details

#request_clientVapi::RequestClient (readonly)

Returns:



18
19
20
# File 'lib/vapi_server_sdk/phone_numbers/client.rb', line 18

def request_client
  @request_client
end

Instance Method Details

#create(request:, request_options: nil) ⇒ Vapi::PhoneNumbers::PhoneNumbersCreateResponse

Examples:

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

Parameters:

Returns:



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/vapi_server_sdk/phone_numbers/client.rb', line 92

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)}/phone-number"
  end
  Vapi::PhoneNumbers::PhoneNumbersCreateResponse.from_json(json_object: response.body)
end

#delete(id:, request_options: nil) ⇒ Vapi::PhoneNumbers::PhoneNumbersDeleteResponse

Examples:

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

Parameters:

Returns:



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/vapi_server_sdk/phone_numbers/client.rb', line 150

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)}/phone-number/#{id}"
  end
  Vapi::PhoneNumbers::PhoneNumbersDeleteResponse.from_json(json_object: response.body)
end

#get(id:, request_options: nil) ⇒ Vapi::PhoneNumbers::PhoneNumbersGetResponse

Examples:

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

Parameters:

Returns:



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/vapi_server_sdk/phone_numbers/client.rb', line 120

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)}/phone-number/#{id}"
  end
  Vapi::PhoneNumbers::PhoneNumbersGetResponse.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::PhoneNumbers::PhoneNumbersListResponseItem>

Examples:

api = Vapi::Client.new(
  base_url: "https://api.example.com",
  environment: Vapi::Environment::DEFAULT,
  token: "YOUR_AUTH_TOKEN"
)
api.phone_numbers.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:



48
49
50
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
# File 'lib/vapi_server_sdk/phone_numbers/client.rb', line 48

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)}/phone-number"
  end
  parsed_json = JSON.parse(response.body)
  parsed_json&.map do |item|
    item = item.to_json
    Vapi::PhoneNumbers::PhoneNumbersListResponseItem.from_json(json_object: item)
  end
end

#update(id:, fallback_destination: nil, name: nil, assistant_id: nil, squad_id: nil, server_url: nil, server_url_secret: nil, request_options: nil) ⇒ Vapi::PhoneNumbers::PhoneNumbersUpdateResponse

Examples:

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

Parameters:

  • id (String)
  • fallback_destination (Vapi::PhoneNumbers::UpdatePhoneNumberDtoFallbackDestination) (defaults to: nil)

    This is the fallback destination an inbound call will be transferred to if:

    1. ‘assistantId` is not set

    2. ‘squadId` is not set

    3. and, ‘assistant-request` message to the `serverUrl` fails

    If this is not set and above conditions are met, the inbound call is hung up with an error message.

  • name (String) (defaults to: nil)

    This is the name of the phone number. This is just for your own reference.

  • assistant_id (String) (defaults to: nil)

    This is the assistant that will be used for incoming calls to this phone number. If neither ‘assistantId` nor `squadId` is set, `assistant-request` will be sent to your Server URL. Check `ServerMessage` and `ServerMessageResponse` for the shape of the message and response that is expected.

  • squad_id (String) (defaults to: nil)

    This is the squad that will be used for incoming calls to this phone number. If neither ‘assistantId` nor `squadId` is set, `assistant-request` will be sent to your Server URL. Check `ServerMessage` and `ServerMessageResponse` for the shape of the message and response that is expected.

  • server_url (String) (defaults to: nil)

    This is the server URL where messages will be sent for calls on this number. This includes the ‘assistant-request` message. You can see the shape of the messages sent in `ServerMessage`. This overrides the `org.serverUrl`. Order of precedence: tool.server.url > assistant.serverUrl > phoneNumber.serverUrl > org.serverUrl.

  • server_url_secret (String) (defaults to: nil)

    This is the secret Vapi will send with every message to your server. It’s sent as a header called x-vapi-secret. Same precedence logic as serverUrl.

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

Returns:



203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# File 'lib/vapi_server_sdk/phone_numbers/client.rb', line 203

def update(id:, fallback_destination: nil, name: nil, assistant_id: nil, squad_id: nil, server_url: nil,
           server_url_secret: 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 || {}),
      fallbackDestination: fallback_destination,
      name: name,
      assistantId: assistant_id,
      squadId: squad_id,
      serverUrl: server_url,
      serverUrlSecret: server_url_secret
    }.compact
    req.url "#{@request_client.get_url(request_options: request_options)}/phone-number/#{id}"
  end
  Vapi::PhoneNumbers::PhoneNumbersUpdateResponse.from_json(json_object: response.body)
end