kevin-mitchell / alexa-app

Set of classes to make creating Amazon Alexa Skills Kit (ASK) applications easier with Laravel and Lumen
MIT License
97 stars 47 forks source link

Getting ConfirmIntents to work. #39

Closed Dayjo closed 7 years ago

Dayjo commented 7 years ago

Hello,

Thanks for the great library. I'm currently trying to get Confirm Intent to work, but Alexa seems to hate the syntax or something.

I'm doing the following;

if ($request->getConfirmationStatus() == 'NONE') {
            $speech = new Speech('Are you sure?');
            return $response->setSpeech($speech)->withDirective(new ConfirmIntent())->endSession(false);
}

Which gives the response;


{
    "version": "1.0",
    "response": {
        "outputSpeech": {
            "type": "PlainText",
            "text": "Are you sure? This will reset your existing game."
        },
        "directives": [
            {
                "type": "Dialog.ConfirmIntent",
                "updatedIntent": {
                    "name": "NewGameIntent",
                    "confirmationStatus": "NONE",
                    "slots": []
                }
            }
        ],
        "shouldEndSession": false
    }
}

This is how it's set up in the Skill Builder.

I just get the classic exception occurred session ended request back;

request": {
        "type": "SessionEndedRequest",
        "requestId": "amzn1.echo-api.request.e5abdcaa-66c0-4bf1-s11d-aab0f6d1ee1a",
        "timestamp": "2017-10-19T15:49:30Z",
        "locale": "en-GB",
        "reason": "ERROR",
        "error": {
            "type": "INVALID_RESPONSE",
            "message": "An exception occurred while dispatching the request to the skill."
        }
    }

I've read through the Amazon docs on the Dialog Model etc but still struggling to grasp what I'm doing wrong.

Any assistance would be fantastic!

Dayjo commented 7 years ago

Hello,

I managed to get this working on our fork as I made a fix to allow slots() to return null when it's empty, Amazon was erroring when it was ; slots: [] (https://github.com/pallant/alexa-app/commit/1504615188d7b9956c989647e833ce8ebe54c335)

My code works like so;

// Confirm if you want to restart 
if (!$request->getConfirmationStatus() || $request->getConfirmationStatus() == 'NONE') {
    $speech = new Speech('Are you sure?');
    return $response->setSpeech($speech)->withDirective(new ConfirmIntent())->endSession(false);
}
// restart the game
elseif ($request->getConfirmationStatus() == 'CONFIRMED') {
  // Do the restarting
    return $this->restartedResponse($request, $response);
}

// Don't restart thegame
return $response->setSpeech(new Speech("Ok, no problem, you can continue when you're ready."))->endSession(false);