首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >nodejs alexa技能继续,直到用户说停止

nodejs alexa技能继续,直到用户说停止
EN

Stack Overflow用户
提问于 2020-04-10 01:41:35
回答 2查看 85关注 0票数 0

我正在写一个alexa技能,它返回城市的一流大学。我希望会话和技能继续下去,直到用户说停止。取城市名的TopCollegesByCityIntentHandler代码如下:

代码语言:javascript
复制
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秒,技能就会死掉,说“请求的技能没有发送有效的响应”。如何继续会话,直到用户说停止?

谢谢

EN

回答 2

Stack Overflow用户

发布于 2020-04-10 02:40:54

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

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

下面是它看起来的样子

代码语言:javascript
复制
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
EN

Stack Overflow用户

发布于 2020-04-15 00:34:44

这里有几个问题。

  • 首先,我不确定您为什么要让会话保持打开状态。你不是在问问题。(我建议您,如果您确实想让会话保持打开状态,您应该指定您的reprompt将是什么(这将自动使会话保持打开状态,不再需要withShouldEndSession).
  • Third,。您应该将大学列表放入它自己的变量中,并将其添加到SimpleCard,而不是speechText中。也就是说,简单的卡片不需要包括短语"to stop..."
  • Finally,“如果你回复了一个很长的列表--你听起来像是在做,你想让他们知道如何停止它或在你开始列表之前要求其他。(否则,他们必须先听完整个列表,然后才能知道有可能阻止它。)我建议从像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 (因为您不希望会话保持打开状态)。然后你就可以依靠“一次性”来处理你的其他请求了。

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

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61127027

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档