Class: Watson::Assistant::Dialog
- Inherits:
-
Object
- Object
- Watson::Assistant::Dialog
- Defined in:
- lib/watson/assistant/dialog.rb
Instance Method Summary collapse
-
#initialize(config) ⇒ Dialog
constructor
A new instance of Dialog.
- #talk(question, context) ⇒ Object
Constructor Details
#initialize(config) ⇒ Dialog
8 9 10 11 12 13 14 15 16 |
# File 'lib/watson/assistant/dialog.rb', line 8 def initialize(config) auth = config[:auth] workspace_id = config[:workspace_id] region = config[:region] || "gateway.watsonplatform.net" url = "https://#{auth}@#{region}/assistant/api" version = "2018-02-16" @endpoint = "#{url}/v1/workspaces/#{workspace_id}/message?version=#{version}" end |
Instance Method Details
#talk(question, context) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/watson/assistant/dialog.rb', line 18 def talk(question, context) if context == "" body = {}.to_json else body = { input: { text: question }, alternate_intents: true, context: context, }.to_json end 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 return code, body end |