我一直在关注这里的博客文章,并且在我的本地环境中测试了这个功能。我已经复制并粘贴了所有的东西,从博客到我的文本编辑器。我的代码中没有任何东西是原创的--但我无法让它工作!当我试图在本地环境中运行它时,我会得到以下错误:
const b = bindings[key].toString();
^
TypeError: Cannot read properties of undefined (reading 'toString')
at PathTemplate.render (/Users/dialogflow-cx/node_modules/google-gax/build/src/pathTemplate.js:114:37)
at SessionsClient.projectLocationAgentSessionPath (/Users/dialogflow-cx/node_modules/@google-cloud/dialogflow-cx/build/src/v3/sessions_client.js:1237:75)
at exports.handler (/Users/Waterfield/dialogflow-cx/functions/dialogflow-detect-intent.protected.js:21:25)
at process.<anonymous> (/Users/dialogflow-cx/node_modules/@twilio/runtime-handler/dist/dev-runtime/internal/functionRunner.js:74:9)
at process.emit (node:events:390:28)
at emit (node:internal/child_process:917:12)
at processTicksAndRejections (node:internal/process/task_queues:84:21) 我不知道从这里往哪里走!帮助!
发布于 2022-03-15 00:44:11
在这里,您的TypeError是“无法读取未定义的属性”,这意味着您传递的参数中至少有一个未定义。在我们检查返回错误时,第二行指向"projectLocationAgentSessionPath“,本节引用博客中的”section“。
session: client.projectLocationAgentSessionPath(
context.DIALOGFLOW_CX_PROJECT_ID,
context.DIALOGFLOW_CX_LOCATION,
context.DIALOGFLOW_CX_AGENT_ID,
event.dialogflow_session_id
)上述错误意味着至少在与projectId、location、agentId、SessionId相关的对象上返回未定义的内容。
要解决错误,必须检查是否传递与.env文件相同的正确环境变量?
发布于 2022-03-14 23:35:15
在错误中,我们可以看到对您正在处理的代码的引用:
at exports.handler (/Users/Waterfield/dialogflow-cx/functions/dialogflow-detect-intent.protected.js:21:25)这指的是这一行:
client.projectLocationAgentSessionPath(
context.DIALOGFLOW_CX_PROJECT_ID,
context.DIALOGFLOW_CX_LOCATION,
context.DIALOGFLOW_CX_AGENT_ID,
event.dialogflow_session_id
)通过对话框库跟踪代码,然后通过Google扩展库显示,代码最终通过与project、location、agent和session相关的对象的键运行,这些键映射到上面的4个参数。其中至少有一个是返回undefined的。
您是否将正确的环境变量添加到.env文件中?当您发出测试此端点的请求时,是否传递了一个dialogflow_session_id?
https://stackoverflow.com/questions/71472658
复制相似问题