Alexa 的两个意图;第二个意图不触发
Alexa Two Intents; Second Intent not triggering
我无法在 alexa 的 hello world 演示中制作两个 intent。我添加了 AboutSarawakIntent 来触发另一个 lambda 函数。
{
"interactionModel": {
"languageModel": {
"invocationName": "greet chief minister",
"intents": [
...,
{
"name": "HelloWorldIntent",
"slots": [],
"samples": [
"Ok",
"Awesome",
"Good",
"Great",
"Okay",
"Yes",
"Good Afternoon",
"Good Morning",
"Hello",
"Say Hello",
"Say hi",
"Tell Me More"
]
},
{
"name": "AboutSarawakIntent",
"slots": [],
"samples": [
"how do you do",
"I am fine",
"how are you"
]
},
...
],
"types": []
}
}
}
因此以下代码来自 lambda 函数,我在其中添加了 AboutSarawakIntentHandler 以收听 AboutSarawakIntent。
....
const HelloWorldIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'HelloWorldIntent';
},
handle(handlerInput) {
const randomNumber = Math.floor(Math.random() * speeches.length);
const speechText = speeches[randomNumber];
const continueSpeech = continues[randomNumber];
return handlerInput.responseBuilder
.speak(speechText)
.reprompt(continueSpeech)
.getResponse();
}
};
const AboutSarawakIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'AboutSarawakIntent';
},
handle(handlerInput) {
const speechText = 'Welcome to Sarawak'
const continueText = 'I am honored to be here.';
return handlerInput.responseBuilder
.speak(speechText)
.reprompt(continueText)
.WithStandardCard('Greeting from Sarawak', 'Welcome Everybody', 'https://s1.bukalapak.com/img/6425275433/w-1000/banner_selamat_datang_di_pernikahan.jpg', 'https://s1.bukalapak.com/img/6425275433/w-1000/banner_selamat_datang_di_pernikahan.jpg')
.getResponse();
}
};
....
// This handler acts as the entry point for your skill, routing all request and response
// payloads to the handlers above. Make sure any new handlers or interceptors you've
// defined are included below. The order matters - they're processed top to bottom.
exports.handler = Alexa.SkillBuilders.custom()
.addRequestHandlers(
LaunchRequestHandler,
HelloWorldIntentHandler,
AboutSarawakIntentHandler,
HelpIntentHandler,
CancelAndStopIntentHandler,
SessionEndedRequestHandler,
IntentReflectorHandler) // make sure IntentReflectorHandler is last so it doesn't override your custom intent handlers
.addErrorHandlers(
ErrorHandler)
.lambda();
我每次使用语句时都能成功触发 HelloWorldIntent,但另一个总是给我回复'对不起,我听不懂你说的话。请再试一遍。'有人可以告诉我哪里可能出错吗?
终于可以触发了,因为我的alexa设备不支持图片输出。所以 WithStandardCard 总是给我错误。所以我将其更改为 WithSimpleCard 并且有效。
"https://ask-sdk-for-nodejs.readthedocs.io/en/latest/Building-Response.html"
我无法在 alexa 的 hello world 演示中制作两个 intent。我添加了 AboutSarawakIntent 来触发另一个 lambda 函数。
{
"interactionModel": {
"languageModel": {
"invocationName": "greet chief minister",
"intents": [
...,
{
"name": "HelloWorldIntent",
"slots": [],
"samples": [
"Ok",
"Awesome",
"Good",
"Great",
"Okay",
"Yes",
"Good Afternoon",
"Good Morning",
"Hello",
"Say Hello",
"Say hi",
"Tell Me More"
]
},
{
"name": "AboutSarawakIntent",
"slots": [],
"samples": [
"how do you do",
"I am fine",
"how are you"
]
},
...
],
"types": []
}
}
}
因此以下代码来自 lambda 函数,我在其中添加了 AboutSarawakIntentHandler 以收听 AboutSarawakIntent。
....
const HelloWorldIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'HelloWorldIntent';
},
handle(handlerInput) {
const randomNumber = Math.floor(Math.random() * speeches.length);
const speechText = speeches[randomNumber];
const continueSpeech = continues[randomNumber];
return handlerInput.responseBuilder
.speak(speechText)
.reprompt(continueSpeech)
.getResponse();
}
};
const AboutSarawakIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'AboutSarawakIntent';
},
handle(handlerInput) {
const speechText = 'Welcome to Sarawak'
const continueText = 'I am honored to be here.';
return handlerInput.responseBuilder
.speak(speechText)
.reprompt(continueText)
.WithStandardCard('Greeting from Sarawak', 'Welcome Everybody', 'https://s1.bukalapak.com/img/6425275433/w-1000/banner_selamat_datang_di_pernikahan.jpg', 'https://s1.bukalapak.com/img/6425275433/w-1000/banner_selamat_datang_di_pernikahan.jpg')
.getResponse();
}
};
....
// This handler acts as the entry point for your skill, routing all request and response
// payloads to the handlers above. Make sure any new handlers or interceptors you've
// defined are included below. The order matters - they're processed top to bottom.
exports.handler = Alexa.SkillBuilders.custom()
.addRequestHandlers(
LaunchRequestHandler,
HelloWorldIntentHandler,
AboutSarawakIntentHandler,
HelpIntentHandler,
CancelAndStopIntentHandler,
SessionEndedRequestHandler,
IntentReflectorHandler) // make sure IntentReflectorHandler is last so it doesn't override your custom intent handlers
.addErrorHandlers(
ErrorHandler)
.lambda();
我每次使用语句时都能成功触发 HelloWorldIntent,但另一个总是给我回复'对不起,我听不懂你说的话。请再试一遍。'有人可以告诉我哪里可能出错吗?
终于可以触发了,因为我的alexa设备不支持图片输出。所以 WithStandardCard 总是给我错误。所以我将其更改为 WithSimpleCard 并且有效。
"https://ask-sdk-for-nodejs.readthedocs.io/en/latest/Building-Response.html"