传递上下文时无法读取未定义的属性“参数” - Google 上的操作

达留施

目前我正在尝试开发一个动作。

我正在尝试实现重用意图。具体来说,就是助理给我一个列表的前三项,如果我要求更多,那么它应该给我列表的后三项。

我实现了本地工作的逻辑,但遗憾的是我总是从列表中获得前三项。因此,我尝试使用上下文,我想将索引作为参数传递,在这里我遇到了问题。云函数日志总是给我:

无法读取未定义的属性“参数”。

我正在使用 dialog v2 api 和 Google sdk 上的操作。以下链接提供了一个如何实现上下文的示例,我看不出有什么大的区别。https://developers.google.com/actions/reference/nodejsv2/overview

为它编写的代码如下所示:

app.intent('Default Welcome Intent', conv => {
    conv.ask('Welcome.')

    const lifespan = 100;
    const parameters = {
        index: 0,
    };
    conv.contexts.set('movieCtx', lifespan, parameters);
});

app.intent('New Cinema Movies Intent', async conv => {
    let movieCtx = conv.contexts.get('movieCtx');
    let index = movieCtx.parameters[index]

    let movieRepository = new MovieRepository();
    movieRepository.index = index;
    await movieRepository.fetchNextTitle(3).then(function(titles) {
        movieCtx.parameters[index] = movieRepository.index;
        conv.ask('The 3 movies are:' + titles.join(', '))

        return true;
    }).catch(function(err) {
        console.log(err); 
        return false;
    });
})

我的依赖:

{
  "name": "functions",
  "description": "Cloud Functions for Firebase",
  "scripts": {
    "lint": "eslint .",
    "serve": "firebase serve --only functions",
    "shell": "firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "dependencies": {
    "actions-on-google": "^2.5.0",
    "firebase-admin": "~6.0.0",
    "firebase-functions": "^2.0.3",
    "pg": "^7.7.1"
  },
  "devDependencies": {
    "eslint": "^4.12.0",
    "eslint-plugin-promise": "^3.6.0"
  },
  "private": true
}

更新:

我还尝试更改以下几行,但这也无济于事:

const parameters = {
        movieIndex: 0,
};

let index = movieCtx.parameters['movieIndex']
达留施

我找到了答案!

const {dialogflow} = require('actions-on-google');
const functions = require('firebase-functions');
const MovieRepository = require('./PostgreSQL/MovieRepository');
let movieRepository = new MovieRepository();

const app = dialogflow({debug: true});

const AppContexts = {
    NUMBER: 'number',
}

app.intent('Default Welcome Intent', (conv) => {
    const lifespan = 10;
    const parameters = {
        movieIndex: 0,
    };
    conv.contexts.set(AppContexts.NUMBER, lifespan, parameters);
    conv.ask('Welcome!')
});

app.intent('New Cinema Movies Intent', async (conv) => {
    const movieCtx = conv.contexts.get(AppContexts.NUMBER);

    await movieRepository.fetchNextTitle(3).then(function(titles) {
        movieCtx.parameters.movieIndex = movieRepository.index;
        conv.ask('The 3 movie titles are: ' + titles.join(', '));
        return true;
    }).catch(function(err) {
        console.log(err); 
        return false;
    });
})

app.intent('Default Fallback Intent', conv => {
    conv.ask('Sorry. Can you repeat?')
})

exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);

如您所见,您必须在意图上方创建 AppContext。有点奇怪但重要的是你申请

NUMBER: 'number'

到上下文,否则你会再次得到一个未定义的上下文。要访问您的参数,您只需要像这样附加您的参数值:

movieCtx.parameters.movieIndex

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

无法读取Redux thunk操作上未定义的属性'then'

无法接受Google的“操作”上的权限提示

无法读取未定义的属性“操作”

无法读取未定义的属性“上下文”-GraphQL

为什么我在 Google 上的操作无法识别触摸选择?

类型“未定义”上不存在属性“句柄”-反应上下文和打字稿

对Google上下文的操作未传递到下一个意图

未定义登录Google操作

Google Charts API:无法读取未定义的属性“ toArrays”

无法读取未定义的Google图表的属性“ DataTable”

Google函数:TypeError:无法读取未定义的属性“名称”

Google App脚本-映射时发生错误-TypeError:无法读取未定义的属性“ map”

尝试创建Google图表时遇到错误Uncaught TypeError:无法读取未定义的属性'arrayToDataTable'

Google Smart Home上的操作

Google上的帐户关联操作

TypeError:执行删除操作时无法读取未定义的属性“ concat”

类型{}上的Conv.user.storage属性不存在Google DialogFlow上的操作

上下文菜单上的文件元素未定义 - 为什么?

× TypeError:无法读取未定义的属性“地图” - google.maps 未定义(React)

无法在 Google 助理 sdk 上触发自定义操作

在画布上绘制时出现“未捕获的TypeError:无法读取未定义的属性'getContext'”

Uncaught TypeError:在Initialize()上添加GetJson时,无法读取未定义的属性'__e3_'

页面刷新时无法读取mergeMap Observable 上未定义的属性“订阅”

无法读取DashboardComponent上未定义的属性“管道”

React无法读取组件上未定义的属性“ map”

无法读取数组上未定义的属性“推送”

无法读取 useEffect 钩子上未定义的属性“map”

TypeError:无法读取.remove()上未定义的属性“ parentElement”

vue 3 上的 Codemirror,无法读取未定义的属性“on”