我正在写一个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秒,技能就会死掉,说“请求的技能没有发送有效的响应”。如何继续会话,直到用户说停止?
谢谢
发布于 2020-04-10 02:40:54
你不能让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();发布于 2020-04-15 00:34:44
这里有几个问题。
reprompt将是什么(这将自动使会话保持打开状态,不再需要withShouldEndSession).SimpleCard,而不是speechText中。也就是说,简单的卡片不需要包括短语"to stop..."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,如果你想添加你的投票。
https://stackoverflow.com/questions/61127027
复制相似问题