question

Francesco Castiglione avatar image
Francesco Castiglione asked

How to use Intent Chaining without slots in Alexa?

I am trying to create an Alexa skill. I only have one intent (LightOnIntent) that it will play audio. I wanted the user to just start the skill and immediately be redirected to the intent for the audio (without the user saying anything else). The Intent Chaining doesn't work if the intent has no slots to fill. How could I solve? Here is the code:


const LaunchRequestHandler = {
canHandle(handlerInput) {
    return Alexa.getRequestType(handlerInput.requestEnvelope) === 'LaunchRequest';
},
handle(handlerInput) {
    const speakOutput = 
    `<speak>
        <amazon:effect name="whispered">Welcome.</amazon:effect>.
    </speak>`;

    return handlerInput.responseBuilder
        .speak(speakOutput)
        .addDelegateDirective({
            name: 'LightOnIntent',
            slots: {}
        })
        .getResponse();
}
};

const LightOnIntentHandler = {
canHandle(handlerInput) {
    return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
        && Alexa.getIntentName(handlerInput.requestEnvelope) === 'LightOnIntent';
},
handle(handlerInput) {
    const {requestEnvelope, responseBuilder} = handlerInput;
    
    const audioUrl = Util.getS3PreSignedUrl("Media/ding.mp3").replace(/&/g,'&amp;');

    const speakOutput = `<audio src="${audioUrl}"/>`;
    
    return responseBuilder
        .speak(speakOutput)
        //.reprompt('add a reprompt if you want to keep the session open for the user to respond')
        .getResponse();
}
};


alexaalexa skillshosted skill
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

Andy Whitworth avatar image
Andy Whitworth answered

Change your LaunchRequest Handler return statement to:

return LightOnIntentHandler.handle (handlerInput) ;


That should work (not tested though).

3 comments
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

It works, thanks, but removing the "speak" from the LaunchRequestHandler, it doesn't say the welcome phrase

0 Likes 0 ·

Maybe there is a way to return both LightOnIntentHandler.handle (handlerInput) and the handlerInput.responseBuilder.speak(speakOutput)

0 Likes 0 ·
Andy Whitworth avatar image Andy Whitworth Francesco Castiglione ·

Extend the handle() function of the LightOnIntentHandler to accept an optional second parameter e.g "chainedSpeech"

handle(handlerInput, chainedSpeech='')

Then in the same handler, you can have:

const speakOutput = `${chainedSpeech} <audio src="${audioUrl}"/>`;

And in your LaunchRequestHandler:

return LightOnIntentHandler.handle (handlerInput, speakOutput) ;
0 Likes 0 ·