google_assistant 0.0.5 → 0.0.6
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/google_assistant.rb +15 -44
- data/lib/google_assistant/conversation.rb +11 -19
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ec771654a969d6e004c2da5c88350943facf8f4
|
4
|
+
data.tar.gz: 08c5f4e0f7c3440ad6d05a7ba3e5859cbbdad37c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ac7fab096ea512ea289a5cfde7004d064dfa9cb8e7843fcc0dd76bbb87a2c1b5f6ae8465d1b5bd2081e5c42334a74c2fb72bd4c09ccda5d1f09256af196f309
|
7
|
+
data.tar.gz: e016e2b76126a8f283f5b1b05887ffc9d74fc5173cb2e5b3fb7b849e0aeb61a73e14a59b1fd066295bca1baaf1f870bb4e735951522cca024ad0a3bb12641248
|
data/lib/google_assistant.rb
CHANGED
@@ -6,8 +6,6 @@ class GoogleAssistant
|
|
6
6
|
attr_reader :params
|
7
7
|
attr_reader :response
|
8
8
|
|
9
|
-
INPUTS_MAX = 2
|
10
|
-
|
11
9
|
def initialize(params, response)
|
12
10
|
@params = params
|
13
11
|
@response = response
|
@@ -47,7 +45,7 @@ class GoogleAssistant
|
|
47
45
|
build_response(nil, false, nil, final_response)
|
48
46
|
end
|
49
47
|
|
50
|
-
def ask(input_prompt
|
48
|
+
def ask(input_prompt)
|
51
49
|
if input_prompt.nil?
|
52
50
|
return handle_error("Invalid input prompt")
|
53
51
|
end
|
@@ -56,23 +54,22 @@ class GoogleAssistant
|
|
56
54
|
input_prompt = build_input_prompt(is_ssml(input_prompt), input_prompt)
|
57
55
|
end
|
58
56
|
|
59
|
-
if dialog_state.nil?
|
60
|
-
dialog_state = { state: nil, data: {} }.to_json
|
61
|
-
elsif dialog_state.is_a?(Array)
|
62
|
-
return handle_error("Invalid dialog state")
|
63
|
-
end
|
64
|
-
|
65
57
|
expected_intent = build_expected_intent(StandardIntents::TEXT)
|
66
58
|
|
67
|
-
|
59
|
+
expected_inputs = [{
|
60
|
+
input_prompt: input_prompt,
|
61
|
+
possible_intents: [expected_intent]
|
62
|
+
}]
|
63
|
+
|
64
|
+
build_response(
|
65
|
+
conversation.dialog_state,
|
66
|
+
true,
|
67
|
+
expected_inputs,
|
68
|
+
nil
|
69
|
+
)
|
68
70
|
end
|
69
71
|
|
70
72
|
def build_input_prompt(is_ssml, initial_prompt, no_inputs = [])
|
71
|
-
if no_inputs&.size > INPUTS_MAX
|
72
|
-
handle_error("Invalid number of no inputs")
|
73
|
-
return nil
|
74
|
-
end
|
75
|
-
|
76
73
|
if is_ssml
|
77
74
|
initial_prompts = [
|
78
75
|
{ ssml: initial_prompt }
|
@@ -104,45 +101,19 @@ class GoogleAssistant
|
|
104
101
|
|
105
102
|
private
|
106
103
|
|
107
|
-
def build_response(
|
104
|
+
def build_response(dialog_state, expect_user_response, expected_input, final_response)
|
108
105
|
response = {}
|
109
106
|
|
110
|
-
response[:conversation_token] =
|
107
|
+
response[:conversation_token] = dialog_state.to_json if dialog_state
|
111
108
|
response[:expect_user_response] = expect_user_response
|
112
109
|
response[:expected_inputs] = expected_input if expected_input
|
113
110
|
response[:final_response] = final_response if !expect_user_response && final_response
|
114
111
|
|
115
112
|
{
|
116
|
-
json: response
|
113
|
+
json: response
|
117
114
|
}
|
118
115
|
end
|
119
116
|
|
120
|
-
def build_ask(input_prompt, possible_intents, dialog_state = nil)
|
121
|
-
if input_prompt.nil? || input_prompt.empty?
|
122
|
-
return handle_error("Invalid input prompt")
|
123
|
-
end
|
124
|
-
|
125
|
-
if input_prompt.is_a?(String)
|
126
|
-
input_prompt = build_input_prompt(is_ssml(input_prompt), input_prompt)
|
127
|
-
end
|
128
|
-
|
129
|
-
if dialog_state.nil?
|
130
|
-
dialog_state = { state: nil, data: {} }.to_json
|
131
|
-
end
|
132
|
-
|
133
|
-
expected_inputs = [{
|
134
|
-
input_prompt: input_prompt,
|
135
|
-
possible_intents: possible_intents
|
136
|
-
}]
|
137
|
-
|
138
|
-
build_response(
|
139
|
-
dialog_state,
|
140
|
-
true,
|
141
|
-
expected_inputs,
|
142
|
-
nil
|
143
|
-
)
|
144
|
-
end
|
145
|
-
|
146
117
|
def build_expected_intent(intent)
|
147
118
|
if intent.nil? || intent == ""
|
148
119
|
return handle_error("Invalid intent")
|
@@ -10,36 +10,28 @@ class GoogleAssistant
|
|
10
10
|
ARCHIVED = 4
|
11
11
|
end
|
12
12
|
|
13
|
-
attr_reader :id, :type, :
|
13
|
+
attr_reader :id, :type, :dialog_state
|
14
14
|
|
15
15
|
def initialize(opts)
|
16
16
|
@id = opts["conversation_id"]
|
17
17
|
@type = opts["type"]
|
18
|
-
@
|
18
|
+
@dialog_state = DialogState.new(opts["conversation_token"])
|
19
19
|
end
|
20
20
|
|
21
|
-
def
|
22
|
-
|
23
|
-
token["data"]
|
24
|
-
else
|
25
|
-
token
|
26
|
-
end
|
21
|
+
def state
|
22
|
+
dialog_state.state
|
27
23
|
end
|
28
24
|
|
29
|
-
def state
|
30
|
-
|
31
|
-
token["state"]
|
32
|
-
else
|
33
|
-
token
|
34
|
-
end
|
25
|
+
def state=(state)
|
26
|
+
dialog_state.state = state
|
35
27
|
end
|
36
28
|
|
37
|
-
|
29
|
+
def data
|
30
|
+
dialog_state.data
|
31
|
+
end
|
38
32
|
|
39
|
-
def
|
40
|
-
|
41
|
-
rescue JSON::ParserError, TypeError
|
42
|
-
token
|
33
|
+
def data=(data)
|
34
|
+
dialog_state.data = data
|
43
35
|
end
|
44
36
|
end
|
45
37
|
end
|