google_assistant 0.0.1 → 0.0.2

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/google_assistant.rb +97 -0
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 838021e6f1b15ce2660f463f4b8f2b06c788e73e
4
- data.tar.gz: de357389e4b5d2581626d2d3809485dfbb01adb2
3
+ metadata.gz: 518fce2773a13509062ff0f27dc6fcaeb57d2392
4
+ data.tar.gz: 934a64c1c792370d11523bfde1648fbdedda4416
5
5
  SHA512:
6
- metadata.gz: 390aedc495624347510ec9cdfcc49608b7a6496a2d6be619d46ee2dfdc4f6ad3d0a014254d44123cc5620e076e401aa3849334406a2f266ce988103c1b183ea2
7
- data.tar.gz: 5aae62a0571a32a8da34ac10720b63c90be36f0794f80d81293ba9ada569561ae198000303dc574abd3296588a9448f621da68730d6c6e52e957f6529f38f190
6
+ metadata.gz: 7a963e28303b4e41653fd7abec9946c6a1fd9cbf716ad8be5ab76b100b1bdfc5fa10e1918d5c99b496133bd9be19978d82c86d0beea1af5a99d10d6be6a5d066
7
+ data.tar.gz: 87c04e6de0c3cd11ba56b0125ee33bf37d46cc91f92df456ff886314cc11f72bd26a297029cf3efb554d0044769a7c50cfe1b4c8ca264834fb16bea79c59ca6d
@@ -5,6 +5,8 @@ Dir["#{File.dirname(__FILE__)}/google_assistant/**/*.rb"].each { |file| require
5
5
  class GoogleAssistant
6
6
  attr_reader :params
7
7
 
8
+ INPUTS_MAX = 2
9
+
8
10
  def initialize(params)
9
11
  @params = params
10
12
  end
@@ -31,6 +33,64 @@ class GoogleAssistant
31
33
  build_response(nil, false, nil, final_response)
32
34
  end
33
35
 
36
+ def ask(input_prompt, dialog_state = nil)
37
+ if input_prompt.nil?
38
+ return handle_error("Invalid input prompt")
39
+ end
40
+
41
+ if input_prompt.is_a?(String)
42
+ input_prompt = build_input_prompt(is_ssml(input_prompt), input_prompt)
43
+ end
44
+
45
+ if dialog_state.nil?
46
+ dialog_state = {
47
+ state: "state", #(self.state instanceof State ? self.state.getName() : self.state),
48
+ data: "data" #self.data
49
+ }
50
+ elsif dialog_state.is_a?(Array)
51
+ return handle_error("Invalid dialog state")
52
+ end
53
+
54
+ expected_intent = build_expected_intent(StandardIntents::TEXT)
55
+
56
+ build_ask(input_prompt, [expected_intent], dialog_state)
57
+ end
58
+
59
+ def build_input_prompt(is_ssml, initial_prompt, no_inputs = [])
60
+ if no_inputs&.size > INPUTS_MAX
61
+ handle_error("Invalid number of no inputs")
62
+ return nil
63
+ end
64
+
65
+ if is_ssml
66
+ initial_prompts = [
67
+ { ssml: initial_prompt }
68
+ ]
69
+
70
+ no_input_prompts = no_inputs.map do |no_input_prompt|
71
+ { ssml: no_input_prompt }
72
+ end
73
+
74
+ {
75
+ initial_prompts: initial_prompts,
76
+ no_input_prompts: no_input_prompts
77
+ }
78
+ else
79
+ initial_prompts = [
80
+ { text_to_speech: initial_prompt }
81
+ ]
82
+
83
+ no_input_prompts = no_inputs.map do |no_input_prompt|
84
+ { text_to_speech: no_input_prompt }
85
+ end
86
+
87
+ {
88
+ initial_prompts: initial_prompts,
89
+ no_input_prompts: no_input_prompts
90
+ }
91
+ end
92
+ end
93
+
34
94
  private
35
95
 
36
96
  def build_response(conversation_token, expect_user_response, expected_input, final_response)
@@ -46,6 +106,43 @@ class GoogleAssistant
46
106
  }
47
107
  end
48
108
 
109
+ def build_ask(input_prompt, possible_intents, dialog_state = nil)
110
+ if input_prompt.nil? || input_prompt.empty?
111
+ return handle_error("Invalid input prompt")
112
+ end
113
+
114
+ if input_prompt.is_a?(String)
115
+ input_prompt = build_input_prompt(is_ssml(input_prompt), input_prompt)
116
+ end
117
+
118
+ if dialog_state.nil?
119
+ dialog_state = {
120
+ state: "state", #(self.state instanceof State ? self.state.getName() : self.state),
121
+ data: "data" #self.data
122
+ }
123
+ end
124
+
125
+ expected_inputs = [{
126
+ input_prompt: input_prompt,
127
+ possible_intents: possible_intents
128
+ }]
129
+
130
+ build_response(
131
+ dialog_state.as_json,
132
+ true,
133
+ expected_inputs,
134
+ nil
135
+ )
136
+ end
137
+
138
+ def build_expected_intent(intent)
139
+ if intent.nil? || intent == ""
140
+ return handle_error("Invalid intent")
141
+ end
142
+
143
+ { intent: intent }
144
+ end
145
+
49
146
  def is_ssml(text)
50
147
  if text.nil?
51
148
  handle_error("Missing text")
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.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Milam