Dialogue.Directive не работает При отправке обработчика? - PullRequest
0 голосов
/ 21 мая 2018

После того, как диалог завершен и его состояние подтверждения изменено на подтвержденное, чем я посылаю другую директиву диалога ./ намерение, но его директива не работает, и он непосредственно переходит к излучению и завершает

код: -

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 завершен, он запрашивает подтверждение, и когда я говорю «да», то добавляется порядок добавления, но его директива диалога не работает, он напрямую генерирует оператор, так как решить эту проблемупроблема?

1 Ответ

0 голосов
/ 21 мая 2018
    '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"
                            }
                        }
                    ]
                }
            ]
        }
    }
}
...