【问题标题】:adding alexa skill session attributes from nodejs从nodejs添加alexa技能会话属性
【发布时间】:2018-07-19 04:44:33
【问题描述】:

在nodejs代码中使用alexa技能中的会话属性

但输出未定义。未定义应该是一种时尚。

代码请参考图片

    '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');
},

【问题讨论】:

    标签: node.js alexa alexa-skills-kit alexa-skill


    【解决方案1】:

    试试这个,

    为Session添加属性,

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

    为了从 Session 中检索它,

    var a = this.attributes.lastSpeech;
    

    希望这对您有所帮助。一切顺利:)

    【讨论】:

      【解决方案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');
      },
      

      【讨论】:

        猜你喜欢
        • 2017-08-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-07-05
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多