【发布时间】:2020-12-11 16:43:51
【问题描述】:
我在我的用户存储中存储了一个值(在我的例子中是用户想要听到新闻的城市)。我希望用户能够改变这个城市,从而改变用户存储。我尝试了很多东西,但还没有成功,希望有人能提供帮助。
当用户选择改变城市时,regio_kiezen Intent 被调用。此意图使用包含多个城市的名为 regio 的实体询问您想要哪个城市。查看此意图的屏幕截图(顺便说一句:为调用此意图的另一个场景添加事件):
在提示输入参数值后,它会执行。这是这个意图和名为 Regio 的意图的实现代码(这是显示新闻标题的意图):
app.intent('regio_kiezen', (conv, params) => {
conv.user.storage.regio = {};
var chosen_regio = params['regio'];
conv.user.storage.regio = chosen_regio;
console.log(`user: ${conv.user.storage.regio}`);
conv.followup('Regio');
console.log("intent: regio kiezen intent");
});
app.intent('Regio', (conv) => {
console.log("regio intent");
console.log(`doebiesnoesje: ${conv.user.storage.regio}`);
conv.ask(new Suggestions('Regio veranderen'));
conv.ask(new Suggestions(['Suggestion 2', 'Suggestion 3']));
return axios.get(`api-adress/${conv.user.storage.regio}`) //can not share the real api-adres
.then((result) => {
// informatie ophalen
for (let i=0; i <= 5; i++) {
titels[i] = (result.data.categories[0].news[i].title); // titel
subtexts[i] = (result.data.categories[0].news[i].text); // subtext
images[i] = (result.data.categories[0].news[i].media[0].image); // image
links[i] = (result.data.categories[0].news[i].url); // link
}
// LIST
if (!conv.screen) {
conv.ask('Sorry, try this on a screen device or select the ' +
'phone surface in the simulator.');
return;
}
console.log(`Regioo:`);
if(conv.user.storage.regio == 'nhgooi') {
praat = 'het Gooi';
} else {
praat = conv.user.storage.regio;
}
conv.ask(`Hier volgt het laatste nieuws uit ${praat}`);
conv.ask(new List({
title: praat,
items: {
// Add the first item to the list
'SELECTION_KEY_ONE': {
synonyms: [
'synonym 1',
'synonym 2',
'synonym 3',
],
title: titels[0],
image: new Image({
url: images[0],
}),
},
// Add the second item to the list
'SELECTION_KEY_GOOGLE_HOME': {
synonyms: [
'Google Home Assistant',
'Assistant on the Google Home',
],
title: titels[1],
image: new Image({
url: images[1],
}),
},
// Add the third item to the list
'SELECTION_KEY_GOOGLE_PIXEL': {
synonyms: [
'Google Pixel XL',
'Pixel',
'Pixel XL',
],
title: titels[2],
image: new Image({
url: images[2],
}),
},
'SELECTION_FOUR': {
synonyms: [
'Google Pixel XL',
'Pixel',
'Pixel XL',
],
title: titels[3],
image: new Image({
url: images[3],
}),
},
'SELECTION_KEY_FIVE': {
synonyms: [
'Google Pixel XL',
'Pixel',
'Pixel XL',
],
title: titels[4],
image: new Image({
url: images[4],
}),
},
},
}));
})
.catch((err) => console.log(err));
});
我遇到的问题是它一直显示旧(第一组)城市的新闻。因此,看起来 conv.user.storage.regio 没有被更改。我不知道为什么会这样,希望有人能提供帮助!提前致谢。
【问题讨论】:
-
如果您删除
regio_kiezen意图中的conv.followup是否允许更新您的变量? -
您是否启用了这些设置?它通常与用户存储的状态问题有关stackoverflow.com/questions/58208082/…
-
嗨@NickFelker 我试过了,但不幸的是不起作用
-
@Jordi ,我正在使用网络测试仪,所以我认为这不是问题。毕竟是能够保存第一个用户存储的。
-
你能试试
conv.user.storage = {};吗?
标签: javascript node.js dialogflow-es actions-on-google dialogflow-es-fulfillment