问题描述
如您所见:
它不会保存 location_type 到 conv.data
。虽然用户存储效果很好,但我想正确使用 conv.data
和 conv.user.storage
。您可以在中看到该参数已实现,但没有保存到转换数据
。
As you can see in: Console Log from SaveLocation - AskLocationPermissionit doesn't save the location_type to the conv.data
. While user storage works great I want to correctly use conv.data
and conv.user.storage
. You can see in the Example of conversation that the parameter is fulfilled, but it doesn't get saved to the conv.data
.
应该如何工作是当用户说要将该位置保存为自己的住所或工作时,应查看 conv.user .storage
(如果他有住所或工作)。如果没有请求允许并添加他的位置,否则它将询问他是否确定要覆盖它。
How it should work is when user says that he wants to save this location as his home or work, it should look into the conv.user.storage
if he has home or work fulfilled. If not ask for permission to his location and add it, else it should ask him if he is sure to override it.
app.intent('SaveLocation - AskLocationPermission', (conv, {location_type}) => {
if (storage.isLocationAlreadySaved(conv, location_type)) {
return fun.talkAsk(conv, i18n.__("LOCATIONS.SAVE_OVERRIDE", location_type))
}
storage.setSaveLocationType(conv, location_type);
console.log("SaveLocation - AskLocationPermission");
console.log(storage.getLocationType(conv));
return conv.ask(new Permission({
context: i18n.__("PERMISSION_LOCATION.SAVE_LOCATION", location_type),
permissions:
['DEVICE_PRECISE_LOCATION'],
}));
});
app.intent('SaveLocation - PermissionHandler', (conv, params, permissionGranted) => {
if (!permissionGranted) return fun.talkAsk(conv, i18n.__("ERROR.PERMISSION_NOT_GRANTED", storage.getLocationType(conv)))
storage.setUserLocation(conv);
storage.saveLocation(conv);
return fun.talkAsk(conv, i18n.__("LOCATIONS.SAVE_COMPLETE", storage.getLocationType(conv)))
});
app.intent('SaveLocation - Yes', (conv) => {
console.log("SaveLocation - Yes");
console.log(storage.getLocationType(conv));
return conv.ask(new Permission({
context: i18n.__("PERMISSION_LOCATION.SAVE_LOCATION", storage.getLocationType(conv)),
permissions:
['DEVICE_PRECISE_LOCATION'],
}));
});
app.intent('SaveLocation - No', (conv) => {
return fun.talkAsk(conv, i18n.__("LOCATIONS.SAVE_DENIED", storage.getLocationType(conv)))
});
存储文件:
let setSaveLocationType = function (conv, locationType) {
conv.data.locationType = locationType;
};
let getLocationType = function (conv) {
return conv.data.locationType;
};
let isLocationAlreadySaved = function (conv, locationType) {
console.log("isLocationAlreadySaved");
if (locationType === "work") {
console.log(getWorkLocationLat(conv))
return getWorkLocationLat(conv) !== 0.0
} else if (locationType === "home") {
console.log(getHomeLocationLat(conv));
return getHomeLocationLat(conv) !== 0.0
}
return false
};
let saveLocation = function (conv) {
let locationType = getLocationType(conv);
if (locationType === "work") {
conv.user.storage.workLocationLatitude = getUserLatitude(conv);
conv.user.storage.workLocationLongitude = getUserLongitude(conv);
} else if (locationType === "home") {
conv.user.storage.homeLocationLatitude = getUserLatitude(conv);
conv.user.storage.homeLocationLongitude = getUserLongitude(conv);
}
};
let getWorkLocationLat = function (conv) {
return conv.user.storage.workLocationLatitude
};
let getWorkLocationLng = function (conv) {
return conv.user.storage.workLocationLongitude
};
let getHomeLocationLat = function (conv) {
return conv.user.storage.homeLocationLatitude
};
let getHomeLocationLng = function (conv) {
return conv.user.storage.homeLocationLongitude
};
How I imagined flow of the conversation for this intent
推荐答案
看起来好像没有 setUserLocation函数实际上已定义,但是您尝试从 SaveLocation-PermissionHandler意图处理程序中调用它。
这篇关于无法获取转换数据以在Google的“操作”中保存参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!