alexa_skillsimulator 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 92f8afa4b48177f0c1e299c891f29ce9af26e196
4
- data.tar.gz: c05465e54982168584b67333d67c78110f47b74a
3
+ metadata.gz: ffc1b176b365392be314945733ba137b7db5edef
4
+ data.tar.gz: c8f8a2045047e82c6dbb28e1c98e7a02a6b3e277
5
5
  SHA512:
6
- metadata.gz: b0ba1262c8a565f0255b611dc33eb65f6e4b5983086fd208036a926533eb41185cd4c0e214bffd97f89c2bc7f5b43cd0cbf77149e01017b4fdfd8f18352e177e
7
- data.tar.gz: a039b70f71a2f39ec4e02ba5f3a294d8a9aa18eced01e653aa4bffa016f44b8c0d93468fc4c16e1ef64805dc2f14975c7edbd36c67ae3166e7dd192fabcc7337
6
+ metadata.gz: 100a3a7c1dbb4a328ff8c867f52d64edbbd982e882fd787cf9b9b5cf88b9a7fc13cdef744f909c6ee3576c045249947fc155f5c0560b52238cfef948c5e4bee1
7
+ data.tar.gz: c9cd8a1db62befba27c7dea325a4d50a9596dca2dae8d6ce26576f795c38f795cfa0624a4190becaea5e04a72cfd61f7f5500725aabb8ec459770a33b9da43af
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -4,16 +4,84 @@
4
4
 
5
5
  require 'time'
6
6
  require 'rest-client'
7
+ require 'console_cmdr'
7
8
  require 'securerandom'
8
9
 
9
10
 
11
+ class AlexaShell < ConsoleCmdr
12
+
13
+ def initialize(manifest, model, debug: false)
14
+ @alexa = AlexaSkillSimulator.new(manifest, model, debug: debug)
15
+ super(debug: debug)
16
+ end
17
+
18
+ def start()
19
+ super()
20
+ end
21
+
22
+ def display_output(s='')
23
+
24
+ print s + "\n\n => Alexa is ready\n\n> "
25
+
26
+ end
27
+
28
+ protected
29
+
30
+ def clear_cli()
31
+ end
32
+
33
+ def cli_banner()
34
+ puts
35
+ puts 'Starting ... (to exit press CTRL-C)'
36
+ puts
37
+ puts 'Alexa is ready'
38
+ puts
39
+ print '> '
40
+ end
41
+
42
+ def on_enter(raw_command)
43
+
44
+ command = raw_command.downcase
45
+
46
+ puts 'on_enter: ' + command.inspect if @debug
47
+
48
+ if command =~ /^what can i say/ then
49
+ return "you can say the following: \n\n" \
50
+ + "open #{@alexa.invocation}\n" + @alexa.utterances.keys.join("\n")
51
+ end
52
+
53
+ return (@running=false; '' ) if command.downcase =~ /^bye|quit|stop|exit$/
54
+
55
+ return false unless command =~ /^open|tell|ask$/
56
+
57
+ response = @alexa.ask command.downcase
58
+ "Alexa says: " + response
59
+
60
+
61
+ end
62
+
63
+ def on_keypress(key)
64
+ @running = false if key == :ctrl_c
65
+ super(key)
66
+ end
67
+
68
+ end
69
+
70
+
10
71
  class AlexaSkillSimulator
11
72
 
73
+ attr_reader :invocation, :utterances
12
74
 
13
75
  def initialize(manifest, model, debug: false)
14
76
 
15
77
  @debug = debug
16
78
 
79
+ @locale = manifest['manifest']['publishingInformation']['locales']\
80
+ .keys.first
81
+ puts '@locale: ' + @locale.inspect if @debug
82
+
83
+ @invocation = model['interactionModel']['languageModel']['invocationName']
84
+
17
85
  # get the utterances
18
86
 
19
87
  @utterances = model['interactionModel']['languageModel']\
@@ -30,41 +98,63 @@ class AlexaSkillSimulator
30
98
  puts ' debugger: @endpoint: ' + @endpoint.inspect if @debug
31
99
 
32
100
  end
33
-
34
- def start()
35
-
101
+
102
+ def ask(s)
103
+
36
104
  puts
