alexa-rails 0.1.5 → 0.1.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 +4 -4
- data/README.md +50 -12
- data/lib/alexa/intent_handlers/base.rb +0 -13
- data/lib/alexa/response.rb +13 -9
- data/lib/alexa/responses/bye.rb +1 -1
- data/lib/alexa/responses/permission_consents/device_address.rb +1 -1
- data/lib/alexa/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d03309523af0c0f06a2dafb3591955407d52e00cd7f9760525e52b38349e7dc8
|
4
|
+
data.tar.gz: 7d10169cac5df98db050a0095cbac14d051ab8e68e23059a7b4f2e7988d15a62
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd6f5a97942b6bdf85bd308f009456bff0b876b9bb34a6bc6fdffe7ca4abbd0dcca32a9d18cfee92a53b7a3d45371410f2685a66cb7c054e33f2734cded96374
|
7
|
+
data.tar.gz: 337b0cb337acc5ecac5d2baaad60a5b48c3b0ae132881eb9fc64bd82c5ddef896953df1d1402982a560ad4dadb0c4414a96834aa83540a6493eca01f61a8360a
|
data/README.md
CHANGED
@@ -65,7 +65,7 @@ module Alexa
|
|
65
65
|
class PlaceOrder < Alexa::IntentHandlers::Base
|
66
66
|
def handle
|
67
67
|
...
|
68
|
-
response # intent handlers should always return the +response+ object
|
68
|
+
response # intent handlers should always return the +response+ object
|
69
69
|
end
|
70
70
|
end
|
71
71
|
end
|
@@ -74,7 +74,7 @@ end
|
|
74
74
|
|
75
75
|
All intent handlers should contain a `#handle` method that has required logic
|
76
76
|
as to how to handle the intent request. For example, adding session variables,
|
77
|
-
setting response to elicit slots, delegate etc.
|
77
|
+
setting response to elicit slots, delegate etc.
|
78
78
|
|
79
79
|
**Note**: `#handle` method should always return the `response` object.
|
80
80
|
`response` object in available in the scope of `#handle`.
|
@@ -100,12 +100,12 @@ slot and the respecitve views are used.
|
|
100
100
|
response.elicit_slot!(:SlotName)
|
101
101
|
```
|
102
102
|
|
103
|
-
####
|
103
|
+
#### Delegate response
|
104
104
|
|
105
105
|
`#handle` is expected to return an instance of `Alexa::Response` or its subclasses.
|
106
|
-
In normal cases, the `response` object is returned.
|
107
|
-
In cases where the slots elicitation is delegated to alexa, an instance of
|
108
|
-
`Alexa::Responses::Delegate` has to be returned.
|
106
|
+
In normal cases, the `response` object is returned.
|
107
|
+
In cases where the slots elicitation is delegated to alexa, an instance of
|
108
|
+
`Alexa::Responses::Delegate` has to be returned.
|
109
109
|
|
110
110
|
```ruby
|
111
111
|
def handle
|
@@ -116,17 +116,17 @@ In cases where the slots elicitation is delegated to alexa, an instance of
|
|
116
116
|
|
117
117
|
### Views
|
118
118
|
|
119
|
-
The content for
|
119
|
+
The content for SSML and display cards is not set in the intent handler
|
120
120
|
classes.
|
121
121
|
We follow rails convention and expect all response content for intents to be
|
122
|
-
in their respective view files.
|
122
|
+
in their respective `default` view files.
|
123
123
|
|
124
124
|
Also, the views are context locale dependant.
|
125
125
|
|
126
126
|
Given an intent named `PlaceOrder`, you view files would be
|
127
127
|
|
128
|
-
* SSML: `views/alexa/en_us/intent_handlers/place_order/
|
129
|
-
* Card: `views/alexa/en_us/intent_handlers/place_order/
|
128
|
+
* SSML: `views/alexa/en_us/intent_handlers/place_order/default.ssml.erb`
|
129
|
+
* Card: `views/alexa/en_us/intent_handlers/place_order/default.text.erb`
|
130
130
|
|
131
131
|
In case of slot elicitations, follow a similar convention but make sure you
|
132
132
|
name the `ssml` and `text` files with the same name as the slot that is being
|
@@ -136,6 +136,25 @@ slot would have the following views
|
|
136
136
|
* SSML: `views/alexa/en_us/intent_handlers/place_order/elicitations/address.ssml.erb`
|
137
137
|
* Card: `views/alexa/en_us/intent_handlers/place_order/elicitations/address.text.erb`
|
138
138
|
|
139
|
+
##### Render custom template instead of default
|
140
|
+
|
141
|
+
If you wish to force the `response` object to take contents from a different
|
142
|
+
template file instead of `default.*.erb`, pass the custom filename with
|
143
|
+
`Alexa::Response#with(template: )`.
|
144
|
+
|
145
|
+
For example: Instead of `default`, if you wish to render the contents of
|
146
|
+
`no_results.ssml.erb` and `no_results.text.erb`, return the response by forcing
|
147
|
+
the template with the following:
|
148
|
+
|
149
|
+
```ruby
|
150
|
+
def handle
|
151
|
+
...
|
152
|
+
return response.with(template: :no_results)
|
153
|
+
end
|
154
|
+
```
|
155
|
+
and make sure you add your contents in the `no_results.*.erb` files in your
|
156
|
+
intent handlers' views' directory.
|
157
|
+
|
139
158
|
#### SSML
|
140
159
|
|
141
160
|
##### Re-prompts
|
@@ -170,11 +189,30 @@ view file for the response as follows:
|
|
170
189
|
|
171
190
|
```
|
172
191
|
|
192
|
+
##### Permission cards
|
193
|
+
|
194
|
+
To render a permission card. Use `ask_for_permissions_consent` as the `card_type`
|
195
|
+
and provide the scope in `permissions_scope` content_for block.
|
196
|
+
Following is an example for Device address permission card.
|
197
|
+
|
198
|
+
```erb
|
199
|
+
<% content_for :card_type do %>
|
200
|
+
ask_for_permissions_consent
|
201
|
+
<% end %>
|
202
|
+
|
203
|
+
<% content_for :permissions_scope do %>
|
204
|
+
read::alexa:device:all:address
|
205
|
+
<% end %>
|
206
|
+
```
|
207
|
+
|
208
|
+
*Note*: The permission card should not have any other content other than the
|
209
|
+
content for `card_type` and `permissions_scope`.
|
210
|
+
|
173
211
|
## Handling Amazon's Built-in Intents / Other request types
|
174
212
|
|
175
213
|
Requests for Amazon's built-in intents and other request types
|
176
|
-
are also handled with intent handlers.
|
177
|
-
Below is the mapping for every request type and respective
|
214
|
+
are also handled with intent handlers.
|
215
|
+
Below is the mapping for every request type and respective
|
178
216
|
intent handler classes.
|
179
217
|
These intent handlers are not included in the gem as they are a
|
180
218
|
but specific to the application.
|
@@ -58,11 +58,6 @@ module Alexa
|
|
58
58
|
@_usage_count ||= context.user.usage_count_for(intent_name: request.intent_name)
|
59
59
|
end
|
60
60
|
|
61
|
-
def show_device_address_permission_consent_card?
|
62
|
-
@_show_device_address_permission_consent_card == true
|
63
|
-
end
|
64
|
-
|
65
|
-
|
66
61
|
protected
|
67
62
|
|
68
63
|
def has_all_slots?
|
@@ -126,14 +121,6 @@ module Alexa
|
|
126
121
|
}
|
127
122
|
end
|
128
123
|
|
129
|
-
def show_device_address_permission_consent_card!
|
130
|
-
@_show_device_address_permission_consent_card = true
|
131
|
-
end
|
132
|
-
|
133
|
-
def device_address_permission_consent_response
|
134
|
-
@_device_address_permission_consent_response ||= Alexa::Responses::PermissionConsents::DeviceAddress.new(intent: self)
|
135
|
-
end
|
136
|
-
|
137
124
|
def delegate_response
|
138
125
|
@_delegate_response ||= Alexa::Responses::Delegate.new
|
139
126
|
end
|
data/lib/alexa/response.rb
CHANGED
@@ -8,6 +8,12 @@ module Alexa
|
|
8
8
|
@slots_to_not_render_elicitation = []
|
9
9
|
end
|
10
10
|
|
11
|
+
def with(template: )
|
12
|
+
# TODO make this return a new object instead of self.
|
13
|
+
@force_template_filename = template
|
14
|
+
self
|
15
|
+
end
|
16
|
+
|
11
17
|
# Marks a slot for elicitation.
|
12
18
|
#
|
13
19
|
# Options:
|
@@ -30,9 +36,13 @@ module Alexa
|
|
30
36
|
slot_to_elicit = elicit_directives.first[:slotToElicit]
|
31
37
|
end
|
32
38
|
|
33
|
-
template_path = "alexa/#{intent.context.locale}/intent_handlers/"\
|
39
|
+
template_path = "alexa/#{intent.context.locale.downcase}/intent_handlers/"\
|
34
40
|
"#{intent.class.name.demodulize.underscore}"
|
35
41
|
|
42
|
+
if filename.nil? && @force_template_filename.present?
|
43
|
+
filename = @force_template_filename
|
44
|
+
end
|
45
|
+
|
36
46
|
if filename.present?
|
37
47
|
if format == :ssml
|
38
48
|
"#{template_path}/#{filename}.ssml.erb"
|
@@ -40,12 +50,6 @@ module Alexa
|
|
40
50
|
"#{template_path}/#{filename}.text.erb"
|
41
51
|
end
|
42
52
|
else
|
43
|
-
if intent.show_device_address_permission_consent_card? && format == :text
|
44
|
-
return Alexa::Responses::PermissionConsents::DeviceAddress.new(
|
45
|
-
intent: intent
|
46
|
-
).partial_path(format: :text)
|
47
|
-
end
|
48
|
-
|
49
53
|
if slot_to_elicit.present? && !@slots_to_not_render_elicitation.include?(slot_to_elicit)
|
50
54
|
if format == :ssml
|
51
55
|
"#{template_path}/elicitations/#{slot_to_elicit.underscore}.ssml.erb"
|
@@ -54,9 +58,9 @@ module Alexa
|
|
54
58
|
end
|
55
59
|
else
|
56
60
|
if format == :ssml
|
57
|
-
"#{template_path}/
|
61
|
+
"#{template_path}/default.ssml.erb"
|
58
62
|
else
|
59
|
-
"#{template_path}/
|
63
|
+
"#{template_path}/default.text.erb"
|
60
64
|
end
|
61
65
|
end
|
62
66
|
end
|
data/lib/alexa/responses/bye.rb
CHANGED
@@ -8,7 +8,7 @@ module Alexa
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def partial_path(format: :ssml)
|
11
|
-
template_path = "alexa/#{intent.context.locale}/intent_handlers/"\
|
11
|
+
template_path = "alexa/#{intent.context.locale.downcase}/intent_handlers/"\
|
12
12
|
"#{intent.class.name.demodulize.underscore}"
|
13
13
|
|
14
14
|
if format == :ssml
|
@@ -10,7 +10,7 @@ module Alexa
|
|
10
10
|
|
11
11
|
def partial_path(format: :ssml)
|
12
12
|
if format == :ssml
|
13
|
-
"alexa/#{intent.context.locale}/intent_handlers/"\
|
13
|
+
"alexa/#{intent.context.locale.downcase}/intent_handlers/"\
|
14
14
|
"#{intent.class.name.demodulize.underscore}"\
|
15
15
|
"/permission_consents/"\
|
16
16
|
"device_address.ssml.erb"
|
data/lib/alexa/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alexa-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sri Vishnu Totakura
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-06-
|
11
|
+
date: 2018-06-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|