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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7b154ca654d07f2cd12c6f443bbf7046ef54d1f3
4
- data.tar.gz: dbc77bed224fd5bd86dd95c829ee0b885f1c97fb
3
+ metadata.gz: 3ec771654a969d6e004c2da5c88350943facf8f4
4
+ data.tar.gz: 08c5f4e0f7c3440ad6d05a7ba3e5859cbbdad37c
5
5
  SHA512:
6
- metadata.gz: f80e5e558716bc7b6a5c51d7fcbf66f4a56e07965f7a7a66dc02c9fe766d789a2aacb0c269e76c8c347fe3bb1b72c0a2c66efb42494820e5976d321f97e95fab
7
- data.tar.gz: 8cb7380fe2917dfd782a39c2b16e7e97413f46d88e9f9cfcf1af8978f767d7023930c6a1d12163065c463ae48a0521f6500927da6187963e63b280ea8d1dcf4a
6
+ metadata.gz: 5ac7fab096ea512ea289a5cfde7004d064dfa9cb8e7843fcc0dd76bbb87a2c1b5f6ae8465d1b5bd2081e5c42334a74c2fb72bd4c09ccda5d1f09256af196f309
7
+ data.tar.gz: e016e2b76126a8f283f5b1b05887ffc9d74fc5173cb2e5b3fb7b849e0aeb61a73e14a59b1fd066295bca1baaf1f870bb4e735951522cca024ad0a3bb12641248
@@ -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, dialog_state = nil)
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
- build_ask(input_prompt, [expected_intent], dialog_state)
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(conversation_token, expect_user_response, expected_input, final_response)
104
+ def build_response(dialog_state, expect_user_response, expected_input, final_response)
108
105
  response = {}
109
106
 
110
- response[:conversation_token] = conversation_token if 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.as_json
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, :token
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
- @token = parse_token(opts["conversation_token"])
18
+ @dialog_state = DialogState.new(opts["conversation_token"])
19
19
  end
20
20
 
21
- def data
22
- if token.is_a?(Hash)
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
- if token.is_a?(Hash)
31
- token["state"]
32
- else
33
- token
34
- end
25
+ def state=(state)
26
+ dialog_state.state = state
35
27
  end
36
28
 
37
- private
29
+ def data
30
+ dialog_state.data
31
+ end
38
32
 
39
- def parse_token(token)
40
- JSON.parse(token)
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google_assistant
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Milam