How to trigger response for Custom Intent?

2019-08-30 05:56发布

问题:

I created an Alexa 'riddle' skill recently and I'm having trouble with the utterances. I created an intent "GetRiddleIntent" then associated a few utterances e.g. "riddle me this" with that intent. I did not include any intent slots. When I test my skill, I have to use the invocation name in order to bring back results from lambda.

The built in intents work upon invocation e.g. "LaunchRequest" & "Amazon HelpRequest" but none of the sample utterances for my custom intent return any results, I keep getting the "There was a problem with the requested skills response" as a result.

This is for a riddle skill being implemented using JAVA and ask-sdk V2.

I've tried implementing the handler responsible for the riddles from scratch.

Edited the Riddle string to ensure there are no characters that might cause any response failure.

Messed around with changing "shouldEndSession" to true and to false (currently have it set back to false)

I've also copied the error response from the developer console into my lambda configurations for a more detailed error log and nothing points specifically to my code per-say. I get a java.lang.NullPointerException which points to errors in built in libraries e.g. com.amazon.ask.SkillStreamHandler.handleRequest(SkillStreamHandler.java:71)

I've also looked at the following sample skills in V2 for assistance but none have helped. https://github.com/alexa/alexa-skills-kit-sdk-for-java/tree/2.0.x/samples

package lambda.riddle.handlers;

import static com.amazon.ask.request.Predicates.intentName;

import java.util.Optional;

import com.amazon.ask.dispatcher.request.handler.HandlerInput;
import com.amazon.ask.dispatcher.request.handler.RequestHandler;
import com.amazon.ask.model.Response;

import riddle_generator.Riddle;
import riddle_generator.GenerateRiddles;



public class GetRiddleIntentHandler implements RequestHandler 
{
  public boolean canHandle(HandlerInput input)
  {
    return input.matches(intentName("GetRiddleIntent"));
  }

  @Override
  public Optional<Response> handle(HandlerInput input) 
  {

    String speechText, repromptText;

    speechText = "I am caucasian, internet famous and best known for my catchphrase, catch me outside how about that. Who am I?";
    repromptText = "I am caucasian, internet famous and best known for my catchphrase, catch me outside how about that. Who am I?";
    return input.getResponseBuilder()
        .withSimpleCard("RiddleSession", speechText)
        .withSpeech(speechText)
        .withReprompt(repromptText)
        .withShouldEndSession(false)
        .build();
  }
}

I should get the speechText as a response in my develop console but instead get a "There was a problem with the requested skill's response" message.

Below is the error Response:

{
  "request": {
        "type": "SessionEndedRequest",
        "requestId": "amzn1.echo-api.request.338924d9-8cf9-448a-85a2-6a8bacc5e1be",
        "timestamp": "2019-02-02T12:01:04Z",
        "locale": "en-GB",
        "reason": "ERROR",
        "error": {
            "type": "INVALID_RESPONSE",
            "message": "An exception occurred while dispatching the request to the skill."
        }
    }
}