7

Something is messed up with my AMAZON.StopIntent. No matter what I put there (I've tried everything from every tutorial), whenever it's called, I get "There was a problem with the requested skill's response" and the Alexa app shows the error as "speechletresponse cannot be null". My project is in the JSON, not Java format.

If anyone can help, I'd very much appreciate it!

Thanks!

As requested here's what is being sent to Lambda

{
  "session": {
    "sessionId": "SessionId.XXXXX",
    "application": {
      "applicationId": "amzn1.ask.skill.XXXXXXX"
    },
    "attributes": {},
    "user": {
      "userId": "amzn1.ask.account.XXXXXXX"
    },
    "new": true
  },
  "request": {
    "type": "IntentRequest",
    "requestId": "EdwRequestId.XXXXXX",
    "locale": "en-US",
    "timestamp": "2017-01-18T22:38:53Z",
    "intent": {
      "name": "AMAZON.StopIntent",
      "slots": {}
    }
  },
  "version": "1.0"
}

And here's the relevent code:

var handlers = {
    'LaunchRequest': function () {
        this.emit('AMAZON.HelpIntent');
    },
    'GetNewDogThoughtIntent': function () {
        this.emit('GetDogThought');
    },
    'GetNewCatThoughtIntent': function () {
        this.emit('GetCatThought');
    },
    'GetDogThought': function () {
        var dogthoughtIndex = Math.floor(Math.random() * DOGTHOUGHTS.length);
        var randomDogThought = DOGTHOUGHTS[dogthoughtIndex];

        // Create speech output
        var speechOutput = "Your dog is thinking, " + randomDogThought;

        this.emit(':tellWithCard', speechOutput, "Your dog was thinking... ", randomDogThought);
    },
    'GetCatThought': function () {
        var catthoughtIndex = Math.floor(Math.random() * CATTHOUGHTS.length);
        var randomCatThought = CATTHOUGHTS[catthoughtIndex];

        // Create speech output
        var speechOutput = "Your cat is thinking, " + randomCatThought;

        this.emit(':tellWithCard', speechOutput, "Your cat was thinking... ", randomCatThought);
    },
    'AMAZON.HelpIntent': function () {
        var speechOutput = "You can ask me for what your cat or dog is thinking, or you can say exit... Right now I can only provide thoughts for one cat or dog at a time... What can I help you with?";
        var reprompt = "What can I help you with? Make sure to say if your pet is a cat or dog when you ask!";
        this.emit(':ask', speechOutput, reprompt);
    },
    'SessionEndedRequest': function (sessionEndedRequest, session) {
    },
    "AMAZON.StopIntent": function (shouldEndSession) {
    }
Branch
  • 387
  • 5
  • 16

3 Answers3

4

I finally got it after consulting the SpaceGeek tutorial again and making some tweaks to it. Basically, here's what worked:

'AMAZON.StopIntent': function () { 
    this.emit(':tell', "Goodbye!");
}

The key was the ':tell', which I didn't have before. Thanks to everyone who answered and helped!

Kerberos
  • 4,036
  • 3
  • 36
  • 55
Branch
  • 387
  • 5
  • 16
2

Can you post your code for the StopIntent? You should be calling a speechlet response in it. For example:

'AMAZON.StopIntent': function (shouldEndSession, response) {
    var speechOutput = "Goodbye";
    response.tell(speechOutput); 
},

Are you building that response properly and passing it?

AppleBaggins
  • 444
  • 3
  • 14
  • That gave a lot of errors when I put it in. Does it have to do with the fact my project is JSON? Right now I don't have anything in StopIntent because anything I put either gets an error in Lambda or gives a null response. – Branch Jan 18 '17 at 22:42
  • Can you post the code of your skill? I'm not sure what language you're working or how everything is constructed. Thanks! :) – AppleBaggins Jan 19 '17 at 11:58
  • OP updated with relevent code. based on the SpaceGeek template. Note that SessionEndedRequest works fine, but not AMAZON.StopIntent. I've literally tried everything there, so presently I have (shouldEndSession) but I tried other things in the {} and in the (). – Branch Jan 19 '17 at 18:16
  • Have you added AMAZON.StopIntent in your intent schema (under the Interaction Model section when you're editing your skill online)? I would make sure the AMAZON.StopIntent is in your schema and just for giggles, I would make sure that you use single quotes around AMAZON.StopIntent in your code like you've done with all the other intents. – AppleBaggins Jan 19 '17 at 18:37
  • And (helps if I go back and reread all the details) add a speechOutput to the StopIntent. `'AMAZON.StopIntent': function (shouldEndSession) { var speechOutput = "Goodbye." }` – AppleBaggins Jan 19 '17 at 18:40
  • I did that exact code. and fixed the quotations. I even added a this.emit. STILL null response. I just don't get it. it is in the schema. i'm at a loss. – Branch Jan 19 '17 at 22:53
  • Try creating it like this: `'AMAZON.StopIntent': function (shouldEndSession, response) { var speechOutput = "Goodbye"; response.tell(speechOutput); },` – AppleBaggins Jan 20 '17 at 15:32
  • That did it! If you could update your main answer with this code that would be great. Thank you SOOOOO much!! – Branch Jan 20 '17 at 20:40
  • Yikes-- I spoke to soon. Now i get an error on the Alexa skill test site that says "the remote endpoint could not be called" and when I actually ask my echo, the app says "skill response marked as failure". So it's no longer null, which is good, but it still isn't working. – Branch Jan 20 '17 at 23:51
  • I think if your Lambda function fails, you'll always get that error on the test site. Your best bet is to look at your Lambda logs (in CloudWatch) and see what they're telling you when you try an action. – AppleBaggins Jan 21 '17 at 12:32
  • Here's what I get: `{ "errorMessage": "Cannot read property 'tell' of undefined", "errorType": "TypeError", }` – Branch Jan 22 '17 at 15:05
  • That essentially means that `response` is undefined when you call it with the StopIntent. My js is weak, but I'm pretty sure you need to clear that up to get rid of the error. – AppleBaggins Jan 23 '17 at 11:24
  • That makes sense but I also don't know how to define response. – Branch Jan 23 '17 at 19:16
  • 1
    I think your best bet would be to open a new question, post the entirety of your code (or link to it), describe the issue you're having and make sure you tag the question with node.js (or something similar), so you can pull in some folks who are knowledgeable about that language. Sorry I couldn't be of more help! – AppleBaggins Jan 26 '17 at 13:10
  • I added node.js to the tags. If I don't get another response soon I'll make a new question. Thanks. – Branch Jan 26 '17 at 21:03
1

I have found this link on alexa developer forum. This might help in your issue..

https://forums.developer.amazon.com/questions/49211/system-error-speechletresponse-was-null.html

I am writing this code in php, if that helps

$data       = file_get_contents("php://input");
$jsonData   = json_decode($data);
if($jsonData->request->type === "IntentRequest"){
     $IntentName    = $jsonData->request->intent->name;
     if($IntentName === "AMAZON.StopIntent"){
         $response = '{
            "version" : "1.0",
            "response" : {
               "outputSpeech": {
               "type": "PlainText",
               "text": ""
            },
            "shouldEndSession" : false
       }
   }';
   echo $response;
  }
}
Rahul Gupta
  • 972
  • 11
  • 29