Class: Watson::Conversation
- Inherits:
-
Object
- Object
- Watson::Conversation
- Defined in:
- lib/watson/conversation.rb
Direct Known Subclasses
Class Method Summary collapse
Instance Method Summary collapse
- #build_response(result) ⇒ Object
- #conversation ⇒ Object
- #send_message(message = '') ⇒ Object
- #url ⇒ Object
Class Method Details
.configure(options = {}) ⇒ Object
3 4 5 6 7 8 |
# File 'lib/watson/conversation.rb', line 3 def self.configure( = {}) @@username = [:username] @@password = [:password] @@url = [:url] @@workspace_id = [:workspace_id] end |
Instance Method Details
#build_response(result) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/watson/conversation.rb', line 32 def build_response(result) { source: 'conversation', intent: result['intents'][0]['intent'], message: @message, tittle: @message, body: result['output']['text'], context_id: result['context']['conversation_id'] } end |
#conversation ⇒ Object
10 11 12 |
# File 'lib/watson/conversation.rb', line 10 def conversation @context['conversation_id'] end |
#send_message(message = '') ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/watson/conversation.rb', line 14 def ( = '') return if .empty? || .nil? @message = params = { input: { text: @message }, alternate_intents: true } params.merge!(@context) unless @context.nil? response = Excon.post(url, body: params.to_json, headers: { 'Content-Type' => 'application/json', 'Accept' => 'application/json' }, user: @@username, password: @@password) result = JSON.parse(response.body) @context = { context: result['context'] } build_response(result) end |
#url ⇒ Object
40 41 42 |
# File 'lib/watson/conversation.rb', line 40 def url @@url + '/v1/workspaces/' + @@workspace_id + '/message?version=2016-09-20' end |