class RecastAI::Build
Attributes
language[R]
token[R]
Public Class Methods
new(token = nil, language = nil)
click to toggle source
# File lib/recastai/apis/build/build.rb, line 13 def initialize(token = nil, language = nil) @token = token @language = language end
Public Instance Methods
delete_conversation(user, bot, conversation_id)
click to toggle source
# File lib/recastai/apis/build/build.rb, line 66 def delete_conversation(user, bot, conversation_id) raise RecastAI::RecastError.new('Token is missing') unless @token url = "#{RecastAI::Utils::BUILD_ENDPOINT}/users/#{user}/bots/#{bot}/builders/v1/conversation_states/#{conversation_id}" response = HTTParty.delete(url, headers: self.headers) raise RecastAI::RecastError.new(JSON.parse(response.body)['message']) if response.code != 204 true end
dialog(msg, conversation_id, language = nil, options = {})
click to toggle source
# File lib/recastai/apis/build/build.rb, line 22 def dialog(msg, conversation_id, language = nil, options = {}) raise RecastAI::RecastError.new('Token is missing') unless @token log_level = options[:log_level] || "info" proxy = options[:proxy] || {} language = @language if language.nil? body = { message: msg, conversation_id: conversation_id, language: language, log_level: log_level} body[:memory] = options[:memory] unless options[:memory].nil? options = { body: body.to_json, headers: self.headers } if proxy != {} options[:http_proxyaddr] = proxy[:host] options[:http_proxyport] = proxy[:port] end response = HTTParty.post("#{RecastAI::Utils::BUILD_ENDPOINT}/dialog", options) raise RecastAI::RecastError.new(JSON.parse(response.body)['message']) if response.code != 200 res = JSON.parse(response.body)['results'] RecastAI::DialogResponse.new(res['messages'], res['conversation'], res['nlp'], res['logs']) end
get_conversation(user, bot, conversation_id)
click to toggle source
# File lib/recastai/apis/build/build.rb, line 56 def get_conversation(user, bot, conversation_id) raise RecastAI::RecastError.new('Token is missing') unless @token url = "#{RecastAI::Utils::BUILD_ENDPOINT}/users/#{user}/bots/#{bot}/builders/v1/conversation_states/#{conversation_id}" response = HTTParty.get(url, headers: self.headers) raise RecastAI::RecastError.new(JSON.parse(response.body)['message']) if response.code != 200 RecastAI::DialogConversation.new(JSON.parse(response.body)['results']) end
headers()
click to toggle source
# File lib/recastai/apis/build/build.rb, line 18 def headers { 'Authorization' => "Token #{@token}", 'Content-Type' => 'application/json' } end
update_conversation(user, bot, conversation_id, opts)
click to toggle source
# File lib/recastai/apis/build/build.rb, line 44 def update_conversation(user, bot, conversation_id, opts) raise RecastAI::RecastError.new('Token is missing') unless @token body = opts url = "#{RecastAI::Utils::BUILD_ENDPOINT}/users/#{user}/bots/#{bot}/builders/v1/conversation_states/#{conversation_id}" response = HTTParty.put(url, body: body.to_json, headers: self.headers) raise RecastAI::RecastError.new(JSON.parse(response.body)['message']) if response.code != 200 RecastAI::DialogConversation.new(JSON.parse(response.body)['results']) end