0
votes

I am writing an alexa skill which returns top colleges by city. I want session and the skill to continue till the user says stop. The code for TopCollegesByCityIntentHandler which takes city name is as below:

const TopCollegesByCityIntentHandler = {
    canHandle(handlerInput) {
        return handlerInput.requestEnvelope.request.type === 'IntentRequest'
            && handlerInput.requestEnvelope.request.intent.name === 'TopCollegesByCity';
    },
    handle(handlerInput) {
        console.log('handlerInput.requestEnvelope.request', JSON.stringify(handlerInput.requestEnvelope.request));
        let speechText = '';
        const cityName = handlerInput.requestEnvelope.request.intent.slots.cityName.value;

        // logic to get top colleges by city name and modify speechText

        speechText += 'To know top colleges in your city say, top colleges in your city. To stop say, stop.';
        return handlerInput.responseBuilder
            .speak(speechText)
            .withSimpleCard('Top Colleges', speechText)
            .withShouldEndSession(false)
            .getResponse();
    }

But if the user doesn't speak for more than 5-10 seconds, the skill dies by saying "the requested skill did not send a valid response". How do I continue the session till the user says stop ?

Thanks

2

2 Answers

0
votes

You can not keep Alexa's mic open for more than 8 seconds.

However what I would suggest is to use the reprompt method, which would ask a question again if the user doesn't respond within the first 8 seconds.

Here is how it would look like

speechText += 'To know top colleges in your city say, top colleges in your city. To stop say, stop.';
repromptText = 'Say top colleges in your city for the city.';
return handlerInput.responseBuilder
        .speak(speechText)
        .reprompt(repromptText)
        .withSimpleCard('Top Colleges', speechText)
        .withShouldEndSession(false)
        .getResponse();
0
votes

Several problems here...

  • First, I'm not sure why you want to leave the session open. You're not asking a question. (And I'm recommending you don't.)

  • Second, if you do want to leave the session open you should specify what your reprompt will be (which will automatically leave the session open, no longer need the withShouldEndSession).

  • Third, you should put the list of colleges in its own variable and add that to the SimpleCard, not the speechText. i.e., no need for the simple card to include the phrase "to stop..."

  • Finally, if you're responding with a long list—which it sounds like you're doing, you want them to know how to stop it or ask for something else before you start the list. (Otherwise, they'd have to listen to the whole list before knowing it was possible to stop it.) I'd recommend starting with something like To know top colleges in your city, say, "Alexa, ask {yourSkillName} for Top Colleges in", and the name of your city. To stop, say "Alexa, stop". Here are the Top Colleges by city: {super long collegeList}. No reprompt (because you don't want the session to remain open). Then you can rely on "one-shot"s to handle your other requests.

This Alexa design doc outlines the 8-second limit.

Official UserVoice feature request for setting the timeout limit, in case you'd like to add your vote.