我只是想获取代码上的广告位值,我想尝试做一个简单的技能,根据用户每天发出的声音以不同的方式做出响应。
这是我的示例代码,由于没有其他问题,我正在尝试空白项目。
意图是“ HelloWorldIntent”,广告位是“天”
JSON:
{
"interactionModel": {
"languageModel": {
"invocationName": "try",
"intents": [
{
"name": "AMAZON.CancelIntent",
"samples": []
},
{
"name": "AMAZON.HelpIntent",
"samples": []
},
{
"name": "AMAZON.StopIntent",
"samples": []
},
{
"name": "HelloWorldIntent",
"slots": [
{
"name": "day",
"type": "AMAZON.DayOfWeek"
}
],
"samples": [
"good {day}",
"hello",
"how are you",
"say hi world",
"say hi",
"hi",
"say hello world",
"say hello"
]
},
{
"name": "AMAZON.NavigateHomeIntent",
"samples": []
}
],
"types": []
}
}
}
index.js是:
const HelloWorldIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'HelloWorldIntent';
},
handle(handlerInput) {
var app = this.event.request.intent.slots.day.value;
const speechText = app;
return handlerInput.responseBuilder
.speak(speechText)
//.reprompt('add a reprompt if you want to keep the session open for the user to respond')
.getResponse();
}
};
当我问星期一(或其他任何一天)的好消息时,结果是“抱歉”,我听不懂你说什么。请重试。
有什么建议吗?
答案 0 :(得分:0)
这是您的问题:
var app = this.event.request.intent.slots.day.value;
这看起来像是SDK v1的代码。
您似乎实际上正在使用v2-如果您使用的是最新版本,则可以通过以下操作来获取广告位值:
// Require the SDK at the top of your file
const Alexa = require('ask-sdk');
// Then in your handle function where you want the slot value
handle (handlerInput) {
const { requestEnvelope } = handlerInput;
const speechText = Alexa.getSlotValue(requestEnvelope, 'day');
return handlerInput.responseBuilder.speak(speechText).getResponse();
}
或者,您也可以像这样获得它:
const speechText = handlerInput.requestEnvelope.request.intent.slots['day'].value