Class: Vapi::Chats::Client
- Inherits:
-
Object
- Object
- Vapi::Chats::Client
- Defined in:
- lib/vapi/chats/client.rb
Instance Method Summary collapse
-
#create(request_options: {}, **params) ⇒ Vapi::Chats::Types::CreateChatsResponse
Creates a new chat with optional SMS delivery via transport field.
- #create_response(request_options: {}, **params) ⇒ Vapi::Chats::Types::CreateResponseChatsResponse
- #delete(request_options: {}, **params) ⇒ Vapi::Types::Chat
- #get(request_options: {}, **params) ⇒ Vapi::Types::Chat
- #initialize(client:) ⇒ void constructor
- #list(request_options: {}, **params) ⇒ Vapi::Types::ChatPaginatedResponse
Constructor Details
#initialize(client:) ⇒ void
9 10 11 |
# File 'lib/vapi/chats/client.rb', line 9 def initialize(client:) @client = client end |
Instance Method Details
#create(request_options: {}, **params) ⇒ Vapi::Chats::Types::CreateChatsResponse
Creates a new chat with optional SMS delivery via transport field. Requires at least one of: assistantId/assistant, sessionId, or previousChatId. Note: sessionId and previousChatId are mutually exclusive. Transport field enables SMS delivery with two modes: (1) New conversation - provide transport.phoneNumberId and transport.customer to create a new session, (2) Existing conversation - provide sessionId to use existing session data. Cannot specify both sessionId and transport fields together. The transport.useLLMGeneratedMessageForOutbound flag controls whether input is processed by LLM (true, default) or forwarded directly as SMS (false).
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/vapi/chats/client.rb', line 100 def create(request_options: {}, **params) params = Vapi::Internal::Types::Utils.normalize_keys(params) request = Vapi::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "chat", body: Vapi::Chats::Types::CreateChatDto.new(params).to_h, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Vapi::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Vapi::Chats::Types::CreateChatsResponse.load(response.body) else error_class = Vapi::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#create_response(request_options: {}, **params) ⇒ Vapi::Chats::Types::CreateResponseChatsResponse
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/vapi/chats/client.rb', line 196 def create_response(request_options: {}, **params) params = Vapi::Internal::Types::Utils.normalize_keys(params) request = Vapi::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "chat/responses", body: Vapi::Chats::Types::OpenAiResponsesRequest.new(params).to_h, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Vapi::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Vapi::Chats::Types::CreateResponseChatsResponse.load(response.body) else error_class = Vapi::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#delete(request_options: {}, **params) ⇒ Vapi::Types::Chat
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/vapi/chats/client.rb', line 165 def delete(request_options: {}, **params) params = Vapi::Internal::Types::Utils.normalize_keys(params) request = Vapi::Internal::JSON::Request.new( base_url: [:base_url], method: "DELETE", path: "chat/#{URI.encode_uri_component(params[:id].to_s)}", request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Vapi::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Vapi::Types::Chat.load(response.body) else error_class = Vapi::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#get(request_options: {}, **params) ⇒ Vapi::Types::Chat
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/vapi/chats/client.rb', line 133 def get(request_options: {}, **params) params = Vapi::Internal::Types::Utils.normalize_keys(params) request = Vapi::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "chat/#{URI.encode_uri_component(params[:id].to_s)}", request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Vapi::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Vapi::Types::Chat.load(response.body) else error_class = Vapi::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#list(request_options: {}, **params) ⇒ Vapi::Types::ChatPaginatedResponse
39 40 41 42 43 44 45 46 47 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 81 |
# File 'lib/vapi/chats/client.rb', line 39 def list(request_options: {}, **params) params = Vapi::Internal::Types::Utils.normalize_keys(params) query_param_names = %i[id assistant_id assistant_id_any squad_id session_id previous_chat_id page sort_order limit created_at_gt created_at_lt created_at_ge created_at_le updated_at_gt updated_at_lt updated_at_ge updated_at_le] query_params = {} query_params["id"] = params[:id] if params.key?(:id) query_params["assistantId"] = params[:assistant_id] if params.key?(:assistant_id) query_params["assistantIdAny"] = params[:assistant_id_any] if params.key?(:assistant_id_any) query_params["squadId"] = params[:squad_id] if params.key?(:squad_id) query_params["sessionId"] = params[:session_id] if params.key?(:session_id) query_params["previousChatId"] = params[:previous_chat_id] if params.key?(:previous_chat_id) query_params["page"] = params[:page] if params.key?(:page) query_params["sortOrder"] = params[:sort_order] if params.key?(:sort_order) query_params["limit"] = params[:limit] if params.key?(:limit) query_params["createdAtGt"] = params[:created_at_gt] if params.key?(:created_at_gt) query_params["createdAtLt"] = params[:created_at_lt] if params.key?(:created_at_lt) query_params["createdAtGe"] = params[:created_at_ge] if params.key?(:created_at_ge) query_params["createdAtLe"] = params[:created_at_le] if params.key?(:created_at_le) query_params["updatedAtGt"] = params[:updated_at_gt] if params.key?(:updated_at_gt) query_params["updatedAtLt"] = params[:updated_at_lt] if params.key?(:updated_at_lt) query_params["updatedAtGe"] = params[:updated_at_ge] if params.key?(:updated_at_ge) query_params["updatedAtLe"] = params[:updated_at_le] if params.key?(:updated_at_le) params.except(*query_param_names) request = Vapi::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "chat", query: query_params, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Vapi::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Vapi::Types::ChatPaginatedResponse.load(response.body) else error_class = Vapi::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |