我正在尝试使用 Amazon 内置功能对我的自定义 Alexa 技能进行越界查询。Alexa 可以为此使用“AMAZON.FallbackIntent”,我在这里找到了基本设置: https ://developer.amazon.com/it/blogs/alexa/post/f6bb7c54-de0d-4abe-98c3-cf3fc75c32f8/how -to-add-fallbackintent-handling-to-your-alexa-skill
现在,所有“en”语言环境都可以使用此功能,无论如何,经过多次尝试,我已经设置了具有相同结构的“en-GB.json”和“en-US.json”,如下所示:
"intents": [
{
"name": "AMAZON.FallbackIntent",
"samples": []
},
{
"name": "AMAZON.CancelIntent",
"samples": []
},
{
"name": "AMAZON.HelpIntent",
"samples": [
"I don't know",
"What can you do",
"What are you capable of",
"What is this",
"help"
]
},
{
"name": "AMAZON.StopIntent",
"samples": []
},
除了后备意图之外,所有内置意图都可以正常工作。以下是该技能的 index.js 片段示例:
const Alexa = require('ask-sdk');
const dbHelper = require('./helpers/dbHelper');
const GENERAL_REPROMPT = "What would you like to do?";
const dynamoDBTableName = "movies";
const LaunchRequestHandler =
{
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'LaunchRequest';
},
handle(handlerInput) {
const speechText = 'Welcome to the X ' + '&' + 'Y Customer Service, my name is Natalia, how may I help you today?';
const repromptText = 'What would you like to do? You can say HELP to get available options';
return handlerInput.responseBuilder
.speak(speechText)
.reprompt(repromptText)
.getResponse();
}
};
const InProgressAddMovieIntentHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'IntentRequest' &&
request.intent.name === 'AddMovieIntent' &&
request.dialogState !== 'COMPLETED';
},
handle(handlerInput) {
const currentIntent = handlerInput.requestEnvelope.request.intent;
return handlerInput.responseBuilder
.addDelegateDirective(currentIntent)
.getResponse();
}
};
const AddMovieIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'AddMovieIntent';
},
async handle(handlerInput) {
const {responseBuilder } = handlerInput;
const userID = handlerInput.requestEnvelope.context.System.user.userId;
const slots = handlerInput.requestEnvelope.request.intent.slots;
const movieName = slots.MovieName.value;
return dbHelper.addMovie(movieName, userID)
.then((data) => {
const speechText = `You have added movie ${movieName}. You can say add to add another one or remove to remove movie`;
return responseBuilder
.speak(speechText)
.reprompt(GENERAL_REPROMPT)
.getResponse();
})
.catch((err) => {
console.log("Error occured while saving movie", err);
const speechText = "we cannot save your movie right now. Try again!"
return responseBuilder
.speak(speechText)
.getResponse();
})
},
};
const GetMoviesIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'GetMoviesIntent';
},
async handle(handlerInput) {
const {responseBuilder } = handlerInput;
const userID = handlerInput.requestEnvelope.context.System.user.userId;
return dbHelper.getMovies(userID)
.then((data) => {
var speechText = "Your movies are "
if (data.length == 0) {
speechText = "You do not have any favourite movie yet, add movie by saving add moviename "
} else {
speechText += data.map(e => e.movieTitle).join(", ")
}
return responseBuilder
.speak(speechText)
.reprompt(GENERAL_REPROMPT)
.getResponse();
})
.catch((err) => {
const speechText = "we cannot get your movie right now. Try again!"
return responseBuilder
.speak(speechText)
.getResponse();
})
}
};
const InProgressRemoveMovieIntentHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'IntentRequest' &&
request.intent.name === 'RemoveMovieIntent' &&
request.dialogState !== 'COMPLETED';
},
handle(handlerInput) {
const currentIntent = handlerInput.requestEnvelope.request.intent;
return handlerInput.responseBuilder
.addDelegateDirective(currentIntent)
.getResponse();
}
};
const RemoveMovieIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'RemoveMovieIntent';
},
handle(handlerInput) {
const {responseBuilder } = handlerInput;
const userID = handlerInput.requestEnvelope.context.System.user.userId;
const slots = handlerInput.requestEnvelope.request.intent.slots;
const movieName = slots.MovieName.value;
return dbHelper.removeMovie(movieName, userID)
.then((data) => {
const speechText = `You have removed movie with name ${movieName}, you can add another one by saying add`
return responseBuilder
.speak(speechText)
.reprompt(GENERAL_REPROMPT)
.getResponse();
})
.catch((err) => {
const speechText = `You do not have movie with name ${movieName}, you can add it by saying add`
return responseBuilder
.speak(speechText)
.reprompt(GENERAL_REPROMPT)
.getResponse();
})
}
};
const HelpIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'AMAZON.HelpIntent';
},
handle(handlerInput) {
const speechText = 'You can access information about products, place an order or raise and issue';
const repromptText = 'What would you like to do? You can say HELP to hear the options again';
return handlerInput.responseBuilder
.speak(speechText)
.reprompt(repromptText)
.getResponse();
},
};
const CancelAndStopIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& (handlerInput.requestEnvelope.request.intent.name === 'AMAZON.CancelIntent'
|| handlerInput.requestEnvelope.request.intent.name === 'AMAZON.StopIntent');
},
handle(handlerInput) {
const speechText = 'Goodbye! See you later!';
return handlerInput.responseBuilder
.speak(speechText)
.getResponse();
},
};
const FallbackHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'IntentRequest' && request.intent.name === 'AMAZON.FallbackIntent';
},
handle(handlerInput) {
const output = "I am sorry, I can't help with that";
return handlerInput.responseBuilder
.speak(output)
.reprompt(output)
.getResponse();
},
};
const SessionEndedRequestHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'SessionEndedRequest';
},
handle(handlerInput) {
console.log(`Session ended with reason: ${handlerInput.requestEnvelope.request.reason}`);
return handlerInput.responseBuilder.getResponse();
},
};
const ErrorHandler = {
canHandle() {
return true;
},
handle(handlerInput, error) {
console.log(`Error handled: ${error.message}`);
return handlerInput.responseBuilder
.speak('Sorry, I can\'t understand the command. Please say again.')
.reprompt('Sorry, I can\'t understand the command. Please say again.')
.getResponse();
},
};
const skillBuilder = Alexa.SkillBuilders.standard();
exports.handler = skillBuilder
.addRequestHandlers(
LaunchRequestHandler,
InProgressAddMovieIntentHandler,
AddMovieIntentHandler,
GetMoviesIntentHandler,
InProgressRemoveMovieIntentHandler,
RemoveMovieIntentHandler,
HelpIntentHandler,
CancelAndStopIntentHandler,
SessionEndedRequestHandler,
FallbackHandler
)
.addErrorHandlers(ErrorHandler)
.withTableName(dynamoDBTableName)
.withAutoCreateTable(true)
.lambda();
启动技能后,技能执行:
语音文本
为此,我尝试说天气如何,该技能会忽略该输入并仅执行:
提示文本
然后如果我再次询问天气,它只会关闭技能......
我怎样才能使这两种英语语言模型都起作用?