最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

AMAZON.FallbackIntent不工作ask

运维笔记admin14浏览0评论

AMAZON.FallbackIntent不工作ask

AMAZON.FallbackIntent不工作ask

我正在尝试使用亚马逊内置功能对我的自定义Alexa技能进行越界查询。 Alexa可以使用“AMAZON.FallbackIntent”这样,我在这里找到了基本设置:

现在,所有“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": []
            },

除了Fallback之外,所有内置意图都可以正常工作。以下是该技能的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();

启动技能后,技能执​​行:

speechText

我尝试说出天气是什么,技能忽略了输入,只执行:

repromptText

然后,如果我再次要求天气,它只会关闭技能......

我怎么能为英语模型做这个工作?

回答如下:

在LanunchRequest处理程序中发送speechText后,您的会话即将结束。会议结束时,Alexa不知道你是在试图通过说“天气怎么样?”来调用你的技能?因此不会调用您的后备处理程序。

使用withShouldEndSession(false)它将保持会话打开,任何不正确的输入将在您的Fallback处理程序中出现。

下面的代码应该工作。

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)
        .withShouldEndSession(false) 
        .reprompt(repromptText)
        .getResponse();
    }
};

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论