Created
May 9, 2017 15:48
-
-
Save fahu/0fa985464f442e73ffc61f8eec3454e0 to your computer and use it in GitHub Desktop.
First time creating an Alexa Skill - SpeechletResponse from JSON Snippet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This is a helper method which allows you to create a SpeechletResponse from the specified JSON file. | |
* | |
* @param requestFileName The name of the JSON file placed in your projects ressource/requests folder. | |
* @return The parsed SpeechletResponse from the specified JSON file. | |
*/ | |
public static SpeechletResponse getSpeechletResponse(String requestFileName) throws Exception { | |
InputStream inputStream = getClass().getClassLoader().getResourceAsStream("requests/" + requestFileName); | |
SpeechletRequestEnvelope requestEnvelope = SpeechletRequestEnvelope.fromJson(inputStream); | |
IntentRequest intentRequest = (IntentRequest) requestEnvelope.getRequest(); | |
Session session = requestEnvelope.getSession(); | |
SpeechletResponse speechletResponse = speechlet.onIntent(intentRequest, session); | |
return speechletResponse; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See https://gist.github.com/fahu/b80fb8d007c5162cf291b1f10d47ac09 for all snippets