8
votes

I tried to create a HelloWorld Skill based on https://github.com/amzn/alexa-skills-kit-java but when I tested the lambda function it showed this error

{
  "errorMessage":"com.amazon.speech.speechlet.SpeechletRequestHandlerException: Could not validate SpeechletRequest null using verifier ApplicationIdSpeechletRequestVerifier, rejecting request",

  "errorType": "java.lang.RuntimeException",

  "stackTrace": [    "com.amazon.speech.speechlet.lambda.SpeechletRequestStreamHandler.handleRequest(SpeechletRequestStreamHandler.java:101)",
 "helloworld.HelloWorldSpeechletRequestStreamHandler.handleRequest(HelloWorldSpeechletRequestStreamHandler.java:43)"

 ],

  "cause": {

    "errorMessage": "Could not validate SpeechletRequest null using 
verifier ApplicationIdSpeechletRequestVerifier, rejecting request",
    "errorType": "com.amazon.speech.speechlet.SpeechletRequestHandlerException",

    "stackTrace": [
      "com.amazon.speech.speechlet.SpeechletRequestHandler.handleSpeechletCall(SpeechletRequestHandler.java:73)",
      "com.amazon.speech.speechlet.lambda.SpeechletRequestStreamHandler.handleRequest(SpeechletRequestStreamHandler.java:98)",
      "helloworld.HelloWorldSpeechletRequestStreamHandler.handleRequest(HelloWorldSpeechletRequestStreamHandler.java:43)"
    ]
  }
}

This is my Java file

public final class HelloWorldSpeechletRequestStreamHandler extends SpeechletRequestStreamHandler {
    private static final Set<String> supportedApplicationIds = new HashSet<String>();
    static {
        /*
         * This Id can be found on https://developer.amazon.com/edw/home.html#/ "Edit" the relevant
         * Alexa Skill and put the relevant Application Ids in this Set.
         */
        supportedApplicationIds.add("amzn1.echo-sdk-ams.app.[amzn1.echo-sdk-ams.app.56bcdaf9-97fc-47f9-9918-43cb6a90d9f5]");
    }


    public HelloWorldSpeechletRequestStreamHandler() {
        super(new HelloWorldSpeechlet(), supportedApplicationIds);
    }
}

What am i missing??

4
Did you figure out the solution? If so, can you share? I am having the same issue.RommelTJ

4 Answers

10
votes

You have the wrong ID in the supported application ID. That id needs to be the ID of the Alexa Skills application, which can be found on the Skill Information page. It should look something like this:

supportedApplicationIds.add("amzn1.ask.skill.c236d019-7d2a-5c96-a02f-ef8ab6f8e023");

I know the demo has is with [place id here] But you really replace the whole thing.

8
votes

For me I got this exception because I was trying to run my lambda function without a proper test event JSON under the Actions tab. If you click the 'Actions' tab and then click 'Configure Test Event' you are supposed give your function input in JSON form that it can interpret. After much looking I figured out that you can get this JSON by going to the developer console where you made your skill that has all your skill configurations. On the left hand side click on the 'Test' tab and then go to the section that says 'Service Simulator'. There is a text box that says 'Enter Utterance' where you can enter a voice command to your function in text e.g 'Alexa tell [yourApp] to say Hello'. Click the 'Ask [yourApp] ' button and a Lambda request JSON will be generated on the left hand box, with the output on the right. Then just copy and paste that JSON in the left into your test event in your lambda console and then you should be good.

1
votes

I tried to create a Address Skill included in https://github.com/amzn/alexa-skills-kit-java, but I got the same type of error.

It turns out that the problem was in DeviceAddressSpeechletRequestStreamHandler and creating instance of Set<String> supportedApplicationIds in static {} block.

When I moved new HashSet<>(); to declaring attributes of class, it started working.

0
votes

I would put the static code onto the class you have created that extends SpeechletLambda. This is, I believe, where the evaluation takes place and gets resolved before this class is loaded and its static code executed.

Alternatively you can just turn the validation off. If someone knows your development environment well enough to call your private lambda function, they probably know enough to spoof your application ID. So there isn't a lot of security value to validating it. For an example of turning it off, see here.