简体   繁体   English

无法获取转换数据以在Google的“操作”中保存参数

[英]Can't get conv.data to save a parameter in Actions on Google

As you can see in: Console Log from SaveLocation - AskLocationPermission it doesn't save the location_type to the conv.data . 如您所见: 来自SaveLocation-AskLocationPermission的控制台日志,它不会将location_type保存到conv.data While user storage works great I want to correctly use conv.data and conv.user.storage . 虽然用户存储很好用,但我想正确使用conv.dataconv.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.data

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. 当用户说要将该位置保存为自己的住所或工作时,应该如何工作,如果conv.user.storage或工作得到满足,则应调查conv.user.storage 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)))
});

Storage file: 存储文件:

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”意图处理程序调用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Dialogflow Conv.Data或Conv.User.Storage的简单计数器 - Simple Counter using Dialogflow Conv.Data or Conv.User.Storage Google / DialogFlow上的操作:从idToken获取用户数据而无需转换对象 - Actions on Google / DialogFlow: get user data from idToken without conv object ReferenceError:在google上的操作中未定义conv - ReferenceError: conv is not defined in actions-on-google actions_intent_SIGN_IN在conv-> user-> profile下没有配置文件数据 - actions_intent_SIGN_IN doesn't have profile data under conv->user->profile 如何使用字段和变量在带有Dialogflow的Google Actions中永久保存数据? - How to use fields and variables to save data permanently in Google Actions with Dialogflow? 使用TypeScript时,扩展Node.js客户端库中的“ conv”实例以在Google v2上执行操作 - Extend “conv” instance in Node.js Client Library for Actions on Google v2 when using TypeScript 类型{}上的Conv.user.storage属性不存在Google DialogFlow上的操作 - Conv.user.storage property does not exist on type {} Actions on Google DialogFlow 通过Google动作传递状态数据 - Passing state data with google actions 使用Google上的操作在对话中保存数据 - saving data in conversations with Actions on Google Actions SDK conv.hasScreen无法按预期工作 - Actions SDK conv.hasScreen not working as expected
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM