[英]Alexa Nodejs Skill - Second Intent asked always fails
我已經開始使用CodeStar和Nodejs制作一個簡單的Alexa技能,如果有任何當前事件或服務中斷,我的技能可以通知用戶Web系統當前是否仍然可用。 我從http://statuspage.io以JSON API的形式獲取了所有數據。
我遇到的問題是,我的LaunchRequestHandler
可以正常工作,我問的第一個意圖也可以正常工作,但是,當我問第二個意圖時(緊接在第一個意圖之后),這就是我的技能中斷和輸出的地方(在Alexa內部)開發者控制台): <Audio only response>
。
下面,我粘貼了我的技能中包含的代碼。
// model/en-GB.json
"intents": [{
"name": "QuickStatusIntent",
"slots": [],
"samples": [
"quick status",
"current status",
"tell me the current status",
"what's the current status",
"tell me the quick status",
"what's the quick status"
]
},
{
"name": "CurrentIncidentIntent",
"slots": [],
"samples": [
"incidents",
"current incident",
"is there a current incident",
"tell me the current incidents",
"what are the current incidents",
"are there any current incidents"
]
}]
// lambda/custom/index.js
const QuickStatusIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'QuickStatusIntent';
},
async handle(handlerInput) {
let speechText = await getNetlifyStatus();
return handlerInput.responseBuilder
.speak(speechText)
.getResponse();
}
};
const CurrentIncidentIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'CurrentIncidentIntent';
},
async handle(handlerInput) {
const result = await getSummary();
const speechText = `There are currently ${result.incidents.length} system incidents`;
return handlerInput.responseBuilder
.speak(speechText)
.getResponse();
}
}
我最初的想法是刪除.getResponse()
因為它可能一直在等待響應,但是,它似乎無法正常工作。
問題是您的CurrentIncidentIntentHandler在將響應傳遞給用戶后立即關閉了會話。
如果要保持會話打開狀態並允許用戶進行會話,請在CurrentIncidentIntentHandler中使用.withShouldEndSession(false)
或.repeat(speechText)
,以使Alexa等待用戶的下一個響應。
const CurrentIncidentIntentHandler = { canHandle(handlerInput) { return handlerInput.requestEnvelope.request.type === 'IntentRequest' && handlerInput.requestEnvelope.request.intent.name === 'CurrentIncidentIntent'; }, async handle(handlerInput) { const result = await getSummary(); const speechText = `There are currently ${result.incidents.length} system incidents`; return handlerInput.responseBuilder .speak(speechText) .withShouldEndSession(false) //you can also use .repeat(speachText) at this line .getResponse(); } }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.