Skip to content

Instantly share code, notes, and snippets.

@fahu
Created May 9, 2017 15:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fahu/0fa985464f442e73ffc61f8eec3454e0 to your computer and use it in GitHub Desktop.
Save fahu/0fa985464f442e73ffc61f8eec3454e0 to your computer and use it in GitHub Desktop.
First time creating an Alexa Skill - SpeechletResponse from JSON Snippet
/**
* 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;
}
@fahu
Copy link
Author

fahu commented May 9, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment