nodejs alexa技能持续到用户说停止为止

问题描述 投票:0回答:1

我正在编写一项Alexa技能,该技能可以按城市返回顶尖大学。我希望会话和技能继续下去,直到用户说停止为止。使用城市名称的TopCollegesByCityIntentHandler的代码如下:

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();
    }

但是,如果用户说的时间不超过5-10秒,则该技能会通过说“所请求的技能未发送有效回复”而死亡。我如何继续会话直到用户说停止?

谢谢

node.js alexa alexa-skill ask-sdk
1个回答
0
投票

您不能让Alexa的麦克风打开超过8秒。

但是我建议使用reprompt方法,如果用户在前8秒内没有响应,它将再次询问一个问题。

这里是它的样子

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();
© www.soinside.com 2019 - 2024. All rights reserved.