alexa_toolbox 1.0.3 → 1.0.4
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 +57 -0
- data/lib/alexa_toolbox/display_directive.rb +27 -0
- data/lib/alexa_toolbox/display_directive_image.rb +78 -0
- data/lib/alexa_toolbox/display_directive_template.rb +66 -0
- data/lib/alexa_toolbox/display_directive_text_content.rb +58 -0
- data/lib/alexa_toolbox/response.rb +4 -0
- data/lib/alexa_toolbox/version.rb +1 -1
- data/lib/alexa_toolbox.rb +1 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d512122e81904260c84fa1820a5611561e70e32a
|
4
|
+
data.tar.gz: 2fdb9f22ad05544f87aa4afb014204ba117a108d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7511ebd8464acf9d9c8eb6fbe0eda787262e04779547ecbce51d5fdf92baac367f734c8ef88de7812f9a6a77a55ba550b5da1bab46fe0a796643eb808338716a
|
7
|
+
data.tar.gz: 82b839225d71eff9e1803ec69c23a6a1c5af74cd311958cc9add80791e2ddc828c6d091ba178f41b016948929e8b1dae8e3c4ebc2e2f0b8ce18358f70dca2259
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -342,6 +342,63 @@ request.context
|
|
342
342
|
|
343
343
|
### Address
|
344
344
|
|
345
|
+
### DisplayDirective
|
346
|
+
|
347
|
+
You can display content on the new Echo Show using the predefined templates.
|
348
|
+
[Amazon Official Documentation Reference](https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/display-interface-reference)
|
349
|
+
|
350
|
+
#### Examples
|
351
|
+
|
352
|
+
##### BodyTemplate1 Example
|
353
|
+
|
354
|
+
```ruby
|
355
|
+
response = AlexaToolbox::Response.new
|
356
|
+
display_directive = AlexaToolbox::DisplayDirective.new("BodyTemplate1","Winner")
|
357
|
+
display_directive.template.add_title("You won!")
|
358
|
+
display_directive.template.hide_back_button
|
359
|
+
display_directive.template.background_image.set_content_description("Description of image")
|
360
|
+
display_directive.template.background_image.add_source("https://placeholder.com/placeholder_image.jpg")
|
361
|
+
response.add_display_directive_object(display_directive)
|
362
|
+
```
|
363
|
+
|
364
|
+
##### BodyTemplate3 Example
|
365
|
+
|
366
|
+
```ruby
|
367
|
+
response = AlexaToolbox::Response.new
|
368
|
+
display_directive = AlexaToolbox::DisplayDirective.new("BodyTemplate3","SampleCard_92347")
|
369
|
+
display_directive.template.add_title("Body Template Title Example")
|
370
|
+
display_directive.template.hide_back_button
|
371
|
+
display_directive.template.text_content.add_primary_text("Example of text content. This content contains <b>bold text</b>, <i>italics</i>, and <br/> line breaks.","RichText")
|
372
|
+
image = AlexaToolbox::DisplayDirectiveImage.new("Mount St. Helens landscape","https://example.com/resources/card-images/mount-saint-helen-small.png")
|
373
|
+
display_directive.template.add_image_object(image)
|
374
|
+
response.add_display_directive_object(display_directive)
|
375
|
+
```
|
376
|
+
|
377
|
+
##### ListTemplate2 Example
|
378
|
+
|
379
|
+
```ruby
|
380
|
+
response = AlexaToolbox::Response.new
|
381
|
+
|
382
|
+
display_directive = AlexaToolbox::DisplayDirective.new("ListTemplate2","list_template_two")
|
383
|
+
display_directive.template.add_title("Pizzas")
|
384
|
+
display_directive.template.hide_back_button
|
385
|
+
|
386
|
+
list_text = AlexaToolbox::DisplayDirectiveTextContent.new
|
387
|
+
list_text.add_primary_text("<font size='7'>Supreme</font> <br/> Large Pan Pizza $17.00","RichText")
|
388
|
+
list_text.add_secondary_text("Secondary Text")
|
389
|
+
list_text.add_tertiary_text("")
|
390
|
+
list_image = AlexaToolbox::DisplayDirectiveImage.new("Supreme Large Pan Pizza","http://www.example.com/images/thumb/SupremePizza1.jpg")
|
391
|
+
display_directive.template.add_item_to_list("item_1",list_image,list_text)
|
392
|
+
|
393
|
+
list_text = AlexaToolbox::DisplayDirectiveTextContent.new
|
394
|
+
list_text.add_primary_text("<font size='7'>Meat Lovers</font> <br/> Large Pan Pizza $17.00","RichText")
|
395
|
+
list_image = AlexaToolbox::DisplayDirectiveImage.new("Meat Lovers Large Pan Pizza","http://www.example.com/images/thumb/MeatLoversPizza1.jpg")
|
396
|
+
display_directive.template.add_item_to_list("item_2",list_image,list_text)
|
397
|
+
|
398
|
+
response.add_display_directive_object(display_directive)
|
399
|
+
```
|
400
|
+
|
401
|
+
|
345
402
|
|
346
403
|
## Troubleshooting
|
347
404
|
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module AlexaToolbox
|
2
|
+
# Handles creating display directives in responses.
|
3
|
+
# https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/display-interface-reference
|
4
|
+
class DisplayDirective
|
5
|
+
require 'json'
|
6
|
+
require 'alexa_toolbox/display_directive_template'
|
7
|
+
|
8
|
+
attr_accessor :type, :template
|
9
|
+
|
10
|
+
def initialize(template,token)
|
11
|
+
@type = "Display.RenderTemplate"
|
12
|
+
if ["BodyTemplate1","BodyTemplate2","BodyTemplate3","BodyTemplate6","ListTemplate1","ListTemplate2","ListTemplate3"].include?(template)
|
13
|
+
@template = AlexaToolbox::DisplayDirectiveTemplate.new(template,token)
|
14
|
+
else
|
15
|
+
raise ArgumentError, 'Invalid display template given. Valid options are: "BodyTemplate1","BodyTemplate2","BodyTemplate3","BodyTemplate6","ListTemplate1","ListTemplate2","ListTemplate3"'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def build_directive(json = true)
|
20
|
+
data_hash = {
|
21
|
+
"type": @type,
|
22
|
+
"template": @template.build
|
23
|
+
}
|
24
|
+
json ? JSON.parse(data_hash.to_json) : data_hash
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module AlexaToolbox
|
2
|
+
# Handles creating display directives in responses.
|
3
|
+
class DisplayDirectiveImage
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
attr_accessor :content_description, :sources
|
7
|
+
|
8
|
+
def initialize(content_description = "", url = nil)
|
9
|
+
@content_description = content_description
|
10
|
+
@sources = []
|
11
|
+
if !url.nil?
|
12
|
+
self.add_xsmall_source(url)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def set_content_description(text)
|
17
|
+
@content_description = text
|
18
|
+
end
|
19
|
+
|
20
|
+
def add_source(url,size = "X_SMALL",widthPixels = nil,heightPixels = nil)
|
21
|
+
source = {
|
22
|
+
url: url,
|
23
|
+
size: size
|
24
|
+
}
|
25
|
+
source[:widthPixels] = widthPixels if !widthPixels.nil?
|
26
|
+
source[:heightPixels] = heightPixels if !heightPixels.nil?
|
27
|
+
@sources.push(source)
|
28
|
+
end
|
29
|
+
|
30
|
+
def add_xsmall_source(url)
|
31
|
+
@sources.push({
|
32
|
+
url: url,
|
33
|
+
size: "X_SMALL"
|
34
|
+
})
|
35
|
+
end
|
36
|
+
|
37
|
+
def add_small_source(url)
|
38
|
+
@sources.push({
|
39
|
+
url: url,
|
40
|
+
size: "SMALL"
|
41
|
+
})
|
42
|
+
end
|
43
|
+
|
44
|
+
def add_medium_source(url)
|
45
|
+
@sources.push({
|
46
|
+
url: url,
|
47
|
+
size: "MEDIUM"
|
48
|
+
})
|
49
|
+
end
|
50
|
+
|
51
|
+
def add_large_source(url)
|
52
|
+
@sources.push({
|
53
|
+
url: url,
|
54
|
+
size: "LARGE"
|
55
|
+
})
|
56
|
+
end
|
57
|
+
|
58
|
+
def add_xlarge_source(url)
|
59
|
+
@sources.push({
|
60
|
+
url: url,
|
61
|
+
size: "X_LARGE"
|
62
|
+
})
|
63
|
+
end
|
64
|
+
|
65
|
+
def valid?
|
66
|
+
@content_description.length > 0 && @sources.count > 0
|
67
|
+
end
|
68
|
+
|
69
|
+
def build
|
70
|
+
data_hash = {
|
71
|
+
contentDescription: @content_description,
|
72
|
+
sources: @sources
|
73
|
+
}
|
74
|
+
data_hash
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module AlexaToolbox
|
2
|
+
# Handles creating display directives in responses.
|
3
|
+
class DisplayDirectiveTemplate
|
4
|
+
require 'json'
|
5
|
+
require 'alexa_toolbox/display_directive_image'
|
6
|
+
require 'alexa_toolbox/display_directive_text_content'
|
7
|
+
|
8
|
+
attr_accessor :type, :token, :back_button, :background_image, :title, :text_content, :list_items
|
9
|
+
|
10
|
+
def initialize(type,token,title = nil,back_button = "VISIBLE")
|
11
|
+
@type = type
|
12
|
+
@token = token
|
13
|
+
@back_button = back_button
|
14
|
+
@background_image = AlexaToolbox::DisplayDirectiveImage.new
|
15
|
+
@title = title
|
16
|
+
@text_content = AlexaToolbox::DisplayDirectiveTextContent.new
|
17
|
+
@list_items = []
|
18
|
+
@image = nil
|
19
|
+
end
|
20
|
+
|
21
|
+
def set_token(token)
|
22
|
+
@token = token
|
23
|
+
end
|
24
|
+
|
25
|
+
def hide_back_button
|
26
|
+
@back_button = "HIDDEN"
|
27
|
+
end
|
28
|
+
|
29
|
+
def show_back_button
|
30
|
+
@back_button = "VISIBLE"
|
31
|
+
end
|
32
|
+
|
33
|
+
def add_title(title)
|
34
|
+
@title = title
|
35
|
+
end
|
36
|
+
|
37
|
+
def add_image_object(image)
|
38
|
+
@image = image
|
39
|
+
end
|
40
|
+
|
41
|
+
def add_item_to_list(token,image,text_content)
|
42
|
+
@list_items.push({
|
43
|
+
token: token,
|
44
|
+
image: image.build,
|
45
|
+
textContent: text_content.build
|
46
|
+
})
|
47
|
+
end
|
48
|
+
|
49
|
+
def build
|
50
|
+
template = {
|
51
|
+
:type => @type,
|
52
|
+
:token => @token,
|
53
|
+
:backButton => @back_button
|
54
|
+
}
|
55
|
+
template[:backgroundImage] = @background_image.build if @background_image.valid?
|
56
|
+
template[:title] = @title if !@title.nil? && @title.length > 0
|
57
|
+
template[:textContent] = @text_content.build if @text_content.valid?
|
58
|
+
template[:image] = @image.build if !@image.nil? && ["ListTemplate1","ListTemplate2","ListTemplate3","BodyTemplate2","BodyTemplate3","BodyTemplate6"].include?(@type)
|
59
|
+
template[:listItems] = @list_items if !@list_items.empty?
|
60
|
+
|
61
|
+
|
62
|
+
template
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module AlexaToolbox
|
2
|
+
# Handles creating display directives in responses.
|
3
|
+
class DisplayDirectiveTextContent
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
attr_accessor :text_content
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@text_content = {}
|
10
|
+
end
|
11
|
+
|
12
|
+
def add_text(slot,text,type = "PlainText")
|
13
|
+
if ["primary","tertiary","secondary"].include?(slot)
|
14
|
+
@text_content[slot + "Text"] = {
|
15
|
+
text: text,
|
16
|
+
type: type
|
17
|
+
}
|
18
|
+
elsif ["primaryText","secondaryText","tertiaryText"].include?(slot)
|
19
|
+
@text_content[slot] = {
|
20
|
+
text: text,
|
21
|
+
type: type
|
22
|
+
}
|
23
|
+
else
|
24
|
+
raise ArgumentError, 'Invalid text type given. Valid options are: "primary","tertiary","secondary","primaryText","secondaryText","tertiaryText"'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def add_primary_text(text,type = "PlainText")
|
29
|
+
@text_content["primaryText"] = {
|
30
|
+
text: text,
|
31
|
+
type: type
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
def add_secondary_text(text,type = "PlainText")
|
36
|
+
@text_content["secondaryText"] = {
|
37
|
+
text: text,
|
38
|
+
type: type
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
def add_tertiary_text(text,type = "PlainText")
|
43
|
+
@text_content["tertiaryText"] = {
|
44
|
+
text: text,
|
45
|
+
type: type
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
def valid?
|
50
|
+
@text_content != {}
|
51
|
+
end
|
52
|
+
|
53
|
+
def build
|
54
|
+
@text_content
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
@@ -50,6 +50,10 @@ module AlexaToolbox
|
|
50
50
|
def add_ssml_reprompt(speech_text)
|
51
51
|
@reprompt = { "outputSpeech" => { :type => 'SSML', :ssml => check_ssml(speech_text) } }
|
52
52
|
end
|
53
|
+
|
54
|
+
def add_display_directive_object(display_directive)
|
55
|
+
@directives << display_directive.build_directive
|
56
|
+
end
|
53
57
|
|
54
58
|
def add_audio_play_directive(url, play_behavior = '', token = '', expected_previous_token = '', offset = 0)
|
55
59
|
directive = {
|
data/lib/alexa_toolbox.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alexa_toolbox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul McMahon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-07-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -94,6 +94,10 @@ files:
|
|
94
94
|
- lib/alexa_toolbox/address.rb
|
95
95
|
- lib/alexa_toolbox/audioplayer.rb
|
96
96
|
- lib/alexa_toolbox/context.rb
|
97
|
+
- lib/alexa_toolbox/display_directive.rb
|
98
|
+
- lib/alexa_toolbox/display_directive_image.rb
|
99
|
+
- lib/alexa_toolbox/display_directive_template.rb
|
100
|
+
- lib/alexa_toolbox/display_directive_text_content.rb
|
97
101
|
- lib/alexa_toolbox/intent.rb
|
98
102
|
- lib/alexa_toolbox/request.rb
|
99
103
|
- lib/alexa_toolbox/response.rb
|