Class: Watson::Assistant::ManageDialog
- Inherits:
-
Object
- Object
- Watson::Assistant::ManageDialog
- Defined in:
- lib/watson/assistant.rb
Instance Method Summary collapse
- #delete(user) ⇒ Object
- #has_key?(user) ⇒ Boolean
-
#initialize(username: "", password: "", workspace_id: "", storage: "hash") ⇒ ManageDialog
constructor
A new instance of ManageDialog.
- #talk(user, question) ⇒ Object
- #users ⇒ Object
Constructor Details
#initialize(username: "", password: "", workspace_id: "", storage: "hash") ⇒ ManageDialog
Returns a new instance of ManageDialog.
72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/watson/assistant.rb', line 72 def initialize(username: "", password: "", workspace_id: "", storage: "hash") @cnv = Dialog.new( username: username, password: password, workspace_id: workspace_id ) if storage == "hash" @users = Hash.new else @users = Redis.new(:url => storage) end end |
Instance Method Details
#delete(user) ⇒ Object
97 98 99 |
# File 'lib/watson/assistant.rb', line 97 def delete(user) @users.delete(user) end |
#has_key?(user) ⇒ Boolean
92 93 94 |
# File 'lib/watson/assistant.rb', line 92 def has_key?(user) @users.has_key?(user) end |
#talk(user, question) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/watson/assistant.rb', line 102 def talk(user, question) future_data = nil if @users.has_key?(user) == false code, body = @cnv.talk("", "") else code, body = @cnv.talk(question, context = @users.fetch(user)) end if code == 200 context = body["context"] output = body["output"]["text"] else output = body["error"] end if code == 200 @users.store(user, context) else @users.delete(user) end return {user: user, status_code: code, output: output}.to_json end |
#users ⇒ Object
87 88 89 |
# File 'lib/watson/assistant.rb', line 87 def users() @users end |