fahu
5/9/2017 - 3:48 PM

First time creating an Alexa Skill - SpeechletResponse from JSON Snippet

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;
}