【发布时间】:2019-08-23 15:11:42
【问题描述】:
我正在 node.js 中编写一个 Alexa 应用程序来回答产品规范问题。例如,我想问“(产品)的最大容量是多少?”目前,我对每个产品的每个问题都有不同的意图,这导致带有大量处理程序的代码非常混乱。例如,我想做的只是有一个 MaxCapacity 意图,它使用插槽(包含不同的产品)来分配事实。我在 node.js 上还是比较新的,所以如果这真的很草率,我很抱歉。我知道如何在开发者控制台上创建新插槽,只是不知道如何在后端编写代码。这是处理程序之一:
const GetNewFactHandler1 = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'LaunchRequest'
|| (request.type === 'IntentRequest'
&& request.intent.name === 'UMaxCapacityIntent');
*/ And if slot type == *product*, then: */
},
handle(handlerInput) {
const factArr = data;
const randomFact = factArr[1]; //Array with all the answers
const speechOutput = GET_FACT_MESSAGE + randomFact;
return handlerInput.responseBuilder
.speak(speechOutput)
.withSimpleCard(SKILL_NAME, randomFact)
.getResponse();
},
};
我希望这是有道理的,但我很乐意进一步解释。谢谢!
【问题讨论】:
标签: node.js amazon-web-services alexa slots