Intent链式调用是在ASK(Alexa Skills Kit)中实现类似于对话的方式的重要技术。通过连续对多个Intent的调用,可以实现用户更加自然和流畅的语音交互体验。下面是一个包含代码示例的Intent链式调用实现方法。
首先,在创建Intent时,需要注意设置对应的Utterances。例如:
{
"intents": [
{
"intent": "HelloIntent",
"slots": [],
"utterances": [
"hello",
"hi",
"hey",
"hi there"
]
},
{
"intent": "HowAreYouIntent",
"slots": [],
"utterances": [
"how are you",
"how are you doing",
"how are things",
"how's it going"
]
},
{
"intent": "GoodbyeIntent",
"slots": [],
"utterances": [
"goodbye",
"bye",
"see you later",
"see you soon"
]
}
]
}
接下来,在Lambda函数中,可以使用request.intent.name获取到当前的Intent,从而实现Intent的分发和链式调用。例如:
exports.handler = function(event, context) {
try {
if (event.session.new) {
// New Session
console.log("New Session");
}
switch (event.request.type) {
case "LaunchRequest":
// Launch Request
console.log(`Launch Request`);
context.succeed(
generateResponse(
buildSpeechletResponse("Welcome to my skill", false),
{}
)
);
break;
case "IntentRequest":
// Intent Request
console.log(`Intent Request: ${event.request.intent.name}`);
switch (event.request.intent.name) {
case "HelloIntent":
// Hello Intent
context.succeed(
generateResponse(
buildSpeechletResponse("Hello there", false),
{}
)
);
break;
case "HowAreYouIntent":
// How are you Intent
context.s
上一篇:Askturtle'without'[blah?]中文翻译是什么?
下一篇:ask_sdk_runtime.exceptions.DispatchException: 无法找到合适的请求处理程序。