watson-assistant-chatbot 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/watson-assistant-chatbot.rb +22 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 73c249936eb92afbf17633947de7d22e8443e6b9c16983eb8c2deee084946f67
|
4
|
+
data.tar.gz: e9c1f0cba7ede2a81b052cb9aa102aae9f901f5b5a153bb81fbe8332881fbed9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be358115b1d597d7a7e182a27748257e913a2d0825b7bddd6eb06267bb4fecf33bafa8b0791044bc4ebb7bd5e0f7b609b4efec043d1a1e7c8c175fa7dfe2d148
|
7
|
+
data.tar.gz: 5dc2fab5cd8a9e2051fa370f17b0d7b5d39add98406024f59ff0faed0ac164262d1119adbb208581921558e3f4d316ffb3037ae1d125f4b87a7672df2cc2cc43
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# chatbot.rb
|
1
|
+
# watson-assistant-chatbot.rb
|
2
2
|
# Julian I. Kamil / @juliankamil
|
3
3
|
# 2018/04/04
|
4
4
|
|
@@ -8,6 +8,7 @@ require 'json'
|
|
8
8
|
module WatsonAssistant
|
9
9
|
API_PROTOCOL = 'https'
|
10
10
|
API_SERVICE = 'assistant'
|
11
|
+
INTENT_UNDETECTED = '-- undetected --'
|
11
12
|
|
12
13
|
class Chatbot
|
13
14
|
attr_accessor :user_id, :password, :workspace_id
|
@@ -38,6 +39,26 @@ module WatsonAssistant
|
|
38
39
|
results = JSON.parse(response.to_str)
|
39
40
|
end
|
40
41
|
|
42
|
+
def conversation_id(results)
|
43
|
+
results["context"]["conversation_id"]
|
44
|
+
end
|
45
|
+
|
46
|
+
def response_text(results)
|
47
|
+
results["output"]["text"][0] if (results["output"]["text"].length > 0)
|
48
|
+
end
|
49
|
+
|
50
|
+
def intent_and_confidence(results)
|
51
|
+
if (results["intents"].length > 0)
|
52
|
+
intent = results["intents"][0]["intent"]
|
53
|
+
confidence = results["intents"][0]["confidence"]
|
54
|
+
else
|
55
|
+
intent = INTENT_UNDETECTED
|
56
|
+
confidence = '1'
|
57
|
+
end
|
58
|
+
|
59
|
+
return intent, confidence
|
60
|
+
end
|
61
|
+
|
41
62
|
private def message_url
|
42
63
|
"#{API_PROTOCOL}://#{self.class.api_domain}" \
|
43
64
|
"/#{API_SERVICE}/api/v1" \
|