adding alexa skill session attributes from nodejs

大城市里の小女人 提交于 2019-12-11 08:37:12

问题


using session attributes in alexa skill in nodejs code

But getting output undefined. Undefined should be a fashion.

.

Please refer to images for the code

    'expenseIntent': function () {
    var updatedIntent=this.event.request.intent;
    var category1 = this.event.request.intent.slots.category.value;
    var expense;
    if(category1=='fashion'){
        expense = '1000';
    }else if(category1=='travel'){

        expense = '2000';
    }else if(category1=='food'){

        expense = '3000';
    }else {

        expense = '4000';
    }
    this.attributes.lastSpeech = this.event.request.intent.slots.category.value;
    console.log(this.attributes);
    if (this.event.request.dialogState === "STARTED") {
    this.emit(":delegate", updatedIntent);
    }else if(this.event.request.dialogState !== "COMPLETED"){
    this.emit(":delegate", updatedIntent);
    }else {
    console.log("this.event.request.intent.slots.category.value"+this.event.request.intent.slots.category.value);
    this.response.speak("Amount spent on "+category1+" is " + expense);
    this.emit(':responseReady'); 
}
},
'intentTwo': function () {
    var a = this.attributes.lastSpeech;

    //var aa = this.event.request.intent.slots.categories.value;
    this.response.speak("you query was about " + a);
    this.emit(':responseReady');
},

回答1:


Try this,

For adding attributes to Session,

Object.assign(this.attributes, {
    "lastSpeech" = this.event.request.intent.slots.category.value;
});

For retrieving it from Session,

var a = this.attributes.lastSpeech;

Hope this helps you. All the best :)




回答2:


'expenseIntent': function () {
    var updatedIntent=this.event.request.intent;
    var category1 = this.event.request.intent.slots.category.value;
    var expense;
    if(category1=='fashion'){
        expense = '1000';
    }else if(category1=='travel'){

        expense = '2000';
    }else if(category1=='food'){

        expense = '3000';
    }else {

        expense = '4000';
    }
    this.attributes.lastSpeech = this.event.request.intent.slots.category.value;
    console.log(this.attributes);
    if (this.event.request.dialogState === "STARTED") {
    this.emit(":delegate", updatedIntent);
    }else if(this.event.request.dialogState !== "COMPLETED"){
    this.emit(":delegate", updatedIntent);
    }else {
    console.log("this.event.request.intent.slots.category.value"+this.event.request.intent.slots.category.value);
    this.response.speak("Amount spent on "+category1+" is " + expense);
    this.emit(':responseReady'); 
}
},
'intentTwo': function () {
    var a = this.attributes.lastSpeech;

    //var aa = this.event.request.intent.slots.categories.value;
    this.response.speak("you query was about " + a);
    this.emit(':responseReady');
},


来源:https://stackoverflow.com/questions/51414507/adding-alexa-skill-session-attributes-from-nodejs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!