class Alexa::Response
Attributes
directives[RW]
intent[RW]
Public Class Methods
new(intent:, directives: [])
click to toggle source
# File lib/alexa/response.rb, line 5 def initialize(intent:, directives: []) @intent = intent @directives = directives @slots_to_not_render_elicitation = [] end
Public Instance Methods
elicit_directives()
click to toggle source
# File lib/alexa/response.rb, line 71 def elicit_directives return [] if directives.empty? directives.select { |directive| directive[:type] == "Dialog.ElicitSlot" } end
elicit_slot!(slot_to_elicit, skip_render: false)
click to toggle source
Marks a slot for elicitation.
Options:
- skip_render: Lets you skip the rendering of the elicited slot's view. Helpful when you have the elication text already in the response and don't wanna override it.
# File lib/alexa/response.rb, line 23 def elicit_slot!(slot_to_elicit, skip_render: false) directives << { type: "Dialog.ElicitSlot", slotToElicit: slot_to_elicit } if skip_render @slots_to_not_render_elicitation << slot_to_elicit end end
end_session?()
click to toggle source
# File lib/alexa/response.rb, line 85 def end_session? return false if keep_listening? return false if elicit_directives.any? return true end
intent_directory_name()
click to toggle source
# File lib/alexa/response.rb, line 91 def intent_directory_name # respects namespacing. # For example +Alexa::IntentHandlers::MyNameSpace::IntentName+ # will return +my_name_space/intent_name+. intent.class.name.split("::").drop(2).join("::").underscore end
keep_listening!()
click to toggle source
# File lib/alexa/response.rb, line 76 def keep_listening! @keep_listening = true self end
keep_listening?()
click to toggle source
# File lib/alexa/response.rb, line 81 def keep_listening? @keep_listening == true end
partial_path(format: :ssml, filename: nil)
click to toggle source
# File lib/alexa/response.rb, line 34 def partial_path(format: :ssml, filename: nil) if elicit_directives.any? slot_to_elicit = elicit_directives.first[:slotToElicit] end if filename.nil? && @force_template_filename.present? filename = @force_template_filename end if filename.present? if format == :ssml "#{partials_directory}/#{filename}.ssml.erb" else "#{partials_directory}/#{filename}.text.erb" end else if slot_to_elicit.present? && !@slots_to_not_render_elicitation.include?(slot_to_elicit) if format == :ssml "#{partials_directory}/elicitations/#{slot_to_elicit.underscore}.ssml.erb" else "#{partials_directory}/elicitations/#{slot_to_elicit.underscore}.text.erb" end else if format == :ssml "#{partials_directory}/default.ssml.erb" else "#{partials_directory}/default.text.erb" end end end end
partials_directory()
click to toggle source
# File lib/alexa/response.rb, line 66 def partials_directory @_partials_directory ||= "alexa/#{intent.context.locale.downcase}/intent_handlers/"\ "#{intent_directory_name}" end
with(template: )
click to toggle source
# File lib/alexa/response.rb, line 11 def with(template: ) # TODO make this return a new object instead of self. @force_template_filename = template self end