【问题标题】:nodejs alexa skill to continue till the user says stopnodejs alexa技能继续直到用户说停止
【发布时间】:2020-04-15 00:34:43
【问题描述】:

我正在编写一个按城市返回顶尖大学的 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】:

    您不能让 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();
    

    【讨论】:

      【解决方案2】:

      这里有几个问题...

      • 首先,我不确定您为什么要让会话保持打开状态。你不是在问问题。 (我建议你不要这样做。)

      • 其次,如果您确实想让会话保持打开状态,您应该指定您的reprompt 将是什么(它会自动使会话保持打开状态,不再需要withShouldEndSession)。

      • 第三,您应该将大学列表放入自己的变量中,并将其添加到SimpleCard,而不是speechText也就是说,简单的卡片不需要包含短语“停止...”

      • 最后,如果您要回复一长串清单(听起来好像您正在这样做),您希望他们知道如何阻止它或要求其他东西在您之前开始列表。 (否则,他们必须先听整个列表,然后才能知道可以停止它。)我建议从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} 之类的东西开始。否reprompt(因为您不希望会话保持打开状态)。然后你可以依靠“one-shot”来处理你的其他请求。

      This Alexa design doc 概述了 8 秒的限制。

      Official UserVoice feature request for setting the timeout limit,如果你想添加你的投票。

      【讨论】:

        猜你喜欢
        • 2020-03-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-02-27
        • 2018-08-22
        • 1970-01-01
        相关资源
        最近更新 更多