class WatsonAssistant::Chatbot
Attributes
api_domain[RW]
api_version[RW]
api_key[RW]
password[RW]
user_id[RW]
workspace_id[RW]
Public Class Methods
new(user_id, password, workspace_id, api_key = nil)
click to toggle source
# File lib/watson-assistant-chatbot.rb, line 31 def initialize(user_id, password, workspace_id, api_key = nil) @user_id = user_id @password = password @workspace_id = workspace_id @api_key = api_key if api_key then @user_id = 'apikey' @password = api_key end end
new_with_api_key(workspace_id, api_key)
click to toggle source
# File lib/watson-assistant-chatbot.rb, line 22 def new_with_api_key(workspace_id, api_key) new(nil, nil, workspace_id, api_key) end
new_with_user_credentials(workspace_id, user_id, password)
click to toggle source
# File lib/watson-assistant-chatbot.rb, line 26 def new_with_user_credentials(workspace_id, user_id, password) new(user_id, password, workspace_id) end
Public Instance Methods
conversation_id(results)
click to toggle source
# File lib/watson-assistant-chatbot.rb, line 56 def conversation_id(results) results["context"]["conversation_id"] end
intent_and_confidence(results)
click to toggle source
# File lib/watson-assistant-chatbot.rb, line 64 def intent_and_confidence(results) if (results["intents"].length > 0) intent = results["intents"][0]["intent"] confidence = results["intents"][0]["confidence"] else intent = INTENT_UNDETECTED confidence = '1' end return intent, confidence end
message(request)
click to toggle source
# File lib/watson-assistant-chatbot.rb, line 43 def message(request) response = RestClient::Request.new( :method => :post, :url => message_url, :user => user_id, :password => password, :payload => request, :headers => { :accept => :json, :content_type => :json } ).execute results = JSON.parse(response.to_str) end
response_text(results)
click to toggle source
# File lib/watson-assistant-chatbot.rb, line 60 def response_text(results) results["output"]["text"][0] if (results["output"]["text"].length > 0) end
Private Instance Methods
message_url()
click to toggle source
# File lib/watson-assistant-chatbot.rb, line 76 def message_url "#{API_PROTOCOL}://#{self.class.api_domain}" \ "/#{API_SERVICE}/api/v1" \ "/workspaces/#{workspace_id}" \ "/message?version=#{self.class.api_version}" end