alexa_web_service 1.0.0 → 1.0.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/Gemfile.lock +1 -1
- data/{README.md → Readme.md} +0 -18
- data/config.ru +3 -0
- data/example_skill/app.rb +45 -0
- data/example_skill/eight_ball.rb +62 -0
- data/example_skill/interaction_model.txt +19 -0
- data/lib/alexa_web_service/response.rb +13 -1
- data/lib/alexa_web_service/version.rb +1 -1
- data/pkg/alexa_web_service-1.0.0.gem +0 -0
- metadata +8 -4
- data/.gitignore +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 09989d6bef15da61c9a47120fa71db45b407bdd2
|
4
|
+
data.tar.gz: 863bb2bd369bd3f6983b4f4dd3d0721d4d26cf25
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 736dac5ce2ad13a50214971324343796ec5d74792840284f92549a74a119c3f155e38dce21a4815017942991dec9e5b55421e68eeb32e7fe177e15a6542e865a
|
7
|
+
data.tar.gz: 51452ddc6a39da86a913466a46361e4fe49f88199483e9e4b0d7a8dd2fe668314443065f610795d51bd6564d55b815828cb75c97c1cf04d1e8b3a13a425f50ac
|
data/Gemfile.lock
CHANGED
data/{README.md → Readme.md}
RENAMED
@@ -113,25 +113,7 @@ response.spoken_response = "This is what Alexa will say to you"
|
|
113
113
|
response.reprompt_text = "This is what she'll say if she doesn't hear your response the first time."
|
114
114
|
````
|
115
115
|
|
116
|
-
You can then send the response back to Alexa with the following command:
|
117
116
|
|
118
|
-
|
119
|
-
````Ruby
|
120
|
-
response.without_card.to_json
|
121
|
-
````
|
122
|
-
|
123
|
-
So, putting the AlexaRequest and AlexaResponse together:
|
124
|
-
|
125
|
-
````Ruby
|
126
|
-
response = AlexaWebService::Response.new
|
127
|
-
|
128
|
-
if @echo_request.launch_request
|
129
|
-
response.spoken_response = "Hello user"
|
130
|
-
response.end_session = true
|
131
|
-
end
|
132
|
-
|
133
|
-
response.without_card.to_json
|
134
|
-
````
|
135
117
|
|
136
118
|
You can use [SSML](https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/speech-synthesis-markup-language-ssml-reference):
|
137
119
|
|
data/config.ru
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'sinatra/base'
|
2
|
+
require 'alexa_web_service'
|
3
|
+
require './eight_ball'
|
4
|
+
|
5
|
+
module Sinatra
|
6
|
+
class MyApp < Sinatra::Base
|
7
|
+
|
8
|
+
set :protection, :except => [:json_csrf]
|
9
|
+
register Sinatra::EightBall
|
10
|
+
|
11
|
+
# You might need the following if you are implementing account linking.
|
12
|
+
# helpers Sinatra::Cookies
|
13
|
+
# enable :inline_templates
|
14
|
+
# enable :sessions
|
15
|
+
|
16
|
+
before do
|
17
|
+
if request.request_method == "POST"
|
18
|
+
content_type :json, 'charset' => 'utf-8'
|
19
|
+
|
20
|
+
@data = request.body.read
|
21
|
+
begin
|
22
|
+
params.merge!(JSON.parse(@data))
|
23
|
+
rescue JSON::ParserError
|
24
|
+
halt 400, "Bad Request"
|
25
|
+
end
|
26
|
+
|
27
|
+
params.merge!(JSON.parse(@data))
|
28
|
+
|
29
|
+
# The request object.
|
30
|
+
@echo_request = AlexaWebService::Request.new(JSON.parse(@data))
|
31
|
+
|
32
|
+
# Boolean: does the Alexa Device handling the response have a screen? (Needed for AlexaWebService::DisplayDirective support)
|
33
|
+
$display_support = JSON.parse(@data)["context"]["System"]["device"]["supportedInterfaces"]["Display"].any? rescue false
|
34
|
+
|
35
|
+
# This can be used in your skill as additional verification that the request is coming from the right place
|
36
|
+
@application_id = @echo_request.application_id
|
37
|
+
|
38
|
+
# If the request body has been read, you need to rewind it.
|
39
|
+
request.body.rewind
|
40
|
+
AlexaWebService::Verify.new(request.env, request.body.read)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
run!
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
ANSWER = ["absolutely!", "I doubt it", "If you want it badly enough", "yes, the stars are aligned for you", "the future is uncertain", "no chance", "you control your own destiny"]
|
4
|
+
|
5
|
+
module Sinatra
|
6
|
+
module EightBall
|
7
|
+
def self.registered(app)
|
8
|
+
app.post '/magic' do
|
9
|
+
|
10
|
+
content_type :json
|
11
|
+
|
12
|
+
# Uncomment this and include your skill id before submitting application for certification:
|
13
|
+
# halt 400, "Invalid Application ID" unless @application_id == "your-skill-id"
|
14
|
+
|
15
|
+
response = AlexaWebService::Response.new
|
16
|
+
|
17
|
+
if @echo_request.launch_request?
|
18
|
+
response.end_session = false
|
19
|
+
response.spoken_response = "I'm ready to tell your future. Ask me any yes no question."
|
20
|
+
|
21
|
+
elsif @echo_request.intent_name == "UserQuestion"
|
22
|
+
response.spoken_response = "#{ANSWER.sample}"
|
23
|
+
|
24
|
+
# Create a progressive response...
|
25
|
+
progressive_response = AlexaWebService::ProgressiveResponse.new(@echo_request, "Looking into the future")
|
26
|
+
|
27
|
+
# Create a display directive for the Show or Spot
|
28
|
+
display_template = AlexaWebService::DisplayDirective.new(type: "BodyTemplate2", token: "token", title: "Magic Eight Ball")
|
29
|
+
display_template.add_image("eight_ball_image", "https://s3-us-west-2.amazonaws.com/alexa-magic-eight-ball-demo/eight_ball.jpg")
|
30
|
+
display_template.add_text(primary_text: response.spoken_response)
|
31
|
+
|
32
|
+
# Create a card. Here we create a card with an image.
|
33
|
+
card = AlexaWebService::Card.new
|
34
|
+
card.title = "Magic Eight Ball"
|
35
|
+
card.content = "I never tell a lie"
|
36
|
+
card.small_image = "https://s3-us-west-2.amazonaws.com/alexa-magic-eight-ball-demo/eight_ball.jpg"
|
37
|
+
|
38
|
+
# Some Display Templates allow you to add hints
|
39
|
+
hint = AlexaWebService::HintDirective.new("Never trust fortune tellers!")
|
40
|
+
|
41
|
+
# Send the Progressive Response
|
42
|
+
progressive_response.post
|
43
|
+
|
44
|
+
# Add the directives to the response...
|
45
|
+
response.add_directive(hint.directive)
|
46
|
+
response.add_directive(display_template.directive)
|
47
|
+
|
48
|
+
# ...and add the card
|
49
|
+
response.add_card(card.with_image)
|
50
|
+
|
51
|
+
elsif @echo_request.session_ended_request?
|
52
|
+
response.end_session = true
|
53
|
+
elsif @echo_request.intent_name == "AMAZON.StopIntent" || @echo_request.intent_name == "AMAZON.CancelIntent"
|
54
|
+
response.end_session = true
|
55
|
+
end
|
56
|
+
|
57
|
+
response.post
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
register EightBall
|
62
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
INTENT SCHEMA:
|
2
|
+
|
3
|
+
|
4
|
+
{
|
5
|
+
"intents":[
|
6
|
+
{
|
7
|
+
"intent":"UserQuestion",
|
8
|
+
"slots":[]
|
9
|
+
}
|
10
|
+
]
|
11
|
+
}
|
12
|
+
|
13
|
+
|
14
|
+
SAMPLE UTTERANCES:
|
15
|
+
|
16
|
+
UserQuestion Is trouble coming
|
17
|
+
UserQuestion Will I be rich
|
18
|
+
UserQuestion Is my boss going to promote me
|
19
|
+
UserQuestion Tell me whether my dreams will come true
|
@@ -19,8 +19,20 @@ module AlexaWebService
|
|
19
19
|
@session_attributes.merge!(key => value)
|
20
20
|
end
|
21
21
|
|
22
|
+
def delete_attribute(key)
|
23
|
+
@session_attributes.delete(key)
|
24
|
+
end
|
25
|
+
|
26
|
+
def append_attribute(key, value)
|
27
|
+
@session_attributes[key] << value if @session_attributes[key] != nil
|
28
|
+
end
|
29
|
+
|
22
30
|
def add_directive(directive)
|
23
|
-
|
31
|
+
if directive[:type] == "Display.RenderTemplate"|| directive[:type] == "Hint"
|
32
|
+
self.directives << directive if $display_support == true
|
33
|
+
else
|
34
|
+
self.directives << directive
|
35
|
+
end
|
24
36
|
end
|
25
37
|
|
26
38
|
def add_card(card)
|
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alexa_web_service
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sarkonovich
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-03-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -94,14 +94,17 @@ executables: []
|
|
94
94
|
extensions: []
|
95
95
|
extra_rdoc_files: []
|
96
96
|
files:
|
97
|
-
- ".gitignore"
|
98
97
|
- Gemfile
|
99
98
|
- Gemfile.lock
|
100
|
-
- README.md
|
101
99
|
- Rakefile
|
100
|
+
- Readme.md
|
102
101
|
- alexa_web_service.gemspec
|
103
102
|
- bin/console
|
104
103
|
- bin/setup
|
104
|
+
- config.ru
|
105
|
+
- example_skill/app.rb
|
106
|
+
- example_skill/eight_ball.rb
|
107
|
+
- example_skill/interaction_model.txt
|
105
108
|
- lib/alexa_web_service.rb
|
106
109
|
- lib/alexa_web_service/card.rb
|
107
110
|
- lib/alexa_web_service/display_directive.rb
|
@@ -111,6 +114,7 @@ files:
|
|
111
114
|
- lib/alexa_web_service/response.rb
|
112
115
|
- lib/alexa_web_service/verify.rb
|
113
116
|
- lib/alexa_web_service/version.rb
|
117
|
+
- pkg/alexa_web_service-1.0.0.gem
|
114
118
|
homepage: https://github.com/sarkonovich/Alexa-Web-Service
|
115
119
|
licenses:
|
116
120
|
- MIT
|