如何在Alexa中为多个Intent创建链接而无需在用户话语下连接Intent中的任何字符串

时间:2019-10-09 11:52:00

标签: alexa alexa-skills-kit alexa-skill alexa-slot

我创建了5个意图:我的第三个意图名称是“ getRestaurantName”,我已经将{restaurantname}设置为alexa开发人员控制台用户的话语,并且为此意图使用了slottype-“ amazon.searchquery”。

下一个意图名称是“ getTableName”。我已将{name}设置为Alexa开发人员控制台用户的话语,并且已将slottype-“ amazon.person”用于getRestaurantName目的。

我在alexa开发人员控制台下添加了针对“ getRestaurantName”意图的构造。我遇到类似“您的餐厅名称为{restaurantname}的餐厅名称,这样正确吗?然后告诉“是”以调用下一个意图,例如“ getTableName”,而Alexa说问题“您的表名是什么”。那时,当我说时,{tablename}意图将被调用,但是Alexa调用了除表名意图之外的先前意图“ getRestaurantName”构象。

简而言之,如果查询将与任何先前的意图匹配,则该意图默认情况下调用先前的意图。请让我知道该解决方案,以避免在已经与当前意图匹配时调用先前的意图。

请给我个提示,并检查我的代码。

第一

enter image description here

enter image description here

第三

enter image description here

 // Lambda Function code for Alexa.
    const Alexa = require("ask-sdk");

    const LaunchRequest_Handler =  {
        canHandle(handlerInput) {
            const request = handlerInput.requestEnvelope.request;
            return request.type === 'LaunchRequest';
        },
        handle(handlerInput) {
            const responseBuilder = handlerInput.responseBuilder;
            let say = `Welcome to my app. How can i help you?`;
            let skillTitle = capitalize(invocationName);
            return responseBuilder
                .speak(say)
                .reprompt('try again, ' + say)
                .withStandardCard('Welcome!', 
                  'Hello!\nThis is a card for your skill, ' + skillTitle,
                  welcomeCardImg.smallImageUrl, welcomeCardImg.largeImageUrl)
                .getResponse();
        },
    };

    const makeReservation_Handler =  {
        canHandle(handlerInput) {
            const request = handlerInput.requestEnvelope.request;
            return request.type === 'IntentRequest' && request.intent.name === 'makeReservation' ;
        },
        handle(handlerInput) {
            const request = handlerInput.requestEnvelope.request;
            const currentIntent = handlerInput.requestEnvelope.request.intent;
            const responseBuilder = handlerInput.responseBuilder;
            let sessionAttributes = handlerInput.attributesManager.getSessionAttributes();
            let say = 'OK Future location or Current location?';
            return responseBuilder
                .speak(say)
                .reprompt(say)
                .getResponse();
        },
    }

    const futureOrCurrentLocation_Handler = {
        canHandle(handlerInput) {
            const request = handlerInput.requestEnvelope.request;
            return request.type === 'IntentRequest' && request.intent.name === 'futureOrCurrentLocation' ;
        },
        handle(handlerInput) {
            const request = handlerInput.requestEnvelope.request;
            const responseBuilder = handlerInput.responseBuilder;
            let slotValues = getSlotValues(request.intent.slots);
            let location = slotValues.location.heardAs;
            let say = '';
           if (location == 'future location') {
                say = `Feature location not available in this moment. Please ask to current location.`;
            } else if(location == 'current location'){
                say = `Ok Where would you like to go?`;
            } else {
                say = `invalid input. Please try again`;
            }
            return responseBuilder
            .speak(say)
            .reprompt(say)
            .getResponse();
        },
    };

    const getRestaurantName_Handler =  {
        canHandle(handlerInput) {
            const request = handlerInput.requestEnvelope.request;
            return request.type === 'IntentRequest' && request.intent.name === 'getRestaurantName' ;
        },
        handle(handlerInput) {
            return new Promise((resolve) => {
                const request = handlerInput.requestEnvelope.request;
                let slotValues = getSlotValues(request.intent.slots);
                let say = slotValues.restaurant.heardAs;
                return handlerInput.responseBuilder
                .speak(say)
                .reprompt('try again, ' + say)
                .getResponse()
            });
        },
    };

    const getTableName_Handler = {
        canHandle(handlerInput) {
            const request = handlerInput.requestEnvelope.request;
            return request.type === 'IntentRequest' &&
                request.intent.name === 'getTableName';
        },
        handle(handlerInput) {
            const request = handlerInput.requestEnvelope.request;
            const {
                attributesManager,
                requestEnvelope,
                responseBuilder
            } = handlerInput;
            const slotValues = getSlotValues(request.intent.slots);
            let say = slotValues.name.heardAs;
            const sessionAttributes = attributesManager.getSessionAttributes();

            // delegate to Alexa to collect all the required slots 
            const currentIntent = request.intent;
            if (request.dialogState && request.dialogState !== 'COMPLETED') {
                return responseBuilder
                    .addDelegateDirective(currentIntent)
                    .getResponse();
            }

            return handlerInput.responseBuilder
                .speak(say)
                .reprompt('try again, ' + say)
                .getResponse()

        },
    };

    const skillBuilder = Alexa.SkillBuilders.custom();
    exports.handler = skillBuilder
        .addRequestHandlers(
            makeReservation_Handler,
            futureOrCurrentLocation_Handler,
            getRestaurantName_Handler,
            getTableName_Handler,
            LaunchRequest_Handler, 
            SessionEndedHandler
        )
        .addErrorHandlers(ErrorHandler)
        .lambda();

0 个答案:

没有答案