node.js - 从nodejs添加alexa技能会话属性
问题描述
在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');
},
解决方案
尝试这个,
为 Session 添加属性,
Object.assign(this.attributes, {
"lastSpeech" = this.event.request.intent.slots.category.value;
});
为了从 Session 中检索它,
var a = this.attributes.lastSpeech;
希望这对您有所帮助。一切顺利 :)
推荐阅读
- wcf - WCF 元数据在 HTTPS 上显示不正确的服务 URI
- aggregation-framework - 聚合端点的用户限制资源访问
- amazon-web-services - 单次写入订购商品
- mysql - NuGet 包 MySql.Data 不兼容 UWP 10.0.10586
- cassandra - 如何从 cassandra 中删除数据
- python - 为什么 != 运算符不调用我的 '__neq__' 方法?
- angular - 使订阅在 Angular 4 中等待主题
- r - 错误:当 R 中没有安装 NA 值时需要 TRUE/FALSE 的缺失值
- html - 在 div 之间添加边界线
- java - 如果语句中 x 可以等于一系列数字/一个数字范围?