37
- puts 'Starting ... (to exit press CTRL-C)'
38
-
39
- while true do
105
+ puts ' debugger: s: ' + s.inspect if @debug
106
+
107
+ invocation = @invocation.gsub(/ /,'\s')
108
+
109
+ regex = %r{
40
110
 
41
- puts
42
- puts 'Alexa is ready'
43
- puts
44
- print '> '
45
- s = gets.downcase.chomp
46
- puts
47
- puts ' debugger: s: ' + s.inspect if @debug
111
+ (?<ask>(?<action>tell|ask)\s#{invocation}\s(?<request>.*)){0}
112
+ (?<open>(?<action>open)\s#{invocation}){0}
113
+ \g<ask>|\g<open>
114
+ }x
115
+
116
+ r2 = s.match(regex)
117
+
118
+ puts ' debugger: r2: ' + r2.inspect if @debug
119
+ puts
120
+
121
+ response = if r2 then
122
+
123
+ case r2[:action]
124
+
125
+ when 'open'
48
126
 
49
- r = @utterances[s]
50
- puts ' debugger: r: ' + r.inspect if @debug
51
- puts
127
+ respond()
128
+
129
+ else
130
+
131
+ r = @utterances[r2[:request]]
132
+ puts ' debugger: r: ' + r.inspect if @debug
133
+ puts
52
134
 
53
- if r then
135
+ if r then
54
136
 
55
- puts ' debugger: your intent is to ' + r if @debug
137
+ puts ' debugger: your intent is to ' + r if @debug
56
138
 
57
- response = respond()
58
- puts "Alexa says: " + response
139
+ respond(r)
140
+
141
+ else
142
+ "I'm sorry I didn't understand what you said"
143
+ end
59
144
 
60
- else
61
- puts "Alexa says: I'm sorry I didn't understand what you said"
62
145
  end
63
-
146
+
147
+ else
148
+
149
+ "hmmm, I don't know that one."
150
+
64
151
  end
65
-
152
+
153
+ response
154
+
66
155
  end
67
156
 
157
+
68
158
  private
69
159
 
70
160
  def post(url, h)
@@ -101,16 +191,30 @@ class AlexaSkillSimulator
101
191
  "apiEndpoint"=>"https://api.eu.amazonalexa.com",
102
192
  "apiAccessToken"=>
103
193
  "A"}},
104
- "request"=>
105
- {"type"=>"LaunchRequest",
106
- "requestId"=>"amzn1.echo-api.request.a",
107
- "timestamp"=> Time.now.utc.iso8601,
108
- "locale"=>"en-US",
109
- "shouldLinkResultBeReturned"=>false}}
110
-
194
+ "request"=> {}
195
+ }
196
+
197
+ h['request'] = if intent then
198
+ {
199
+ "type"=>"IntentRequest",
200
+ "requestId"=>"amzn1.echo-api.request.0",
201
+ "timestamp"=>Time.now.utc.iso8601,
202
+ "locale"=>@locale,
203
+ "intent"=>{"name"=>intent, "confirmationStatus"=>"NONE"},
204
+ "dialogState"=>"STARTED"
205
+ }
206
+ else
207
+ {
208
+ "type"=>"LaunchRequest",
209
+ "requestId"=>"amzn1.echo-api.request.a",
210
+ "timestamp"=> Time.now.utc.iso8601,
211
+ "locale"=>@locale,
212
+ "shouldLinkResultBeReturned"=>false
213
+ }
214
+ end
215
+
111
216
  r = post @endpoint, h
112
217
  puts ' degbugger: r: ' + r.inspect if @debug
113
- puts
114
218
 
115
219
  r[:response][:outputSpeech][:text]
116
220
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alexa_skillsimulator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -52,6 +52,26 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: 2.0.2
55
+ - !ruby/object:Gem::Dependency
56
+ name: console_cmdr
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.5'
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 0.5.0
65
+ type: :runtime
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - "~>"
70
+ - !ruby/object:Gem::Version
71
+ version: '0.5'
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 0.5.0
55
75
  description:
56
76
  email: james@jamesrobertson.eu
57
77
  executables: []
metadata.gz.sig CHANGED
Binary file