Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 发出处理程序时指令不工作?_Javascript_Node.js_Amazon Web Services_Alexa_Alexa Skills Kit - Fatal编程技术网

Javascript 发出处理程序时指令不工作?

Javascript 发出处理程序时指令不工作?,javascript,node.js,amazon-web-services,alexa,alexa-skills-kit,Javascript,Node.js,Amazon Web Services,Alexa,Alexa Skills Kit,对话完成且其确认状态更改为已确认后,我发出另一条对话指令。/intent但其指令起作用,它直接跳到发出并结束 代码:- const handlers = { 'LaunchRequest': function () { this.response.speak(welcomeOutput).listen(welcomeReprompt); var userID = this.event.session.user.userID; console

对话完成且其确认状态更改为已确认后,我发出另一条对话指令。/intent但其指令起作用,它直接跳到发出并结束

代码:-

const handlers = {
    'LaunchRequest': function () {
        this.response.speak(welcomeOutput).listen(welcomeReprompt);
        var userID = this.event.session.user.userID;
        console.log(userID);
        this.emit(':responseReady');
    },
    'createOrder': function () {

        var filledSlots = delegateSlotCollection.call(this);
        this.emit(':tell','Create Order Ended');
    },
    'addOrder': function () {
        var filledSlots = delegateSlotCollectionSecond.call(this);

    },
    'AMAZON.HelpIntent': function () {
        speechOutput = "";
        reprompt = "";
        this.response.speak(speechOutput).listen(reprompt);
        this.emit(':responseReady');
    },
    'AMAZON.YesIntent': function () {
        this.emit("Yes Triggered");
    },
    'AMAZON.NoIntent': function () {
        this.emit("NO Triggered");
    },
    'AMAZON.CancelIntent': function () {
        speechOutput = "Okay Your Request is Cancelled";
        this.response.speak(speechOutput);
        this.emit(':responseReady');
    },
    'AMAZON.StopIntent': function () {
        speechOutput = "";
        this.response.speak(speechOutput);
        this.emit(':responseReady');
    },
    'SessionEndedRequest': function () {
        var speechOutput = "";
        this.response.speak(speechOutput);
        this.emit(':responseReady');
    },
    'AMAZON.FallbackIntent': function () {
        console.log('AMAZON FALL BACKINTENT');
    },
    'Unhandled': function () {
        console.log("Unhandled");
    },
};

exports.handler = (event, context) => {
    var alexa = Alexa.handler(event, context);
    alexa.appId = APP_ID;
    // To enable string internationalization (i18n) features, set a resources object.
    //alexa.resources = languageStrings;
    alexa.registerHandlers(handlers);
    alexa.execute();
};

//    END of Intent Handlers {} ========================================================================================
// 3. Helper Function  =================================================================================================

function delegateSlotCollection() {
    console.log("in delegateSlotCollection");
    console.log("current dialogState: " + this.event.request.dialogState);
    if (this.event.request.dialogState === "STARTED") {
        var updatedIntent = this.event.request.intent;
        this.emit(":delegate", updatedIntent);
    } else if (this.event.request.dialogState !== "COMPLETED") {
        console.log("in not completed");
        this.emit(":delegate")
    } else {
        if (this.event.request.intent.confirmationStatus === 'CONFIRMED'){
           this.emit('addOrder');
        }
        return this.event.request.intent;
    }
}


function delegateSlotCollectionSecond() {
    console.log("in delegateSlotCollection");
    console.log("current dialogState: " + this.event.request.dialogState);
    if (this.event.request.dialogState === "STARTED") {
        var updatedIntent = this.event.request.intent;
        this.emit(":delegate", updatedIntent);
    } else if (this.event.request.dialogState !== "COMPLETED") {
        console.log("in not completed");
        this.emit(":delegate")
    } else {
        if (this.event.request.intent.confirmationStatus === 'CONFIRMED'){
            Console.log("Vegeta");
             console.log(this.event.request.intent.confirmationStatus);
        }
        return this.event.request.intent;
    }
}
这是我正在使用的代码,所以当第一个createOrder对话完成时,它会请求确认,当我说“是”时,会发出“添加顺序”,但其对话指令不起作用,它会直接发出语句,所以如何解决此问题

    'createOrder': function () {     
         this.emit(':ask','tell me item name');
        },
     'productIntent': function(){
         this.event.request.intent.slots.product.value //have an intent and slot for product 
         this.attributes['anyName'] = "product"; put product in session
         this.emit(':ask','tell me quantity');
      } 
     'quantityIntent': function(){
         this.event.request.intent.slots.quantity.value //have an intent and slot for quality
         this.attributes['anyName'] = "quantity"; put quantity in session
         this.emit(':ask','do you want to add more item');
     }
      'Amazon.yesIntent': function () {
            this.emit("createOrder"); //repeat
    }, 
//handle no intent by retrieving all data and making your order
let retriveddata = this.attributes['anyName'];
你明白了。 这样,除非会话结束,否则不会在意图之间丢失数据

{
    "interactionModel": {
        "languageModel": {
            "invocationName": "hello order",
            "intents": [
                {
                    "name": "AMAZON.FallbackIntent",
                    "samples": []
                },
                {
                    "name": "AMAZON.CancelIntent",
                    "samples": []
                },
                {
                    "name": "AMAZON.HelpIntent",
                    "samples": []
                },
                {
                    "name": "AMAZON.StopIntent",
                    "samples": []
                },
                {
                    "name": "CreateOrder",
                    "slots": [],
                    "samples": []
                },
                {
                    "name": "ProductIntent",
                    "slots": [
                        {
                            "name": "productType",
                            "type": "products"
                        }
                    ],
                    "samples": [
                        "{productType}"
                    ]
                },
                {
                    "name": "QuanityIntent",
                    "slots": [
                        {
                            "name": "quantiyValue",
                            "type": "AMAZON.NUMBER"
                        }
                    ],
                    "samples": [
                        "{quantiyValue}"
                    ]
                },
                {
                    "name": "AMAZON.YesIntent",
                    "samples": []
                },
                {
                    "name": "AMAZON.NoIntent",
                    "samples": []
                }
            ],
            "types": [
                {
                    "name": "products",
                    "values": [
                        {
                            "name": {
                                "value": "burger"
                            }
                        },
                        {
                            "name": {
                                "value": "pizza"
                            }
                        }
                    ]
                }
            ]
        }
    }
}

因为当第二个对话框函数被调用时,这一切都发生在同一个会话中,“this.event.request.dialogState”仍然是“confirm”。您是否有机会检查此问题?this.event.request.dialogState=“STARTED”只需更改状态。将其作为答案发布。