Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic view filename in intent response #9

Closed
tsrivishnu opened this issue Jun 23, 2018 · 0 comments
Closed

Dynamic view filename in intent response #9

tsrivishnu opened this issue Jun 23, 2018 · 0 comments

Comments

@tsrivishnu
Copy link
Owner

Right now, by returning response in an intent handler renders the default speech.ssml.erb and display.text.erb. These files need to handle all the different conditions if the response needs to be different for different conditions. This will pollute the view file with some if clauses and sharing variables from intent. For example. Consider the following:

# Intent handler class
class Alexa::IntentHandlers::SaveBookmark < Alexa::IntentHandlers::Base
  attr_accessor :success
  def handle
     if some_condition
       @sucess = true
     else
       @success = false
     end
     return response
  end
end
# View - intent_handlers/save_bookmarks/speech.ssml.erb
<% if intent.success %>
   <s> You request is successfully processed. </s>
<% else %>
  <s>Unable to process your request.</s>
<% end %>

It would be nice if a the response method on intent handlers can accept the response filename argument so that there can be multiple view files for conditions.

In above example.

# Intent handler
def handle
     if some_condition
       @sucess = true
       return response(view_file: :success)
     else
       @success = false
       return response(view_file: :failure)
     end
  end
# View - intent_handlers/save_bookmarks/success.ssml.erb
   <s> You request is successfully processed. </s>
# View - intent_handlers/save_bookmarks/success.text.erb
   Succesfull. 

# View - intent_handlers/save_bookmarks/failure.ssml.erb
   <s> You request couldn't be processed. </s>
# View - intent_handlers/save_bookmarks/failure.text.erb
   Failed. Sorry!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant