Class: Watson::Conversation::Dialog
- Inherits:
-
Object
- Object
- Watson::Conversation::Dialog
- Defined in:
- lib/watson/conversation.rb
Instance Method Summary collapse
- #get_data ⇒ Object
-
#initialize(username: "", password: "", workspace_id: "") ⇒ Dialog
constructor
A new instance of Dialog.
- #talk(question, context) ⇒ Object
Constructor Details
#initialize(username: "", password: "", workspace_id: "") ⇒ Dialog
Returns a new instance of Dialog.
13 14 15 16 17 |
# File 'lib/watson/conversation.rb', line 13 def initialize(username: "", password: "", workspace_id: "") url = "https://#{username}:#{password}@gateway.watsonplatform.net/conversation/api" version="2017-02-03" @endpoint = "#{url}/v1/workspaces/#{workspace_id}/message?version=#{version}" end |
Instance Method Details
#get_data ⇒ Object
51 52 53 |
# File 'lib/watson/conversation.rb', line 51 def get_data() return code, body end |
#talk(question, context) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/watson/conversation.rb', line 20 def talk(question, context) future_data = FutureData.new() if context == "" body = {}.to_json else body = { input: { text: question }, alternate_intents: true, context: context, }.to_json end Thread.start do begin response = RestClient.post @endpoint, body, content_type: :json, accept: :json code = response.code body = JSON.parse(response.body) rescue RestClient::ExceptionWithResponse => e code = e.response.code body = JSON.parse(e.response.body) end future_data.set_real_data(code, body) end return future_data end |